Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-lite #115

Merged
merged 11 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 24 additions & 52 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Node CI

# Push tests commits; pull_request tests PR merges
on: [push, pull_request]
on: [ push, pull_request ]

jobs:

Expand All @@ -11,16 +11,16 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 14.x, 16.x, 18.x ]
node-version: [ 14.x, 16.x, 18.x, 20.x ]
os: [windows-latest, ubuntu-latest, macOS-latest]

# Go
steps:
- name: Check out repo
uses: actions/checkout@v1
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -39,16 +39,15 @@ jobs:
- name: Test
run: npm test

- name: Notify
uses: homoluctus/slatify@master
# Only fire alert once
if: github.ref == 'refs/heads/master' && failure() && matrix.node-version == '14.x' && matrix.os == 'ubuntu-latest'
with:
type: ${{ job.status }}
job_name: '*Build*'
url: ${{ secrets.SLACK_WEBHOOK }}
commit: true
token: ${{ secrets.GITHUB_TOKEN }}
# - name: Notify
# uses: sarisia/actions-status-discord@v1
# # Only fire alert once
# if: github.ref == 'refs/heads/main' && failure() && matrix.node-version == '20.x' && matrix.os == 'ubuntu-latest'
# with:
# webhook: ${{ secrets.DISCORD_WEBHOOK }}
# title: "build and test"
# color: 0x222222
# username: GitHub Actions

# ----- Only git tag testing + package publishing beyond this point ----- #

Expand All @@ -62,17 +61,14 @@ jobs:
# Go
steps:
- name: Check out repo
uses: actions/checkout@v1
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 12
node-version: lts/*
registry-url: https://registry.npmjs.org/

- name: Install
run: npm i

# Publish to npm
- name: Publish @RC to npm
if: contains(github.ref, 'RC')
Expand All @@ -86,35 +82,11 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

# Set up Node again, this time using GitHub as the publish target
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://npm.pkg.github.com/

# Change package org (@smallwins on GitHub vs @begin on NPM)
- name: Change package name
run: scripts/change-package-name @beginner-corp/data

# Publish to GitHub
- name: Publish @RC to GitHub
if: contains(github.ref, 'RC')
run: npm publish --tag RC
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish @latest to GitHub
if: contains(github.ref, 'RC') == false #'!contains()'' doesn't work lol
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Notify
uses: homoluctus/slatify@master
if: always()
with:
type: ${{ job.status }}
job_name: '*Publish*'
url: ${{ secrets.SLACK_WEBHOOK }}
commit: true
token: ${{ secrets.GITHUB_TOKEN }}
# - name: Notify
# uses: sarisia/actions-status-discord@v1
# if: always()
# with:
# webhook: ${{ secrets.DISCORD_WEBHOOK }}
# title: "npm publish"
# color: 0x222222
# username: GitHub Actions
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "@begin/data",
"version": "4.0.2",
"version": "5.0.0-RC.2",
"description": "Begin Data is a durable and fast key/value document store built on top of DynamoDB",
"main": "src/index.js",
"scripts": {
"t": "tape test/integration-test.js | tap-spec",
"lint": "eslint --fix .",
"test": "npm run lint && tape test/*-test.js | tap-spec",
"rc": "npm version prerelease --preid RC"
Expand All @@ -24,21 +25,20 @@
"src/*"
],
"dependencies": {
"@aws-lite/client": "^0.15.1",
"@aws-lite/dynamodb": "^0.3.3",
"@aws-lite/ssm": "^0.2.2",
"@begin/hashid": "^1.0.0",
"run-parallel": "^1.2.0",
"run-waterfall": "^1.1.7"
},
"devDependencies": {
"@architect/eslint-config": "^2.0.1",
"@architect/sandbox": "^5.1.0-RC.0",
"@aws-sdk/client-dynamodb": "^3.216.0",
"@aws-sdk/client-ssm": "^3.216.0",
"@aws-sdk/lib-dynamodb": "^3.216.0",
"aws-sdk": "^2.1261.0",
"eslint": "^8.10.0",
"@architect/eslint-config": "^2.1.2",
"@architect/sandbox": "^6.0.0-RC.1",
"eslint": "^8.56.0",
"tap-spec": "^5.0.0",
"tape": "^5.5.2",
"tiny-json-http": "^7.3.1"
"tape": "^5.7.4",
"tiny-json-http": "^7.5.1"
},
"eslintConfig": {
"extends": "@architect/eslint-config",
Expand Down
6 changes: 4 additions & 2 deletions src/count.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
* @module count
*/
let waterfall = require('run-waterfall')
let util = require('util')
let getTableName = require('./helpers/_get-table-name')
let getKey = require('./helpers/_get-key')
let dynamo = require('./helpers/_dynamo').doc
let dynamo = require('./helpers/_dynamo')

/**
* Get document count for given table
Expand Down Expand Up @@ -36,7 +37,8 @@ module.exports = function count ({ table }, callback) {
})
},
function counts (TableName, doc, callback) {
doc.query({
let query = util.callbackify(doc.Query)
query({
TableName,
Select: 'COUNT',
KeyConditionExpression: '#scopeID = :scopeID and begins_with(#dataID, :dataID)',
Expand Down
6 changes: 4 additions & 2 deletions src/destroy/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* @private
* @module destroy/batch
*/
let util = require('util')
let waterfall = require('run-waterfall')
let getTableName = require('../helpers/_get-table-name')
let getKey = require('../helpers/_get-key')
let dynamo = require('../helpers/_dynamo').doc
let dynamo = require('../helpers/_dynamo')

/**
* Destroy an array of documents
Expand Down Expand Up @@ -33,7 +34,8 @@ module.exports = function batch (params, callback) {
let batch = params.map(getKey).map(req)
let query = { RequestItems: {} }
query.RequestItems[TableName] = batch
doc.batchWrite(query, callback)
let batchWrite = util.callbackify(doc.BatchWriteItem)
batchWrite(query, callback)
}
],
function destroyed (err) {
Expand Down
6 changes: 4 additions & 2 deletions src/destroy/one.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* @private
* @module destroy/one
*/
let util = require('util')
let waterfall = require('run-waterfall')
let getTableName = require('../helpers/_get-table-name')
let getKey = require('../helpers/_get-key')
let dynamo = require('../helpers/_dynamo').doc
let dynamo = require('../helpers/_dynamo')

/**
* Destroy a document
Expand All @@ -22,8 +23,9 @@ module.exports = function one (params, callback) {
})
},
function destroys (TableName, doc, callback) {
let del = util.callbackify(doc.DeleteItem)
let Key = getKey(params)
doc.delete({
del({
TableName,
Key,
}, callback)
Expand Down
6 changes: 4 additions & 2 deletions src/get/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
* @private
* @module get/batch
*/
let util = require('util')
let waterfall = require('run-waterfall')
let getTableName = require('../helpers/_get-table-name')
let getKey = require('../helpers/_get-key')
let unfmt = require('../helpers/_unfmt')
let dynamo = require('../helpers/_dynamo').doc
let dynamo = require('../helpers/_dynamo')

let badKey = i => !(i['table'] && i['key'])

Expand Down Expand Up @@ -39,9 +40,10 @@ module.exports = function batch (Keys, callback) {
})
},
function gets (table, doc, callback) {
let batchGet = util.callbackify(doc.BatchGetItem)
let query = { RequestItems: {} }
query.RequestItems[table] = { Keys: Keys.map(getKey) }
doc.batchGet(query, function gots (err, result) {
batchGet(query, function gots (err, result) {
if (err) callback(err)
else {
callback(null, result.Responses[table].map(unfmt))
Expand Down
6 changes: 4 additions & 2 deletions src/get/one.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ let waterfall = require('run-waterfall')
let getTableName = require('../helpers/_get-table-name')
let getKey = require('../helpers/_get-key')
let unfmt = require('../helpers/_unfmt')
let dynamo = require('../helpers/_dynamo').doc
let dynamo = require('../helpers/_dynamo')
let util = require('util')

/**
* Read a document
Expand All @@ -32,8 +33,9 @@ module.exports = function one (params, callback) {
})
},
function gets (TableName, doc, callback) {
let getItem = util.callbackify(doc.GetItem)
let Key = getKey(params)
doc.get({
getItem({
TableName,
Key
}, callback)
Expand Down
9 changes: 6 additions & 3 deletions src/get/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ let waterfall = require('run-waterfall')
let getTableName = require('../helpers/_get-table-name')
let getKey = require('../helpers/_get-key')
let unfmt = require('../helpers/_unfmt')
let dynamo = require('../helpers/_dynamo').doc
let dynamo = require('../helpers/_dynamo')
let util = require('util')

/**
* Read documents
Expand Down Expand Up @@ -55,16 +56,18 @@ module.exports = function page (params, callback) {
if (params.cursor) {
query.ExclusiveStartKey = JSON.parse(Buffer.from(params.cursor, 'base64').toString('utf8'))
}
doc.query(query, callback)
let runQuery = util.callbackify(doc.Query)
runQuery(query, callback)
},
],
function paged (err, result) {
if (err) callback(err)
else {
let exact = item => item.table === params.table
let returns = result.Items.map(unfmt).filter(exact)
if (result.LastEvaluatedKey)
if (result.LastEvaluatedKey) {
returns.cursor = Buffer.from(JSON.stringify(result.LastEvaluatedKey)).toString('base64')
}
callback(null, returns)
}
})
Expand Down
8 changes: 5 additions & 3 deletions src/helpers/_atomic-counters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* @module decr
*/
let waterfall = require('run-waterfall')
let dynamo = require('./_dynamo').doc
let util = require('util')
let dynamo = require('./_dynamo')
let getTableName = require('./_get-table-name')
let getKey = require('./_get-key')
let unfmt = require('./_unfmt')
Expand Down Expand Up @@ -41,9 +42,10 @@ function atomic (isIncr, params, callback) {
else callback(null, TableName, doc)
})
},
function update (TableName, doc, callback) {
function _update (TableName, doc, callback) {
// perform the atomic update and callback w the updated values
doc.update({
let update = util.callbackify(doc.UpdateItem)
update({
TableName,
Key: getKey({ table, key }),
UpdateExpression: `SET ${prop} = if_not_exists(${prop}, :zero) ${isIncr ? '+' : '-'} :val`,
Expand Down
25 changes: 13 additions & 12 deletions src/helpers/_create-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
*/
let waterfall = require('run-waterfall')
let getTableName = require('./_get-table-name')
let dynamo = require('./_dynamo').db
let dynamo = require('./_dynamo')
let Hashids = require('@begin/hashid')
let util = require('util')
let hash = new Hashids

module.exports = function createKey (table, callback) {
Expand All @@ -19,27 +20,27 @@ module.exports = function createKey (table, callback) {
})
},
function update (TableName, db, callback) {
db.updateItem({
let updateItem = util.callbackify(db.UpdateItem)
let query = {
TableName,
Key: {
'scopeID': { S: BEGIN_DATA_SCOPE_ID || ARC_APP_NAME },
'dataID': { S: `${table}-seq` }
'scopeID': BEGIN_DATA_SCOPE_ID || ARC_APP_NAME,
'dataID': `${table}-seq`
},
AttributeUpdates: {
idx: {
Action: 'ADD',
Value: { N: '1' }
}
UpdateExpression: `SET idx = if_not_exists(idx, :one) + :one`,
ExpressionAttributeValues: {
':one': 1
},
ReturnValues: 'UPDATED_NEW'
}, callback)
ReturnValues: 'ALL_NEW'
}
updateItem(query, callback)
}
],
function done (err, result) {
if (err) callback(err)
else {
let epoc = Date.now() - 1544909702376 // hbd
let seed = Number(result.Attributes.idx.N)
let seed = Number(result.Attributes.idx)
let val = hash.encode([ epoc, seed ])
callback(null, val)
}
Expand Down
Loading
Loading