Token导航 LogoToken导航TokenDH.com
开发只读github未标认证来源可访问许可证需确认审计通过

typeorm-seeding类型播种

Agent Skill

typeorm-seeding 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

353

周安装

15

GitHub Stars

公开资料未说明

下载量

124
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:typeorm-seeding(类型播种)
来源仓库:https://github.com/kage0x3b/typeorm-seeding
仓库路径:skills/typeorm-seeding
安装命令:
npx skills add https://github.com/kage0x3b/typeorm-seeding --skill typeorm-seeding
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/kage0x3b/typeorm-seeding --skill typeorm-seeding

简介

用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,辅助项目协作管理。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中围绕代码变更和协作事项进行整理。
  • 通过 GitHub 安装,使用 npx skills add 命令从 kage0x3b/typeorm-seeding 仓库添加技能。
  • 安装前需确认权限范围和维护状态,避免触发不必要的联网或文件操作。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

typeorm-seeding

Library for creating and seeding TypeORM entities using a factory/seeder pattern. ESM-only, TypeScript.

Four components: Factory (defines how to build entities), SeedingContext (manages factories, sequences, cleanup), Descriptors (relationship/value helpers), Seeder (orchestrates factory calls).

Creating a Factory

import { Factory, sequence, type Faker, type FactorySchema } from '@kage0x3b/typeorm-seeding';
import { UserEntity } from './entities/UserEntity.js';

export class UserFactory extends Factory<UserEntity> {
    readonly model = UserEntity;

    define(faker: Faker): FactorySchema<UserEntity> {
        return {
            firstName: faker.person.firstName(),
            lastName: faker.person.lastName(),
            email: sequence((n) => `user${n}@test.com`),
            role: faker.helpers.arrayElement(['user', 'editor', 'viewer']),
        };
    }
}

Rules:

  • model = the TypeORM entity class
  • define(faker) returns FactorySchema<T> — plain values and/or descriptors for each data property
  • FactorySchema<T> excludes functions and symbols; only covers persistable properties
  • Entity must have no required constructor args (created via new Model() + Object.assign)
  • Source imports use .js extensions (Node16 module resolution)

Factory with relationships

import { Factory, belongsTo, type Faker, type FactorySchema } from '@kage0x3b/typeorm-seeding';
import { PetEntity } from './entities/PetEntity.js';
import { UserFactory } from './UserFactory.js';

export class PetFactory extends Factory<PetEntity> {
    readonly model = PetEntity;

    define(faker: Faker): FactorySchema<PetEntity> {
        return {
            name: faker.animal.petName(),
            species: faker.helpers.arrayElement(['dog', 'cat', 'bird']),
            owner: belongsTo(UserFactory),
        };
    }
}

Descriptors

All descriptors are imported from @kage0x3b/typeorm-seeding.

belongsTo(factoryRef, overridesOrEntity?, variant?)

ManyToOne or owning-side OneToOne. Creates (or references) a parent entity and sets the FK.

owner: belongsTo(UserFactory)                                    // auto-create parent
owner: belongsTo(UserFactory, { role: 'admin' })                 // with overrides
owner: belongsTo(UserFactory, existingUser)                      // existing entity (has PK)
owner: belongsTo(UserFactory, undefined, 'admin')                // with variant
owner: belongsTo(UserFactory, { email: 'a@b.com' }, ['admin', 'inactive'])  // variant + overrides

Disambiguation: if the second arg has a non-nullish primary key (detected via TypeORM metadata), it's an existing entity; otherwise it's overrides.

Each entity gets its own parent. 5 pets with belongsTo(UserFactory) = 5 separate users.

hasMany(factoryRef, count, overrides?, variant?)

OneToMany. Creates count children referencing back to the parent. Resolved after the parent is saved.

pets: hasMany(PetFactory, 3)
pets: hasMany(PetFactory, 2, { species: 'dog' })
pets: hasMany(PetFactory, 3, undefined, 'dog')

hasOne(factoryRef, overrides?, variant?)

Non-owning OneToOne. Creates a single child referencing back to the parent.

profile: hasOne(ProfileFactory)
profile: hasOne(ProfileFactory, { bio: 'Custom bio' })

sequence(callback)

Auto-incrementing counter scoped per factory class, starts at 1.

orderIndex: sequence((n) => n)
email: sequence((n) => `user${n}@test.com`)

ref(label)

Resolves to a previously labeled entity (via .as(label)). Throws if label not registered.

company: ref('acmeCorp')

Variants

Override variants(faker) to define named variations layered on top of define(). The faker instance is passed as an argument, allowing variants to generate dynamic fake data.

export class UserFactory extends Factory<UserEntity> {
    readonly model = UserEntity;

    define(faker: Faker): FactorySchema<UserEntity> {
        return {
            firstName: faker.person.firstName(),
            email: sequence((n) => `user${n}@test.com`),
            role: 'user',
            isActive: true,
        };
    }

    variants(faker: Faker) {
        return {
            admin: {
                role: 'admin',
                email: sequence((n) => `admin${n}@test.com`),
            },
            inactive: { isActive: false },
            withPets: { pets: hasMany(PetFactory, 3) },
        };
    }
}

Usage:

await userFactory.variant('admin').persistOne();
await userFactory.variant('admin', 'inactive').persistOne();  // combine variants

Variants can contain any descriptor. Throws if variant name doesn't exist.

Descriptors in overrides

Overrides accept descriptors, not just plain values. The type is FactoryOverrides<T>.

// sequence in override — unique email per entity
const users = await userFactory.build(5, {
    email: sequence((n) => `batch-${n}@test.com`),
});

// belongsTo in override — create a specific parent
const pet = await petFactory.persistOne({
    owner: belongsTo(UserFactory, { role: 'admin' }),
});

// ref in override — reference a labeled entity
await userFactory.persistOne().as('manager');
const report = await reportFactory.buildOne({
    assignedTo: ref('manager'),
});

Variant in relationship descriptors:

user: belongsTo(UserFactory, undefined, 'admin')   // parent created with admin variant
pets: hasMany(PetFactory, 2, undefined, 'dog')      // children created with dog variant

Creating a Seeder

import { Seeder } from '@kage0x3b/typeorm-seeding';

export class DatabaseSeeder extends Seeder {
    async run(): Promise<void> {
        const admin = await this.factory(UserFactory)
            .variant('admin')
            .persistOne()
            .as('adminUser');

        await this.factory(PetFactory).persist(3, { owner: admin });
        await this.factory(UserFactory).persist(10);
    }
}
  • Extend Seeder, implement run()
  • this.factory(FactoryClass) returns the factory instance (same as this.ctx.getFactory())
  • this.ctx accesses the SeedingContext for refs, store, etc.
  • .as(label) registers the entity for later lookup via ref('label') or ctx.ref<T>('label')
  • .as() only works on persistOne()/buildOne(), not on persist(n)/build(n)

Run seeders: await ctx.runSeeders([SetupSeeder, DataSeeder]); — runs in order, shares context.

Test Setup

Cleanup-per-test pattern

import { DataSource } from 'typeorm';
import { createSeedingContext, SeedingContext } from '@kage0x3b/typeorm-seeding';

let dataSource: DataSource;
let ctx: SeedingContext;

beforeAll(async () => {
    dataSource = new DataSource({
        type: 'better-sqlite3',
        database: ':memory:',
        entities: [UserEntity, PetEntity],
        synchronize: true,
    });
    await dataSource.initialize();
});

beforeEach(() => {
    ctx = createSeedingContext(dataSource);
    // Or with a custom faker instance for deterministic output:
    // ctx = createSeedingContext(dataSource, { faker: seededFaker });
});

afterEach(async () => {
    await ctx.cleanup();   // deletes all created entities in reverse order
});

afterAll(async () => {
    await dataSource.destroy();
});

Transaction-per-test pattern

Each test runs in a transaction that rolls back — no cleanup needed.

let ctx: SeedingContext;
let txCtx: SeedingContext;
let queryRunner: QueryRunner;

beforeAll(async () => {
    // ... dataSource setup ...
    ctx = createSeedingContext(dataSource);
});

beforeEach(async () => {
    ctx.reset();   // resets sequences, refs, and creation log
    queryRunner = dataSource.createQueryRunner();
    await queryRunner.startTransaction();
    txCtx = ctx.withTransaction(queryRunner.manager);
});

afterEach(async () => {
    await queryRunner.rollbackTransaction();
    await queryRunner.release();
});

// In tests, use txCtx instead of ctx:
const user = await txCtx.getFactory(UserFactory).variant('withPets').persistOne();

Common Pitfalls

  • No constructor args: Entities must work with new Entity() + Object.assign. No required constructor parameters.
  • Overrides accept descriptors: Override parameters (FactoryOverrides<T>) accept plain values, null, or any descriptor (belongsTo, hasMany, hasOne, sequence, ref).
  • Overrides replace descriptors: Passing {owner: existingUser} replaces the entire belongsTo descriptor. The factory won't create a new parent.
  • Separate parents per belongsTo: Each entity gets its own parent by default. To share a parent, pass it explicitly as an override.
  • Sequence scoping: Sequences are scoped per factory class, not per variant. UserFactory and UserFactory.variant('admin') share the same counter.
  • .as() on single-entity methods only: .as(label) is only available on persistOne()/buildOne(), not persist(n)/build(n).
  • Enum values in variants: When using TypeScript enums in variants, you may need as any cast due to Partial<FactorySchema<T>> typing: role: UserRole.ADMIN as any.

Advanced

  • Context store: Typed shared state via ctx.store with module augmentation. See docs/public-api.md for details.
  • Labeled refs: .as(label) + ref('label') for ad-hoc entity references across factories/seeders.
  • Transaction support: ctx.withTransaction(em) creates a child context scoped to a transaction.
  • Resolution internals: 7-phase schema resolution. See docs/internal-implementation.md for SchemaResolver phases.
  • Full API reference: See docs/public-api.md for all methods on Factory, SeedingContext, and Seeder.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

33.82%
按下载量换算42

Claude

32.78%
按下载量换算41

Cursor

17.55%
按下载量换算22

Gemini CLI

10.09%
按下载量换算13

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills