Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/actions/stale-9
Browse files Browse the repository at this point in the history
  • Loading branch information
johntalton committed Dec 21, 2023
2 parents 9fa9a18 + 104e875 commit c3e0b5c
Show file tree
Hide file tree
Showing 15 changed files with 1,253 additions and 410 deletions.
567 changes: 567 additions & 0 deletions .eslintrc.json

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2.4.0
with:
node-version: 14.x
- uses: actions/setup-node@v3.6.0
- run: npm install
- run: npm run build
- run: npm run format
Expand All @@ -25,11 +23,11 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [14, 15, 16]
node-version: [14, 15, 16, 20]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2.4.0
- uses: actions/setup-node@v3.6.0
with:
node-version: ${{ matrix.node-version }}
- uses: actions/download-artifact@v3
Expand Down
104 changes: 104 additions & 0 deletions README_TRANSACTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Transaction Bus

The transaction bus provides a queue around the wrapped i2c bus. And provides and additional api for exposing a queue transaction.

## Basics

The Transaction bus chains the promise based on the last transaction, effectively serializing the calls to the wrapped i2c bus api.

When single operation are performed, this is of limited use (except when mixed with transactions as they count as such).

And additional api `transaction<T>(async cb: bus => T)` is provided to create a block of bus calls that will serialize over the wrapped bus.

Withe the assumption that add client are using this shared consumption api this can be use to make calls to the bus that span multiple requests.

```typescript
const hwbus = __hw('i2c')
const tbus = new I2CTransactionBus(hwbus)

const updatedMode = await tbus.transaction(async bus => {

const mode = await bus.readI2cBlock(ADDRESS, MODE_REG, 1)

// perform Mode Operation and derive node Mode
const newMode = __op(mode)

await bus.writeI2cBlock(ADDRESS, MODE_REG, 1, newMode)

return newMode
})
```

## Addressed Bus

The Address Bus API simplification can be used in two distinct ways.

The first is in combination with the `I2CTransactionBus`, as both a typical wrapper, and as a wrapper for the bus resulting from a call to `transaction`.

Secondly, a Addressed Transaction Bus can be created that will both extends the api over the address parameter, but will also change the context of how `transaction` works for the bus. Allowing for the transaction to be "Scoped" to the address used.

### Serialized over Bus


```javascript
function updateMode(bus, offset) {
return bus.transaction(atbus => {
const mode = await atbus.readI2cBlock(MODE_REG, 1)
// read the value in the buffer and create a new buffer with the newMode value
// newMode = mode + offset
return atbus.writeI2cBlock(ADDRESS, MODE_REG, 1, newMode)
})
}

const incrementMode = bus => updateMode(bus, 1)
const decrementMode = bus => updateMode(bus, -1)

const hwbus = __hw('i2c')
cosnt tbus = new I2CTransactionBus(hwbus)
const abus1 = new I2CAddressBus(tbus, ADDRESS_1)
const abus2 = new I2CAddressBus(tbus, ADDRESS_2)

setTimeout(() => incrementMode(abus1), 1000 * Math.random() * 3
setTimeout(() => decrementMode(abus1), 1000 * Math.random() * 3
```
Alternatively, using the Transaction bus directly and wrapping the resulting `I2CBus` results in the same effect, serializing all calls across the entire bus.
```javascript
function updateMode(bus, offset) {
return bus.transaction(tbus => {
const abus = new I2CAddressedBus(tbus, ADDRESS)
...

...


const hwbus = __hw('i2c')
cosnt tbus = new I2CTransactionBus(hwbus)

...

setTimeout(() => incrementMode(tbus), 1000 * Math.random() * 3
setTimeout(() => decrementMode(tbus), 1000 * Math.random() * 3


```
### Serialized over Address
In order to create limited serialization to only addressed devices, the Addressed Transactions bus can be used
```typescript

const hwbus = __hw('i2c')
const tbus = new I2CTransactionBus(hwbus)
const atbus1 = new I2CAddressedTransactionBus(tbus, ADDRESS_1)
const atbus2 = new I2CAddressedTransactionBus(tbus, ADDRESS_2)

...

atbus1.transaction(bus => {
// multiple read writes are safe for this device
})

```
47 changes: 11 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@johntalton/and-other-delights",
"version": "6.1.0",
"version": "6.2.0",
"description": "",
"main": "src/aod.mjs",
"exports": {
Expand Down Expand Up @@ -30,35 +30,10 @@
"test:mocha": "mocha",
"coverage": "npm --silent run coverage:c8",
"coverage:nyc": "nyc npm run test:mocha -- --reporter min",
"coverage:c8": "c8 --check-coverage --all --lines 60 --functions 5 --branches 50 npm --silent run test:mocha -- --no-parallel --reporter min",
"coverage:c8": "c8 --check-coverage --reporter text --reporter lcov --all --lines 60 --functions 5 --branches 50 npm --silent run test:mocha -- --no-parallel --reporter min",
"audit": "auditjs ossi --dev",
"clean": "rm -r .nyc_output coverage lib node_modules package-lock.json aod.min.js aod.min.js.map"
},
"eslintConfig": {
"extends": [
"@johntalton/eslint-config/ts"
],
"env": {
"node": false
},
"ignorePatterns": "test/**/*.ts",
"rules": {
"valid-jsdoc": "off",
"max-len": [
"warn",
{
"code": 120
}
],
"fp/no-throw": "off",
"fp/no-nil": "off",
"fp/no-class": "off",
"immutable/no-mutation": "off",
"fp/no-mutation": "off",
"fp/no-this": "off",
"immutable/no-this": "off"
}
},
"mocha": {
"spec": [
"test/*.spec.js"
Expand Down Expand Up @@ -102,34 +77,34 @@
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@johntalton/eslint-config": "^2.0.0",
"@types/chai": "^4.2.11",
"@types/mocha": "^9.0.0",
"@types/node": "^18.7.3",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"@types/mocha": "^10.0.6",
"@types/node": "^20.10.5",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
"auditjs": "^4.0.18",
"c8": "^7.3.0",
"c8": "^8.0.1",
"chai": "^4.3.3",
"eslint": "^8.22.0",
"eslint-import-resolver-typescript": "^3.4.1",
"eslint-plugin-fp": "^2.3.0",
"eslint-plugin-functional": "^4.2.2",
"eslint-plugin-immutable": "^1.0.0",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-mocha": "^10.1.0",
"eslint-plugin-no-loops": "^0.3.0",
"eslint-plugin-no-use-extend-native": "^0.5.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-spellcheck": "0.0.19",
"eslint-plugin-security": "^2.1.0",
"eslint-plugin-spellcheck": "^0.0.20",
"js-beautify": "^1.11.0",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"source-map-support": "^0.5.19",
"standard": "^17.0.0",
"terser": "^5.0.0",
"ts-node": "^10.0.0",
"typescript": "^4.2.3"
"eslint-plugin-functional": "^6.0.0",
"typescript": "^5.3.3"
},
"repository": {
"type": "git",
Expand Down
3 changes: 3 additions & 0 deletions src/aod.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* eslint-disable spellcheck/spell-checker */
export * from '../lib/busutil.js'
export * from '../lib/i2c-addressed.js'
export * from '../lib/i2c-addressedtransaction.js'
export * from '../lib/i2c-mock.js'
export * from '../lib/i2c-scriptbus.js'
export * from '../lib/i2c-throwbus.js'
export * from '../lib/i2c-transactionbus.js'
export * from '../lib/i2c-proxybus.js'
// # sourceMappingURL=../lib/aod.js.map
3 changes: 3 additions & 0 deletions src/aod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
export * from './i2c.js'
export * from './busutil.js'
export * from './i2c-addressed.js'
export * from './i2c-addressedtransaction.js'
export * from './i2c-mock.js'
export * from './i2c-scriptbus.js'
export * from './i2c-throwbus.js'
export * from './i2c-transactionbus.js'
export * from './i2c-proxybus.js'
Loading

0 comments on commit c3e0b5c

Please sign in to comment.