supabase-community/copycat

someOf returns an empty array

Closed this issue · 4 comments

Hi,

It seems like copycat.someOf is always returning an empty array regardless what range I pick. I've pasted the minimum reproducible example below. Would you be able to have a look into this please?

import { createSeedClient } from '@snaplet/seed';
import { copycat } from '@snaplet/copycat'

const listOfStrings = ['a', 'b', 'c', 'd', 'e'];

const seed = await createSeedClient({
  dryRun: process.env.DRY !== '0',
});

await seed.$resetDatabase()

await seed.users(x => x(10, {
  chosenStrings: (ctx) => copycat.someOf(ctx.seed, [0, 3], listOfStrings),
}));

I am using the following versions:

"devDependencies": {
  "@snaplet/copycat": "^4.1.0",
  "@snaplet/seed": "^0.88.2",
  "snaplet": "^0.88.2"
}

Hi @rickaw, I can indeed reproduce this. Will fix asap, sorry about this!

In the meantime, if you are alright with a single value instead of a range (e.g. "pick 3 of the following items", rather than "pick 0 to 3 of the following items"), you can work around this with:

  chosenStrings: (ctx) => copycat.someOf(ctx.seed, 3, listOfStrings),

Hi again @rickaw, should be solved now. Can you upgrade to @snaplet/copycat@5.0.0?

Closing as solved until then!

Amazing thank you for fixing it so quickly!