Skip to content

Thank you #5

@jandockx

Description

@jandockx

After 2 longs days of searching and dispair, your library seems to save me. Thank you.

I am a bit worried about the viability, though, seeing your previous responses. Is this a dead project for you, or would you still consider taking PRs, and releasing new versions?

Context

I am in need to determine whether a first pattern raa is covered by another ram.

Interesting references I found are:

The approach that I found referenced was

  1. create ram|raa, the pattern that expresses that a string must match ram or raa
  2. derive DFA(ram|raa) and DFA(ram), and minimize them
  3. if the 2 resulting minimized DFAs are isomorph, raa is covered by ram

Indeed, ram|raa (ram or raa) allows more strings to match than ram alone. If however ram|raa turns out to match exactly the same set of strings as ram alone, it means that all the strings that are matched by raa are already in the set of strings matched by ram, i.e., raa is covered by ram.

Alternatively, we can determine the intersection of raa and ram:

  1. create ram&raa, the pattern that expresses that a string must match both ram and raa
  2. derive DFA(ram&raa) and DFA(raa), and minimize them
  3. if the 2 resulting minimized [DFA]s are isomorph, raa is covered by ram

Indeed, ram&raa (ram and raa) allows less strings to match than raa alone. If however ram&raa turns out to match exactly the same set of strings as raa alone, it means that there are no strings that are matched by raa that are not matched by ram, i.e., raa is covered by ram.

This now seems to be realised trivially by your library:

const intersect = require('glob-intersection')

function minimize (pattern) {
  return intersect(pattern, pattern)
}

function covered (raaPattern, ramPattern) {
  let intersection = intersect(raaPattern, ramPattern)
  console.log(`${raaPattern} ∩ ${ramPattern} = ${intersection}`)
  const result = typeof intersection === 'string' && intersection === minimize(raaPattern)
  console.log(`${raaPattern} ⊆ ${ramPattern} ? ${result}`)
  return result
}

covered('/I/*/p523564.faa.bar.baz/**', '/I/**')
covered('/I/**', '/I/*/p523564.faa.bar.baz/**')
covered('/I/*/p523564.faa.bar.baz/**', '/I/*')
covered('/I/*/p523564.faa.bar.baz/service/instance', '/I/host/p523564.faa.bar.baz/**')

covered('{GET,PUT,DELETE}', '*')
covered('*', '{GET,PUT,DELETE}')
covered('PUT', 'DELETE')
covered('PUT', '{GET,DELETE}')
covered('{GET,PUT}', '{GET,PUT,DELETE}') // requires minimisation of raaPattern

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions