GenerateWeightedCount Class — drizzle-orm Architecture
Architecture documentation for the GenerateWeightedCount class in Generators.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 1eb4cc3b_1b3f_0a33_4f89_0accb688801e["GenerateWeightedCount"] e5cee001_0354_7e76_ef0a_06dca71dc8ce["Generators.ts"] 1eb4cc3b_1b3f_0a33_4f89_0accb688801e -->|defined in| e5cee001_0354_7e76_ef0a_06dca71dc8ce e7bb7ead_27db_e586_431c_367e654ae94a["init()"] 1eb4cc3b_1b3f_0a33_4f89_0accb688801e -->|method| e7bb7ead_27db_e586_431c_367e654ae94a 74b81297_5013_ca1d_0662_ecfc835701bf["generate()"] 1eb4cc3b_1b3f_0a33_4f89_0accb688801e -->|method| 74b81297_5013_ca1d_0662_ecfc835701bf
Relationship Graph
Source Code
drizzle-seed/src/services/Generators.ts lines 132–168
export class GenerateWeightedCount extends AbstractGenerator<{}> {
static override readonly entityKind: string = 'GenerateWeightedCount';
private state: {
rng: prand.RandomGenerator;
weightedIndices: number[];
weightedCount: { weight: number; count: number | number[] }[];
} | undefined;
override init({ seed, count }: { count: { weight: number; count: number | number[] }[]; seed: number }) {
const rng = prand.xoroshiro128plus(seed);
const weightedIndices = getWeightedIndices(count.map((val) => val.weight));
this.state = { rng, weightedIndices, weightedCount: count };
}
generate() {
if (this.state === undefined) {
throw new Error('state is not defined.');
}
// logic for this generator
let idx: number;
const weightedCount = this.state.weightedCount;
[idx, this.state.rng] = prand.uniformIntDistribution(0, this.state.weightedIndices.length - 1, this.state.rng);
const objIdx = this.state.weightedIndices[idx] as number;
if (typeof weightedCount[objIdx]!.count === 'number') {
return weightedCount[objIdx]!.count as number;
} else {
// typeof weightedCount[objIdx]!.count === 'object' // number[]
const possCounts = weightedCount[objIdx]!.count as number[];
[idx, this.state.rng] = prand.uniformIntDistribution(0, possCounts.length - 1, this.state.rng);
return possCounts[idx]!;
}
}
}
Domain
Defined In
Source
Frequently Asked Questions
What is the GenerateWeightedCount class?
GenerateWeightedCount is a class in the drizzle-orm codebase, defined in drizzle-seed/src/services/Generators.ts.
Where is GenerateWeightedCount defined?
GenerateWeightedCount is defined in drizzle-seed/src/services/Generators.ts at line 132.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free