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

@begin/data

Package Overview
Dependencies
Maintainers
3
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@begin/data - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

11

package.json
{
"name": "@begin/data",
"version": "1.0.0",
"description": "Begin Data is a durable and fast key/value store for Begin built on top of DynamoDB.",
"version": "1.0.1",
"description": "Begin Data is a durable and fast key/value document store built on top of DynamoDB.",
"main": "src/index.js",
"scripts": {
"lint": "eslint src --ignore-pattern node_modules --fix",
"test": "ARC_LOCAL=true NODE_ENV=testing tape test/test.js | tap-spec"
"test": "tape test/test.js | tap-spec"
},

@@ -20,3 +20,5 @@ "license": "Apache-2.0",

"dependencies": {
"@architect/parser": "^1.1.6",
"hashids": "^1.2.2",
"run-parallel": "^1.1.9",
"run-waterfall": "^1.1.6"

@@ -27,3 +29,2 @@ },

"eslint": "^5.10.0",
"run-parallel": "^1.1.9",
"tap-spec": "^5.0.0",

@@ -36,2 +37,4 @@ "tape": "^4.9.1"

"AWS",
"dynamodb",
"keyvalue",
"infrastructure",

@@ -38,0 +41,0 @@ "infra"

@@ -11,2 +11,19 @@ # Begin Data

## Usage
Begin Data operates on one DynamoDB table named `data` with a partition key `scopeID` and a sort key of `dataID` and, optionally, a `ttl` for expiring documents.
Example `.arc`:
```
@app
myapp
@tables
data
scopeID *String
dataID **String
ttl TTL
```
### API

@@ -30,3 +47,3 @@

All methods require a params object and, optionally, a Node style errback. If no errback is supplied a promise is returned. All methods support `async`/`await`.
All methods accept params object and, optionally, a Node style errback. If no errback is supplied a promise is returned. All methods support `async`/`await`.

@@ -33,0 +50,0 @@ #### Writes

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

/**
* @private
* @module incr
* @module decr
*/
let doc = require('./_get-doc')

@@ -2,0 +7,0 @@ let getTableName = require('./_get-table-name')

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

/**
* @private
* @module createKey
*/
let getTableName = require('./_get-table-name')

@@ -2,0 +6,0 @@ let db = require('./_get-db')

@@ -0,4 +1,8 @@

/**
* @private
* @module fmt
*/
let getKey = require('./_get-key')
module.exports = function(obj) {
module.exports = function fmt(obj) {
let copy = {...obj, ...getKey(obj)}

@@ -5,0 +9,0 @@ delete copy.key

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

/**
* @private
* @module DynamoDB
*/
if (typeof process.env.NODE_ENV === 'undefined') {

@@ -2,0 +6,0 @@ process.env.NODE_ENV = 'testing'

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

/**
* @private
* @module DynamoDB.DocumentClient
*/
if (typeof process.env.NODE_ENV === 'undefined') {

@@ -2,0 +6,0 @@ process.env.NODE_ENV = 'testing'

@@ -1,7 +0,18 @@

module.exports = function _getKey(params) {
/**
* @private
* @module getKey
*
* Get the begin-data partition key (scopeID) and sort key (dataID)
*
* - the env var BEGIN_DATA_SCOPE_ID override always wins
* - uses ARC_APP_NAME if it exists
* - fallback to 'local' for running in the sandbox
* - dataID is scoped to staging or production depending on NODE_ENV
*/
module.exports = function getKey(params) {
let {table, key} = params
let env = process.env.NODE_ENV === 'testing'? 'staging' : (process.env.NODE_ENV || 'staging')
let scopeID = process.env.BEGIN_DATA_SCOPE_ID || 'local'
let scopeID = process.env.BEGIN_DATA_SCOPE_ID || process.env.ARC_APP_NAME || 'sandbox'
let dataID = `${env}#${table}#${key}`
return {scopeID, dataID}
}

@@ -1,4 +0,73 @@

module.exports = function() {
/**
* @private
* @module getTableName
*
* Get the begin-data table name
*
* - the env var BEGIN_DATA_TABLE_NAME override always wins
* - fallback to `data` table defined the current .arc
* - final fallback to begin-data-production-data or begin-data-staging-data
*/
let parse = require('@architect/parser')
let join = require('path').join
let fs = require('fs')
let read = p=> fs.readFileSync(p).toString()
let exists = fs.existsSync
let table = false // cache between invocations
module.exports = function getTableName() {
if (table)
return table
let raw
let arc
let env = process.env.NODE_ENV === 'testing'? 'staging' : process.env.NODE_ENV
return process.env.BEGIN_DATA_TABLE_NAME || `begin-data-${env}-data`
let cwd = process.cwd()
let arcDefaultPath = join(cwd, '.arc')
let appDotArcPath = join(cwd, 'app.arc')
let arcYamlPath = join(cwd, 'arc.yaml')
let arcJsonPath = join(cwd, 'arc.json')
let localPath = join(__dirname, '..', 'shared', '.arc')
let override = process.env.hasOwnProperty('BEGIN_DATA_TABLE_NAME')
if (override) {
table = process.env.BEGIN_DATA_TABLE_NAME
}
else if (exists(arcDefaultPath)) {
raw = read(arcDefaultPath)
arc = parse(raw)
table = `${arc.app[0]}-${env}-data`
}
else if (exists(appDotArcPath)) {
raw = read(appDotArcPath)
arc = parse(raw)
table = `${arc.app[0]}-${env}-data`
}
else if (exists(arcYamlPath)) {
raw = read(arcYamlPath)
arc = parse.yaml(raw)
// HACK
raw = parse.yaml.stringify(raw)
table = `${arc.app[0]}-${env}-data`
}
else if (exists(arcJsonPath)) {
raw = read(arcJsonPath)
arc = parse.json(raw)
// HACK
raw = parse.json.stringify(raw)
table = `${arc.app[0]}-${env}-data`
}
else if (exists(localPath)) {
// otherwise we are: testing, staging or in production
// loading from node_modules/@architect/shared/.arc
raw = read(localPath)
arc = parse(raw)
table = `${arc.app[0]}-${env}-data`
}
else {
table = `begin-data-${env}-data`
}
return table
}

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

module.exports = function(obj) {
/**
* @private
* @module unfmt
*/
module.exports = function unfmt(obj) {
let copy = {...obj}

@@ -3,0 +7,0 @@ copy.key = obj.dataID.split('#')[2]

/**
* @private
* @module validate
*
* validate.table([table|items])

@@ -24,3 +27,2 @@ * ---

*
*
* validate.size([item|items])

@@ -27,0 +29,0 @@ * ---

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