Skip to content

Commit

Permalink
console.trace deprecated usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mixmix committed Dec 10, 2023
1 parent 2731cf1 commit 1d39893
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const NotAllowedTypeError = (type) => new Error(
`recps-guard: public messages of type "${type}" not allowed`
)

let warnings = 0

module.exports = {
name: 'recpsGuard',
version: require('./package.json').version,
Expand All @@ -22,10 +24,14 @@ module.exports = {
function publishHook (publish, args) {
const [input, cb] = args

const isExplictAllow = (
input.allowPublic === true ||
get(input, ['options', 'allowPublic']) === true // legacy support
)
const modernAllow = input.allowPublic === true
const legacyAllow = get(input, ['options', 'allowPublic']) === true
if (legacyAllow && warnings < 5) {
console.trace('input.options.allowPublic is deprecated, please use input.allowPublic')
warnings++
}

const isExplictAllow = (modernAllow || legacyAllow)

if (isExplictAllow) {
const content = input.content
Expand Down
2 changes: 1 addition & 1 deletion test/db2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test('db2', async t => {
t.deepEqual(data.value.content, content, '(msg content unencrypted, allowPublic pruned). db.create')
})
.catch(err => {
t.error(err, 'msgs { content, options: { allowPublic: true } allowed. db.create')
t.error(err, 'msgs { content, { allowPublic: true } db.create')
})

const weird = {
Expand Down
2 changes: 1 addition & 1 deletion test/install-order.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('installed in right order', t => {

const input = {
content,
options: { allowPublic: true }
allowPublic: true
}

server.publish(input, (err, msg) => {
Expand Down
2 changes: 1 addition & 1 deletion test/not-installed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test('not installed', t => {

const content = { type: 'profile' }

ssb.publish({ content, options: { allowPublic: true } }, (err) => {
ssb.publish({ content, allowPublic: true }, (err) => {
t.match(err.message, /type must be a string/)
ssb.close(t.end)
})
Expand Down

0 comments on commit 1d39893

Please sign in to comment.