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

Release v1.0.7 #20

Merged
merged 3 commits into from
Apr 8, 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
24 changes: 2 additions & 22 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,6 @@ env:
node: true
es6: true
mocha: true
es2020: true
es2023: true

plugins:
- haraka

extends:
- eslint:recommended
- plugin:haraka/recommended

root: true

globals:
OK: true
CONT: true
DENY: true
DENYSOFT: true
DENYDISCONNECT: true
DENYSOFTDISCONNECT: true

rules:
indent: [2, 4, { SwitchCase: 1 } ]
console: 0
no-console: 0
extends: ['@haraka']
6 changes: 4 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Fixes #

Changes proposed in this pull request:
-
-

-
-

Checklist:

- [ ] docs updated
- [ ] tests updated
- [ ] Changes.md updated
Expand Down
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

version: 2
updates:
- package-ecosystem: "npm"
directory: "/" # Location of package manifests
- package-ecosystem: 'npm'
directory: '/' # Location of package manifests
schedule:
interval: "weekly"
interval: 'weekly'
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
secrets: inherit

test:
needs: [ lint ]
needs: [lint]
uses: haraka/.github/.github/workflows/ubuntu.yml@master

windows:
needs: [ lint ]
needs: [lint]
uses: haraka/.github/.github/workflows/windows.yml@master
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: CodeQL

on:
push:
branches: [ master ]
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
branches: [master]
schedule:
- cron: '18 7 * * 4'

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule ".release"]
path = .release
url = [email protected]:msimerson/.release.git
11 changes: 0 additions & 11 deletions .npmignore

This file was deleted.

2 changes: 2 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
singleQuote: true
semi: false
1 change: 1 addition & 0 deletions .release
Submodule .release added at 7cd570
44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Changelog

The format is based on [Keep a Changelog](https://keepachangelog.com/).

### Unreleased

### [1.0.7] - 2024-04-08

- use `[files]` in package.json. Delete .npmignore.
- doc: Changes -> CHANGELOG
- ci: more shared workflows
- lint: remove duplicate / stale rules from .eslintrc

### [1.0.6] - 2022-05-27

- chore(ci): depend on shared GHA workflows

### 1.0.5 - 2022-01-26

- feat: make it possible to set a false value
- chore(ci): bump lowest node.js version to 14

### [1.0.4] - 2021-02-04

- CI: replace Travis & AppVeyor with GitHub actions
- CI: automatically publish upon release.

### 1.0.3 - 2020-03-23

- bump packaging versions
- remove package-lock.json
- codeclimate: moved functions out of constructor

### 1.0.2 - 2017-09-07

- if an object is passed in, populate the notes with it

### 1.0.1 - 2017-09-04

- initial release

[1.0.4]: https://github.com/haraka/haraka-notes/releases/tag/1.0.4
[1.0.6]: https://github.com/haraka/haraka-notes/releases/tag/1.0.6
[1.0.7]: https://github.com/haraka/haraka-notes/releases/tag/v1.0.7
33 changes: 0 additions & 33 deletions Changes.md

This file was deleted.

12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,38 @@

Notes are objects that exist on Haraka connections and transactions. Prior to the release of [haraka-notes](https://github.com/haraka/haraka-notes), notes was just an empty object. Now notes is an empty object with two functions:


### set (path, value)

Sets a note at a dot delimited path to the specified value. The path can be any number of levels deep and any missing objects in the path are [autovivified](https://en.wikipedia.org/wiki/Autovivification). Perl refugees, contain yourselves.

```js
connection.transaction.notes.set('queue.wants', 'smtp_forward');
connection.transaction.notes.set('queue.wants', 'smtp_forward')
```

The above command sets `connection.transaction.notes.queue.wants` to the value 'smtp_forward'.


### get (path)

Fetches the value of a note from a given dot delimited path.

```js
connection.transaction.notes.get('queue.wants');
connection.transaction.notes.get('queue.wants')
```


## Array Syntax

The get and set functions support passing the path as an array of strings. This might be useful to the type of masochist that has dots in their JS/JSON keys. Example:

```js
connection.transaction.notes.get(['i.do','like','pa.in']);
connection.transaction.notes.get(['i.do', 'like', 'pa.in'])
```


## [Note Path Registry](https://github.com/haraka/haraka-notes/wiki)

To reduce the likelihood of namespace collisions in Haraka notes, consider registering the note paths your plugins use [in the registry](https://github.com/haraka/haraka-notes/wiki).


<!-- leave these buried at the bottom of the document -->

[ci-img]: https://github.com/haraka/haraka-notes/actions/workflows/ci.yml/badge.svg
[ci-url]: https://github.com/haraka/haraka-notes/actions/workflows/ci.yml
[cov-img]: https://codecov.io/github/haraka/haraka-notes/coverage.svg
Expand Down
19 changes: 8 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@

class Notes {

constructor (notes) {

constructor(notes) {
if (notes && typeof notes === 'object') {
Object.assign(this, notes)
}
Expand All @@ -11,47 +8,47 @@ class Notes {
configurable: false,
enumerable: false,
writable: false,
value: assignPathValue.bind(this)
value: assignPathValue.bind(this),
})

Object.defineProperty(this, 'get', {
configurable: false,
enumerable: false,
writable: false,
value: getPathValue.bind(this)
value: getPathValue.bind(this),
})
}
}

module.exports = Notes

function getSegments (path) {
function getSegments(path) {
// a dot.delimited.path
if (typeof path === 'string') return path.split('.')

// ['one', 'two', 'thr.ee']
if (Array.isArray(path)) return path
}

function assignPathValue (path, value) {
function assignPathValue(path, value) {
if (path === undefined || value === undefined) return

const segments = getSegments(path)
let dest = this

while (segments.length > 1) {
// create any missing paths
// create any missing paths
if (!dest[segments[0]]) dest[segments[0]] = {}
// set dest one path segment deeper
dest = dest[segments.shift()]
}
dest[segments[0]] = value
}

function getPathValue (path) {
function getPathValue(path) {
if (!path) return
const segments = getSegments(path)
return segments.reduce((prev, curr) => {
return prev ? prev[curr] : undefined
}, this)
}
}
20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
{
"name": "haraka-notes",
"version": "1.0.6",
"version": "1.0.7",
"description": "Haraka Notes",
"main": "index.js",
"files": [
"CHANGELOG.md"
],
"scripts": {
"lint": "npx eslint *.js test",
"lintfix": "npx eslint --fix *.js test",
"test": "npx mocha"
"format": "npm run prettier:fix && npm run lint:fix",
"lint": "npx eslint@^8 *.js test",
"lint:fix": "npx eslint@^8 *.js test --fix",
"prettier": "npx prettier . --check",
"prettier:fix": "npx prettier . --write --log-level=warn",
"test": "npx mocha@10",
"versions": "npx @msimerson/dependency-version-checker check",
"versions:fix": "npx @msimerson/dependency-version-checker update && npm run prettier:fix"
},
"repository": {
"type": "git",
Expand All @@ -23,8 +31,6 @@
},
"homepage": "https://github.com/haraka/haraka-notes#readme",
"devDependencies": {
"eslint": "^8.55.0",
"eslint-plugin-haraka": "*",
"mocha": "^10.2.0"
"@haraka/eslint-config": "^1.1.3"
}
}
13 changes: 5 additions & 8 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@

const assert = require('assert')

const Notes = require('../index')
const Notes = require('../index')

describe('notes', () => {

beforeEach((done) => {
this.notes = new Notes()
done()
})

it('exports an object', (done) => {
// console.log(this.notes)
// console.log(this.notes)
assert.ok(typeof this.notes === 'object')
done()
})
Expand Down Expand Up @@ -82,15 +80,14 @@ describe('notes', () => {
})

describe('notes + object', () => {

it('assigns instantiation object', (done) => {
const passIn = {
one: true,
two: "false",
three: "floor",
two: 'false',
three: 'floor',
}
this.notes = this.notes = new Notes(passIn)
assert.deepEqual(this.notes, passIn)
done()
})
})
})
Loading