Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input is not a string type (crash on remove method) #66

Closed
thomscoder opened this issue Jul 30, 2022 · 2 comments
Closed

input is not a string type (crash on remove method) #66

thomscoder opened this issue Jul 30, 2022 · 2 comments

Comments

@thomscoder
Copy link
Contributor

Describe the bug
The remove method makes Lyra beta_17 crash.

It gives the following error

TypeError: input.toLowerCase is not a function

at

const tokens = input.toLowerCase().split(splitRule);

To Reproduce

const movieDB = create({
  schema: {
    title: 'string',
    director: 'string',
    plot: 'string',
    year: 'number',
    isFavorite: 'boolean'
  }
});

const { id: harryPotter } = insert(movieDB, {
  title: 'Harry Potter and the Philosopher\'s Stone',
  director: 'Chris Columbus',
  plot: 'Harry Potter, an eleven-year-old orphan, discovers that he is a wizard and is invited to study at Hogwarts. Even as he escapes a dreary life and enters a world of magic, he finds trouble awaiting him.',
  year: 2001,
  isFavorite: false
});


remove(movieDB, harryPotter);

Screenshots
Schermata 2022-07-31 alle 00 31 24

Desktop (please complete the following information):

  • OS: Monterey 12.4
  • Node: 14.16.0 <= x <= 18.7.0
@thomscoder
Copy link
Contributor Author

EXPANDING: I was writing the tests for this and something very interesting happened.
Consider the following example:

const db = create({
  schema: {
    quote: "string",
    author: "string",
  },
});

const {id: tomRiddle} = insert(db, {
  quote: "Harry Potter, the boy who lived, come to die. Avada kedavra.",
  author: "Tom Riddle",
});

remove(db, tomRiddle);

The test passes. It successfully deletes the document!
But it fails (with the aforementioned TypeError giving a typeof input == 'object') with this:

const db = create({
  schema: {
    quote: "string",
    author: {
      name: "string",
      surname: "string",
    },
  },
});

const {id: tomRiddle} = insert(db, {
  quote: "Harry Potter, the boy who lived, come to die. Avada kedavra.",
  author: {
    name: "Tom",
    surname: "Riddle",
  },
});

remove(db, tomRiddle);

The interesting thing is in

export function tokenize(input: string, language: Language = "english") {
  const splitRule = splitRegex[language];
  const tokens = input.toLowerCase().split(splitRule); // the error occurs in here
  return Array.from(new Set(trim(tokens)));
}

If the Schema has properties of type !== string, the typeof input is equal to the very first property in the Schema !== string

const movieDB = create({
    schema: {
      title: 'string',
      director: 'string',
      plot: 'string',
      year: 'number',
      isFavorite: 'boolean'
    }
  });

const { id: harryPotter } = insert(movieDB, {
  title: 'Harry Potter and the Philosopher\'s Stone',
  director: 'Chris Columbus',
  plot: 'Harry Potter, an eleven-year-old orphan, discovers that he is a wizard and is invited to study at Hogwarts. Even as he escapes a dreary life and enters a world of magic, he finds trouble awaiting him.',
  year: 2001,
  isFavorite: false
});

remove(movieDB, harryPotter); 

typeof input == 'number'

const movieDB = create({
    schema: {
      title: 'string',
      director: 'string',
      plot: 'string',
      isFavorite: 'boolean'
    }
  });

const { id: harryPotter } = insert(movieDB, {
  title: 'Harry Potter and the Philosopher\'s Stone',
  director: 'Chris Columbus',
  plot: 'Harry Potter, an eleven-year-old orphan, discovers that he is a wizard and is invited to study at Hogwarts. Even as he escapes a dreary life and enters a world of magic, he finds trouble awaiting him.',
  isFavorite: false
});

remove(movieDB, harryPotter);

typeof input == 'boolean'


Hope it helps 😄

@micheleriva
Copy link
Member

Thank you @thomscoder!

I fixed this with 3cb1c75, will be published with the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants