Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodger committed Dec 17, 2023
1 parent 62ad784 commit 8c8db5b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 26 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# seneca-allow
Allow messages to proceed if they meet certain criteria.

<!--START:options-->

## Options

_None._

<!--END:options-->

<!--START:action-list-->


## Action Patterns



<!--END:action-list-->

21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@seneca/allow",
"version": "0.2.1",
"main": "dist/allow.js",
"version": "1.0.0",
"main": "dist/Allow.js",
"type": "commonjs",
"types": "dist/allow.d.ts",
"types": "dist/Allow.d.ts",
"description": "Allow messages to proceed if they meet certain criteria",
"homepage": "https://github.com/senecajs/seneca-allow",
"keywords": [
Expand All @@ -16,16 +16,18 @@
"url": "git://github.com/senecajs/seneca-allow.git"
},
"scripts": {
"prettier": "prettier --write .",
"test": "jest --coverage",
"test-some": "jest -t",
"test-watch": "jest --coverage --watchAll",
"watch": "tsc -w -d",
"build": "tsc -d",
"clean": "rm -rf node_modules yarn.lock package-lock.json",
"doc": "seneca-doc",
"clean": "rm -rf node_modules yarn.lock package-lock.json dist",
"reset": "npm run clean && npm i && npm test",
"repo-tag": "REPO_VERSION=`node -e \"console.log(require('./package').version)\"` && echo TAG: v$REPO_VERSION && git commit -a -m v$REPO_VERSION && git push && git tag v$REPO_VERSION && git push --tags;",
"repo-publish": "npm run clean && npm i && npm run repo-publish-quick",
"repo-publish-quick": "npm run build && npm run test && npm run repo-tag && npm publish --access public --registry https://registry.npmjs.org "
"repo-publish-quick": "npm run build && npm run test && npm run doc && npm run repo-tag && npm publish --access public --registry https://registry.npmjs.org "
},
"license": "MIT",
"files": [
Expand All @@ -34,20 +36,21 @@
"LICENSE"
],
"devDependencies": {
"@types/jest": "^29.5.7",
"esbuild": "^0.19.5",
"@types/jest": "^29.5.11",
"esbuild": "^0.19.9",
"esbuild-jest": "^0.5.0",
"jest": "^29.7.0",
"seneca": "^3.23.3",
"seneca-msg-test": "^3.4.0",
"seneca-promisify": "^2.0.0",
"typescript": "^5.2.2"
"seneca-doc": "^2.1.3",
"typescript": "^5.3.3"
},
"peerDependencies": {
"seneca": ">=3",
"seneca-promisify": ">=3"
},
"dependencies": {
"@hapi/hoek": "^11.0.2"
"@hapi/hoek": "^11.0.4"
}
}
38 changes: 26 additions & 12 deletions src/allow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,26 @@
import Hoek from '@hapi/hoek'


function allow(this: any, options: any) {

type Options = {
debug: boolean
check: any[],
wrap: any[],
}

// Default options.
const defaults = {
check: [],
wrap: [],
debug: false,
}


export type AllowOptions = Partial<Options>



function Allow(this: any, options: any) {
const seneca: any = this
const Patrun = seneca.util.Patrun
const Jsonic = seneca.util.Jsonic
Expand Down Expand Up @@ -77,19 +96,14 @@ function allow(this: any, options: any) {
}


// Default options.
allow.defaults = {
check: [],
wrap: [],
debug: false,
}


export default allow

Object.assign(Allow, { defaults })

// Prevent name mangling
Object.defineProperty(Allow, 'name', { value: 'Allow' })

export default Allow

if ('undefined' !== typeof (module)) {
module.exports = allow
if ('undefined' !== typeof module) {
module.exports = Allow
}
13 changes: 8 additions & 5 deletions test/allow.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@


import Allow from '../src/allow'

const Seneca = require('seneca')
const SenecaMsgTest = require('seneca-msg-test')
const AllowMessages = require('./allow.messages').default
import Seneca from 'seneca'
import SenecaMsgTest from 'seneca-msg-test'

import AllowMessages from './allow.messages'



Expand All @@ -19,6 +21,7 @@ describe('allow', () => {
await (SenecaMsgTest(seneca, AllowMessages)())
})


test('allow', async () => {
const seneca = Seneca({ legacy: false })
.test()
Expand All @@ -31,12 +34,12 @@ describe('allow', () => {
})
await seneca.ready()

const allowed = seneca.export('allow/allowed')
const allowed = seneca.export('Allow/allowed')
expect('' + allowed).toEqual(`
a=1 -> <true>
b=2, c=3 -> <true>`.trim())

const check = seneca.export('allow/check')
const check = seneca.export('Allow/check')

expect(check(allowed, { a: 1 }, {})).toBe(true)
expect(check(allowed, { a: 2 }, {})).toBe(false)
Expand Down

0 comments on commit 8c8db5b

Please sign in to comment.