node_modules: update

This commit is contained in:
Dawid Dziurla 2020-11-12 16:37:43 +01:00
parent 4a21c51f2f
commit b91baffed3
No known key found for this signature in database
GPG key ID: 7B6D8368172E9B0B
107 changed files with 3886 additions and 2943 deletions

View file

@ -16,16 +16,27 @@ function groupRestore ({ keys, values, target }) {
}
}
function groupRedact (o, path, censor, isCensorFct) {
function groupRedact (o, path, censor, isCensorFct, censorFctTakesPath) {
const target = get(o, path)
if (target == null) return { keys: null, values: null, target: null, flat: true }
const keys = Object.keys(target)
const length = keys.length
const values = new Array(length)
for (var i = 0; i < length; i++) {
const k = keys[i]
values[i] = target[k]
target[k] = isCensorFct ? censor(target[k]) : censor
const keysLength = keys.length
const pathLength = path.length
const pathWithKey = censorFctTakesPath ? [...path] : undefined
const values = new Array(keysLength)
for (var i = 0; i < keysLength; i++) {
const key = keys[i]
values[i] = target[key]
if (censorFctTakesPath) {
pathWithKey[pathLength] = key
target[key] = censor(target[key], pathWithKey)
} else if (isCensorFct) {
target[key] = censor(target[key])
} else {
target[key] = censor
}
}
return { keys, values, target, flat: true }
}
@ -38,14 +49,15 @@ function nestedRestore (arr) {
}
}
function nestedRedact (store, o, path, ns, censor, isCensorFct) {
function nestedRedact (store, o, path, ns, censor, isCensorFct, censorFctTakesPath) {
const target = get(o, path)
if (target == null) return
const keys = Object.keys(target)
const length = keys.length
for (var i = 0; i < length; i++) {
const keysLength = keys.length
for (var i = 0; i < keysLength; i++) {
const key = keys[i]
const { value, parent, exists } = specialSet(target, key, ns, censor, isCensorFct)
const { value, parent, exists } =
specialSet(target, key, path, ns, censor, isCensorFct, censorFctTakesPath)
if (exists === true && parent !== null) {
store.push({ key: ns[ns.length - 1], target: parent, value })
@ -58,10 +70,11 @@ function has (obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop)
}
function specialSet (o, k, p, v, f) {
function specialSet (o, k, path, afterPath, censor, isCensorFct, censorFctTakesPath) {
const afterPathLen = afterPath.length
const lastPathIndex = afterPathLen - 1
const originalKey = k
var i = -1
var l = p.length
var li = l - 1
var n
var nv
var ov
@ -69,22 +82,26 @@ function specialSet (o, k, p, v, f) {
var exists = true
ov = n = o[k]
if (typeof n !== 'object') return { value: null, parent: null, exists }
while (n != null && ++i < l) {
k = p[i]
while (n != null && ++i < afterPathLen) {
k = afterPath[i]
oov = ov
if (!(k in n)) {
exists = false
break
}
ov = n[k]
nv = f ? v(ov) : v
nv = (i !== li) ? ov : nv
n[k] = (has(n, k) && nv === ov) || (nv === undefined && v !== undefined) ? n[k] : nv
nv = (i !== lastPathIndex)
? ov
: (isCensorFct
? (censorFctTakesPath ? censor(ov, [...path, originalKey, ...afterPath]) : censor(ov))
: censor)
n[k] = (has(n, k) && nv === ov) || (nv === undefined && censor !== undefined) ? n[k] : nv
n = n[k]
if (typeof n !== 'object') break
}
return { value: ov, parent: oov, exists }
}
function get (o, p) {
var i = -1
var l = p.length

View file

@ -4,16 +4,16 @@ const rx = require('./rx')
module.exports = redactor
function redactor ({ secret, serialize, wcLen, strict, isCensorFct }, state) {
function redactor ({ secret, serialize, wcLen, strict, isCensorFct, censorFctTakesPath }, state) {
/* eslint-disable-next-line */
const redact = Function('o', `
if (typeof o !== 'object' || o == null) {
${strictImpl(strict, serialize)}
}
const { censor, secret } = this
${redactTmpl(secret, isCensorFct)}
${redactTmpl(secret, isCensorFct, censorFctTakesPath)}
this.compileRestore()
${dynamicRedactTmpl(wcLen > 0, isCensorFct)}
${dynamicRedactTmpl(wcLen > 0, isCensorFct, censorFctTakesPath)}
${resultTmpl(serialize)}
`).bind(state)
@ -24,9 +24,9 @@ function redactor ({ secret, serialize, wcLen, strict, isCensorFct }, state) {
return redact
}
function redactTmpl (secret, isCensorFct) {
function redactTmpl (secret, isCensorFct, censorFctTakesPath) {
return Object.keys(secret).map((path) => {
const { escPath, leadingBracket } = secret[path]
const { escPath, leadingBracket, path: arrPath } = secret[path]
const skip = leadingBracket ? 1 : 0
const delim = leadingBracket ? '' : '.'
const hops = []
@ -49,6 +49,11 @@ function redactTmpl (secret, isCensorFct) {
`).join('\n')}
}
`
const censorArgs = censorFctTakesPath
? `val, ${JSON.stringify(arrPath)}`
: `val`
return `
if (${existence}) {
const val = o${delim}${path}
@ -56,7 +61,7 @@ function redactTmpl (secret, isCensorFct) {
secret[${escPath}].precensored = true
} else {
secret[${escPath}].val = val
o${delim}${path} = ${isCensorFct ? 'censor(val)' : 'censor'}
o${delim}${path} = ${isCensorFct ? `censor(${censorArgs})` : 'censor'}
${circularDetection}
}
}
@ -64,7 +69,7 @@ function redactTmpl (secret, isCensorFct) {
}).join('\n')
}
function dynamicRedactTmpl (hasWildcards, isCensorFct) {
function dynamicRedactTmpl (hasWildcards, isCensorFct, censorFctTakesPath) {
return hasWildcards === true ? `
{
const { wildcards, wcLen, groupRedact, nestedRedact } = this
@ -72,8 +77,8 @@ function dynamicRedactTmpl (hasWildcards, isCensorFct) {
const { before, beforeStr, after, nested } = wildcards[i]
if (nested === true) {
secret[beforeStr] = secret[beforeStr] || []
nestedRedact(secret[beforeStr], o, before, after, censor, ${isCensorFct})
} else secret[beforeStr] = groupRedact(o, before, censor, ${isCensorFct})
nestedRedact(secret[beforeStr], o, before, after, censor, ${isCensorFct}, ${censorFctTakesPath})
} else secret[beforeStr] = groupRedact(o, before, censor, ${isCensorFct}, ${censorFctTakesPath})
}
}
` : ''

13
node_modules/fast-redact/lib/rx.js generated vendored
View file

@ -1,3 +1,16 @@
'use strict'
module.exports = /[^.[\]]+|\[((?:.)*?)\]/g
/*
Regular expression explanation:
Alt 1: /[^.[\]]+/ - Match one or more characters that are *not* a dot (.)
opening square bracket ([) or closing square bracket (])
Alt 2: /\[((?:.)*?)\]/ - If the char IS dot or square bracket, then create a capture
group (which will be capture group $1) that matches anything
within square brackets. Expansion is lazy so it will
stop matching as soon as the first closing bracket is met `]`
(rather than continuing to match until the final closing bracket).
*/

View file

@ -6,7 +6,6 @@ function state (o) {
const {
secret,
censor,
isCensorFct,
compileRestore,
serialize,
groupRedact,
@ -14,8 +13,7 @@ function state (o) {
wildcards,
wcLen
} = o
const builder = [{ secret, censor, isCensorFct, compileRestore }]
builder.push({ secret })
const builder = [{ secret, censor, compileRestore }]
if (serialize !== false) builder.push({ serialize })
if (wcLen > 0) builder.push({ groupRedact, nestedRedact, wildcards, wcLen })
return Object.assign(...builder)

View file

@ -6,7 +6,7 @@ module.exports = validator
function validator (opts = {}) {
const {
ERR_PATHS_MUST_BE_STRINGS = () => 'fast-redact - Paths must be strings',
ERR_PATHS_MUST_BE_STRINGS = () => 'fast-redact - Paths must be (non-empty) strings',
ERR_INVALID_PATH = (s) => `fast-redact Invalid path (${s})`
} = opts