From 1d398935dec5091a62eac3c6945541b2c2127eb3 Mon Sep 17 00:00:00 2001 From: mixmix Date: Mon, 11 Dec 2023 10:56:41 +1300 Subject: [PATCH] console.trace deprecated usage --- index.js | 14 ++++++++++---- test/db2.test.js | 2 +- test/install-order.test.js | 2 +- test/not-installed.test.js | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index cbd4150..05fd90b 100644 --- a/index.js +++ b/index.js @@ -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, @@ -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 diff --git a/test/db2.test.js b/test/db2.test.js index 46486ea..b4b7eae 100644 --- a/test/db2.test.js +++ b/test/db2.test.js @@ -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 = { diff --git a/test/install-order.test.js b/test/install-order.test.js index bd9ece6..3ae80a1 100644 --- a/test/install-order.test.js +++ b/test/install-order.test.js @@ -24,7 +24,7 @@ test('installed in right order', t => { const input = { content, - options: { allowPublic: true } + allowPublic: true } server.publish(input, (err, msg) => { diff --git a/test/not-installed.test.js b/test/not-installed.test.js index 718a9df..889e857 100644 --- a/test/not-installed.test.js +++ b/test/not-installed.test.js @@ -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) })