@geekmidas/testkit 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Factory-z2m01hMj.mjs → Factory-BFVnMMCC.mjs} +2 -2
- package/dist/Factory-BFVnMMCC.mjs.map +1 -0
- package/dist/{Factory-Cmr3s3-s.d.mts → Factory-BcGJjLc8.d.mts} +23 -9
- package/dist/{Factory-WMhTNZ9S.cjs → Factory-BhjUOBWN.cjs} +2 -2
- package/dist/Factory-BhjUOBWN.cjs.map +1 -0
- package/dist/{Factory-D7oHtI2D.d.cts → Factory-IdfEkOeT.d.cts} +24 -10
- package/dist/Factory.cjs +1 -1
- package/dist/Factory.d.cts +3 -3
- package/dist/Factory.d.mts +2 -2
- package/dist/Factory.mjs +1 -1
- package/dist/{KyselyFactory-DaaCykWP.cjs → KyselyFactory-BFqVIn_0.cjs} +21 -4
- package/dist/KyselyFactory-BFqVIn_0.cjs.map +1 -0
- package/dist/{KyselyFactory-BTdygZ-i.d.mts → KyselyFactory-Cj-EultY.d.mts} +17 -4
- package/dist/{KyselyFactory-CXY5gJk2.mjs → KyselyFactory-DMswpwji.mjs} +21 -4
- package/dist/KyselyFactory-DMswpwji.mjs.map +1 -0
- package/dist/{KyselyFactory-dYdviox2.d.cts → KyselyFactory-Dxhi_ZkA.d.cts} +18 -5
- package/dist/KyselyFactory.cjs +2 -2
- package/dist/KyselyFactory.d.cts +3 -3
- package/dist/KyselyFactory.d.mts +2 -2
- package/dist/KyselyFactory.mjs +2 -2
- package/dist/{ObjectionFactory-0gUdx8bB.d.cts → ObjectionFactory-BRAkAByP.d.cts} +18 -5
- package/dist/{ObjectionFactory-Eb04AOnv.cjs → ObjectionFactory-BeFBYcan.cjs} +21 -4
- package/dist/ObjectionFactory-BeFBYcan.cjs.map +1 -0
- package/dist/{ObjectionFactory-BagGjikT.d.mts → ObjectionFactory-DL4qkuF1.d.mts} +17 -4
- package/dist/{ObjectionFactory-zf2fLKrL.mjs → ObjectionFactory-QCJ7u0Ql.mjs} +21 -4
- package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +1 -0
- package/dist/ObjectionFactory.cjs +2 -2
- package/dist/ObjectionFactory.d.cts +3 -3
- package/dist/ObjectionFactory.d.mts +2 -2
- package/dist/ObjectionFactory.mjs +2 -2
- package/dist/benchmark.cjs +49 -0
- package/dist/benchmark.cjs.map +1 -0
- package/dist/benchmark.d.cts +35 -0
- package/dist/benchmark.d.mts +35 -0
- package/dist/benchmark.mjs +45 -0
- package/dist/benchmark.mjs.map +1 -0
- package/dist/better-auth.d.cts +2 -2
- package/dist/{directory-BUcnztHI.d.cts → directory-Mi7tdOuD.d.cts} +3 -3
- package/dist/{faker-Dg3trU4a.d.cts → faker-CbYiF-8_.d.cts} +3 -3
- package/dist/faker.d.cts +1 -1
- package/dist/kysely.cjs +2 -2
- package/dist/kysely.cjs.map +1 -1
- package/dist/kysely.d.cts +4 -4
- package/dist/kysely.d.mts +3 -3
- package/dist/kysely.mjs +2 -2
- package/dist/kysely.mjs.map +1 -1
- package/dist/objection.cjs +2 -2
- package/dist/objection.cjs.map +1 -1
- package/dist/objection.d.cts +4 -4
- package/dist/objection.d.mts +3 -3
- package/dist/objection.mjs +2 -2
- package/dist/objection.mjs.map +1 -1
- package/dist/os/directory.d.cts +1 -1
- package/dist/os/index.d.cts +1 -1
- package/package.json +6 -1
- package/src/Factory.ts +25 -11
- package/src/KyselyFactory.ts +21 -4
- package/src/ObjectionFactory.ts +21 -4
- package/src/__tests__/Factory.spec.ts +16 -10
- package/src/__tests__/KyselyFactory.spec.ts +12 -6
- package/src/__tests__/ObjectionFactory.spec.ts +57 -48
- package/src/__tests__/integration.spec.ts +16 -8
- package/src/benchmark.ts +48 -0
- package/src/kysely.ts +1 -0
- package/src/objection.ts +1 -0
- package/dist/Factory-WMhTNZ9S.cjs.map +0 -1
- package/dist/Factory-z2m01hMj.mjs.map +0 -1
- package/dist/KyselyFactory-CXY5gJk2.mjs.map +0 -1
- package/dist/KyselyFactory-DaaCykWP.cjs.map +0 -1
- package/dist/ObjectionFactory-Eb04AOnv.cjs.map +0 -1
- package/dist/ObjectionFactory-zf2fLKrL.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObjectionFactory-BeFBYcan.cjs","names":["Factory","seedFn: Seed","ModelClass: TModel","defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Knex;\n faker: FakerFactory;\n }) =>\n | Partial<InstanceType<TModel>>\n | Promise<Partial<InstanceType<TModel>>>","autoInsert?: boolean","attrs: Attrs","factory: Factory","db: Knex","fakerInstance: FakerFactory","data: Partial<InstanceType<TModel>>","builders: Builders","seeds: Seeds","builderName: K","attrs?: Parameters<Builders[K]>[0]","faker","count: number","attrs?: any","records: any[]","record: any","seedName: K","attrs?: ExtractSeedAttrs<Seeds[K]>"],"sources":["../src/ObjectionFactory.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport type { Model } from 'objection';\nimport { type ExtractSeedAttrs, Factory, type FactorySeed } from './Factory.ts';\nimport { type FakerFactory, faker } from './faker.ts';\n\n/**\n * Factory implementation for Objection.js ORM, providing test data creation utilities.\n * Extends the base Factory class with Objection.js-specific database operations.\n *\n * @template Builders - Record of builder functions for creating entities\n * @template Seeds - Record of seed functions for complex test scenarios\n *\n * @example\n * ```typescript\n * // Define your models with Objection.js\n * class User extends Model {\n * static tableName = 'users';\n * }\n *\n * // Create builders\n * const builders = {\n * user: ObjectionFactory.createBuilder(User, ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * })),\n * post: ObjectionFactory.createBuilder(Post, ({ attrs }) => ({\n * title: 'Test Post',\n * content: 'Test content',\n * ...attrs\n * })),\n * };\n *\n * // Create factory instance\n * const factory = new ObjectionFactory(builders, seeds, knex);\n *\n * // Use in tests\n * const user = await factory.insert('user', { name: 'John Doe' });\n * ```\n */\nexport class ObjectionFactory<\n Builders extends Record<string, any>,\n Seeds extends Record<string, any>,\n> extends Factory<Builders, Seeds> {\n /**\n * Creates a typed seed function with proper type inference.\n * Inherits from the base Factory class implementation.\n *\n * @template Seed - The seed function type\n * @param seedFn - The seed function to wrap (receives { attrs, factory, db } object)\n * @returns The same seed function with proper typing\n *\n * @example\n * ```typescript\n * const seeds = {\n * userWithPosts: ObjectionFactory.createSeed(\n * async ({ attrs, factory }) => {\n * const user = await factory.insert('user', attrs);\n * await factory.insertMany(3, 'post', { userId: user.id });\n * return user;\n * },\n * ),\n * };\n * ```\n */\n static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {\n return Factory.createSeed(seedFn);\n }\n\n /**\n * Creates a typed builder function for Objection.js models.\n * This is a utility method that helps create builders with proper type inference.\n *\n * @template TModel - The Objection.js Model class type\n * @template Attrs - The attributes type for the builder (defaults to Partial of model)\n * @template Factory - The factory instance type\n * @template Result - The result type (defaults to the model instance)\n *\n * @param ModelClass - The Objection.js Model class\n * @param defaults - Optional function to provide default values (receives destructured context)\n * @param autoInsert - Whether to automatically insert the record (default: true)\n * @returns A builder function that creates and optionally inserts records\n *\n * @example\n * ```typescript\n * // Create a simple builder with defaults - destructure only what you need\n * const userBuilder = ObjectionFactory.createBuilder(User,\n * ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * createdAt: new Date(),\n * ...attrs\n * })\n * );\n *\n * // Only need faker? Just destructure that\n * const leaveTypeBuilder = ObjectionFactory.createBuilder(LeaveType,\n * ({ faker }) => ({\n * name: faker.helpers.arrayElement(['Annual', 'Sick', 'Maternity']),\n * code: faker.string.alpha({ length: 3, casing: 'upper' }),\n * })\n * );\n *\n * // Create a builder that doesn't auto-insert (useful for nested inserts)\n * const addressBuilder = ObjectionFactory.createBuilder(Address,\n * ({ attrs }) => ({\n * street: '123 Main St',\n * city: 'Anytown',\n * ...attrs\n * }),\n * false // Don't auto-insert\n * );\n *\n * // Use with relations\n * const postBuilder = ObjectionFactory.createBuilder(Post,\n * async ({ attrs, factory, faker }) => ({\n * title: faker.lorem.sentence(),\n * content: faker.lorem.paragraphs(),\n * authorId: attrs.authorId || (await factory.insert('user')).id,\n * ...attrs\n * })\n * );\n * ```\n */\n static createBuilder<\n TModel extends typeof Model,\n Attrs extends Partial<InstanceType<TModel>> = Partial<InstanceType<TModel>>,\n Factory = any,\n Result = InstanceType<TModel>,\n >(\n ModelClass: TModel,\n defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Knex;\n faker: FakerFactory;\n }) =>\n | Partial<InstanceType<TModel>>\n | Promise<Partial<InstanceType<TModel>>>,\n autoInsert?: boolean,\n ): (\n attrs: Attrs,\n factory: Factory,\n db: Knex,\n faker: FakerFactory,\n ) => Promise<Result> {\n return async (\n attrs: Attrs,\n factory: Factory,\n db: Knex,\n fakerInstance: FakerFactory,\n ) => {\n // Start with attributes\n let data: Partial<InstanceType<TModel>> = { ...attrs };\n\n // Apply defaults\n if (defaults) {\n const defaultValues = await defaults({\n attrs,\n factory,\n db,\n faker: fakerInstance,\n });\n data = { ...defaultValues, ...data };\n }\n\n // Create model instance\n const model = ModelClass.fromJson(data) as InstanceType<TModel>;\n\n // Handle insertion based on autoInsert flag\n if (autoInsert !== false) {\n // Auto insert is enabled by default\n // Extract only defined values for insertion\n const insertData = Object.entries(model).reduce((acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n }, {} as any);\n\n // Use static query method to insert data directly\n // @ts-ignore\n const result = await ModelClass.query(db).insert(insertData);\n return result as Result;\n } else {\n // Return model for factory to handle insertion\n return model as Result;\n }\n };\n }\n\n /**\n * Creates a new ObjectionFactory instance.\n *\n * @param builders - Record of builder functions for creating individual entities\n * @param seeds - Record of seed functions for creating complex test scenarios\n * @param db - Knex database connection instance\n */\n constructor(\n private builders: Builders,\n private seeds: Seeds,\n private db: Knex,\n ) {\n super();\n }\n\n /**\n * Inserts a single record into the database using the specified builder.\n * Uses Objection.js's insertGraph method to handle nested relations.\n *\n * @template K - The builder name (must be a key of Builders)\n * @param builderName - The name of the builder to use\n * @param attrs - Optional attributes to override builder defaults\n * @returns A promise resolving to the inserted record with all relations\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert with defaults\n * const user = await factory.insert('user');\n *\n * // Insert with overrides\n * const adminUser = await factory.insert('user', {\n * email: 'admin@example.com',\n * role: 'admin'\n * });\n *\n * // Insert with nested relations\n * const userWithProfile = await factory.insert('user', {\n * name: 'John Doe',\n * profile: {\n * bio: 'Software Developer',\n * avatar: 'avatar.jpg'\n * }\n * });\n * ```\n */\n async insert<K extends keyof Builders>(\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Factory \"${\n builderName as string\n }\" does not exist. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const result = await this.builders[builderName](\n attrs || {},\n this,\n this.db,\n faker,\n );\n\n // If the builder returns a model instance, insert it\n if (result && typeof result.$query === 'function') {\n // Extract data from model, excluding undefined values and id\n const insertData = Object.entries(result).reduce((acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n }, {} as any);\n\n // Use the model's constructor to get the query builder\n return await result.constructor.query(this.db).insert(insertData);\n }\n\n // Otherwise, assume the builder handled insertion itself\n return result;\n }\n /**\n * Inserts multiple records into the database using the specified builder.\n * Supports both static attributes and dynamic attribute generation via a function.\n *\n * @param count - The number of records to insert\n * @param builderName - The name of the builder to use\n * @param attrs - Static attributes or a function that generates attributes for each record\n * @returns A promise resolving to an array of inserted records\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert multiple with same attributes\n * const users = await factory.insertMany(5, 'user', { role: 'member' });\n *\n * // Insert multiple with dynamic attributes\n * const posts = await factory.insertMany(10, 'post', (idx) => ({\n * title: `Post ${idx + 1}`,\n * content: `Content for post ${idx + 1}`,\n * publishedAt: new Date()\n * }));\n *\n * // Create users with sequential emails\n * const admins = await factory.insertMany(3, 'user', (idx) => ({\n * email: `admin${idx + 1}@example.com`,\n * role: 'admin'\n * }));\n * ```\n */\n // Method overloads for better type inference\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs: (idx: number, faker: FakerFactory) => Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: any,\n ): Promise<Awaited<ReturnType<Builders[K]>>[]> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Builder \"${\n builderName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const records: any[] = [];\n for (let i = 0; i < count; i++) {\n const newAttrs =\n typeof attrs === 'function' ? await (attrs as any)(i, faker) : attrs;\n\n records.push(\n this.builders[builderName](newAttrs, this, this.db, faker).then(\n (record: any) => {\n // If the builder returns a model instance, insert it\n if (record && typeof record.$query === 'function') {\n // Extract data from model, excluding undefined values and id\n const insertData = Object.entries(record).reduce(\n (acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n },\n {} as any,\n );\n\n // Use the model's constructor to get the query builder\n return record.constructor.query(this.db).insert(insertData);\n }\n // Otherwise, assume the builder handled insertion itself\n return record;\n },\n ),\n );\n }\n\n return Promise.all(records);\n }\n /**\n * Executes a seed function to create complex test scenarios with multiple related records.\n * Seeds are useful for setting up complete test environments with realistic data relationships.\n *\n * @template K - The seed name (must be a key of Seeds)\n * @param seedName - The name of the seed to execute\n * @param attrs - Optional configuration attributes for the seed\n * @returns The result of the seed function (typically the primary record created)\n * @throws Error if the specified seed doesn't exist\n *\n * @example\n * ```typescript\n * // Execute a simple seed\n * const user = await factory.seed('userWithProfile');\n *\n * // Execute a seed with configuration\n * const author = await factory.seed('authorWithBooks', {\n * bookCount: 5,\n * includeReviews: true\n * });\n *\n * // Use seed result in tests with Objection.js relations\n * const company = await factory.seed('companyWithDepartments', {\n * departmentCount: 3,\n * employeesPerDepartment: 10\n * });\n *\n * // Access eager loaded relations\n * const companyWithRelations = await Company.query()\n * .findById(company.id)\n * .withGraphFetched('[departments.employees]');\n * ```\n */\n seed<K extends keyof Seeds>(\n seedName: K,\n attrs?: ExtractSeedAttrs<Seeds[K]>,\n ): ReturnType<Seeds[K]> {\n if (!(seedName in this.seeds)) {\n throw new Error(\n `Seed \"${\n seedName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n return this.seeds[seedName]({\n attrs: attrs || {},\n factory: this,\n db: this.db,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,mBAAb,cAGUA,wBAAyB;;;;;;;;;;;;;;;;;;;;;;CAsBjC,OAAO,WAAqCC,QAAoB;AAC9D,SAAO,wBAAQ,WAAW,OAAO;CAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DD,OAAO,cAMLC,YACAC,UAQAC,YAMmB;AACnB,SAAO,OACLC,OACAC,SACAC,IACAC,kBACG;GAEH,IAAIC,OAAsC,EAAE,GAAG,MAAO;AAGtD,OAAI,UAAU;IACZ,MAAM,gBAAgB,MAAM,SAAS;KACnC;KACA;KACA;KACA,OAAO;IACR,EAAC;AACF,WAAO;KAAE,GAAG;KAAe,GAAG;IAAM;GACrC;GAGD,MAAM,QAAQ,WAAW,SAAS,KAAK;AAGvC,OAAI,eAAe,OAAO;IAGxB,MAAM,aAAa,OAAO,QAAQ,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,MAAM,KAAK;AACrE,SAAI,oBAAuB,QAAQ,KACjC,KAAI,OAAO;AAEb,YAAO;IACR,GAAE,CAAE,EAAQ;IAIb,MAAM,SAAS,MAAM,WAAW,MAAM,GAAG,CAAC,OAAO,WAAW;AAC5D,WAAO;GACR,MAEC,QAAO;EAEV;CACF;;;;;;;;CASD,YACUC,UACAC,OACAJ,IACR;AACA,SAAO;EAJC;EACA;EACA;CAGT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiCD,MAAM,OACJK,aACAC,OAC2C;AAC3C,QAAM,eAAe,KAAK,UACxB,OAAM,IAAI,OACP,WACC,YACD;EAIL,MAAM,SAAS,MAAM,KAAK,SAAS,aACjC,SAAS,CAAE,GACX,MACA,KAAK,IACLC,oBACD;AAGD,MAAI,iBAAiB,OAAO,WAAW,YAAY;GAEjD,MAAM,aAAa,OAAO,QAAQ,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,MAAM,KAAK;AACtE,QAAI,oBAAuB,QAAQ,KACjC,KAAI,OAAO;AAEb,WAAO;GACR,GAAE,CAAE,EAAQ;AAGb,UAAO,MAAM,OAAO,YAAY,MAAM,KAAK,GAAG,CAAC,OAAO,WAAW;EAClE;AAGD,SAAO;CACR;CAyCD,MAAM,WACJC,OACAH,aACAI,OAC6C;AAC7C,QAAM,eAAe,KAAK,UACxB,OAAM,IAAI,OACP,WACC,YACD;EAIL,MAAMC,UAAiB,CAAE;AACzB,OAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;GAC9B,MAAM,kBACG,UAAU,aAAa,MAAM,AAAC,MAAc,GAAGH,oBAAM,GAAG;AAEjE,WAAQ,KACN,KAAK,SAAS,aAAa,UAAU,MAAM,KAAK,IAAIA,oBAAM,CAAC,KACzD,CAACI,WAAgB;AAEf,QAAI,iBAAiB,OAAO,WAAW,YAAY;KAEjD,MAAM,aAAa,OAAO,QAAQ,OAAO,CAAC,OACxC,CAAC,KAAK,CAAC,KAAK,MAAM,KAAK;AACrB,UAAI,oBAAuB,QAAQ,KACjC,KAAI,OAAO;AAEb,aAAO;KACR,GACD,CAAE,EACH;AAGD,YAAO,OAAO,YAAY,MAAM,KAAK,GAAG,CAAC,OAAO,WAAW;IAC5D;AAED,WAAO;GACR,EACF,CACF;EACF;AAED,SAAO,QAAQ,IAAI,QAAQ;CAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCD,KACEC,UACAC,OACsB;AACtB,QAAM,YAAY,KAAK,OACrB,OAAM,IAAI,OACP,QACC,SACD;AAIL,SAAO,KAAK,MAAM,UAAU;GAC1B,OAAO,SAAS,CAAE;GAClB,SAAS;GACT,IAAI,KAAK;EACV,EAAC;CACH;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FakerFactory } from "./faker-DHh7xs4u.mjs";
|
|
2
|
-
import { Factory, FactorySeed } from "./Factory-
|
|
2
|
+
import { ExtractSeedAttrs, Factory, FactorySeed } from "./Factory-BcGJjLc8.mjs";
|
|
3
3
|
import { Knex } from "knex";
|
|
4
4
|
import { Model } from "objection";
|
|
5
5
|
|
|
@@ -50,8 +50,21 @@ declare class ObjectionFactory<Builders extends Record<string, any>, Seeds exten
|
|
|
50
50
|
* Inherits from the base Factory class implementation.
|
|
51
51
|
*
|
|
52
52
|
* @template Seed - The seed function type
|
|
53
|
-
* @param seedFn - The seed function to wrap
|
|
53
|
+
* @param seedFn - The seed function to wrap (receives { attrs, factory, db } object)
|
|
54
54
|
* @returns The same seed function with proper typing
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const seeds = {
|
|
59
|
+
* userWithPosts: ObjectionFactory.createSeed(
|
|
60
|
+
* async ({ attrs, factory }) => {
|
|
61
|
+
* const user = await factory.insert('user', attrs);
|
|
62
|
+
* await factory.insertMany(3, 'post', { userId: user.id });
|
|
63
|
+
* return user;
|
|
64
|
+
* },
|
|
65
|
+
* ),
|
|
66
|
+
* };
|
|
67
|
+
* ```
|
|
55
68
|
*/
|
|
56
69
|
static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed;
|
|
57
70
|
/**
|
|
@@ -220,8 +233,8 @@ declare class ObjectionFactory<Builders extends Record<string, any>, Seeds exten
|
|
|
220
233
|
* .withGraphFetched('[departments.employees]');
|
|
221
234
|
* ```
|
|
222
235
|
*/
|
|
223
|
-
seed<K extends keyof Seeds>(seedName: K, attrs?:
|
|
236
|
+
seed<K extends keyof Seeds>(seedName: K, attrs?: ExtractSeedAttrs<Seeds[K]>): ReturnType<Seeds[K]>;
|
|
224
237
|
}
|
|
225
238
|
//#endregion
|
|
226
239
|
export { ObjectionFactory };
|
|
227
|
-
//# sourceMappingURL=ObjectionFactory-
|
|
240
|
+
//# sourceMappingURL=ObjectionFactory-DL4qkuF1.d.mts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Factory } from "./Factory-
|
|
1
|
+
import { Factory } from "./Factory-BFVnMMCC.mjs";
|
|
2
2
|
import { faker } from "./faker-BGKYFoCT.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/ObjectionFactory.ts
|
|
@@ -44,8 +44,21 @@ var ObjectionFactory = class extends Factory {
|
|
|
44
44
|
* Inherits from the base Factory class implementation.
|
|
45
45
|
*
|
|
46
46
|
* @template Seed - The seed function type
|
|
47
|
-
* @param seedFn - The seed function to wrap
|
|
47
|
+
* @param seedFn - The seed function to wrap (receives { attrs, factory, db } object)
|
|
48
48
|
* @returns The same seed function with proper typing
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const seeds = {
|
|
53
|
+
* userWithPosts: ObjectionFactory.createSeed(
|
|
54
|
+
* async ({ attrs, factory }) => {
|
|
55
|
+
* const user = await factory.insert('user', attrs);
|
|
56
|
+
* await factory.insertMany(3, 'post', { userId: user.id });
|
|
57
|
+
* return user;
|
|
58
|
+
* },
|
|
59
|
+
* ),
|
|
60
|
+
* };
|
|
61
|
+
* ```
|
|
49
62
|
*/
|
|
50
63
|
static createSeed(seedFn) {
|
|
51
64
|
return Factory.createSeed(seedFn);
|
|
@@ -241,10 +254,14 @@ var ObjectionFactory = class extends Factory {
|
|
|
241
254
|
*/
|
|
242
255
|
seed(seedName, attrs) {
|
|
243
256
|
if (!(seedName in this.seeds)) throw new Error(`Seed "${seedName}" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`);
|
|
244
|
-
return this.seeds[seedName](
|
|
257
|
+
return this.seeds[seedName]({
|
|
258
|
+
attrs: attrs || {},
|
|
259
|
+
factory: this,
|
|
260
|
+
db: this.db
|
|
261
|
+
});
|
|
245
262
|
}
|
|
246
263
|
};
|
|
247
264
|
|
|
248
265
|
//#endregion
|
|
249
266
|
export { ObjectionFactory };
|
|
250
|
-
//# sourceMappingURL=ObjectionFactory-
|
|
267
|
+
//# sourceMappingURL=ObjectionFactory-QCJ7u0Ql.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObjectionFactory-QCJ7u0Ql.mjs","names":["seedFn: Seed","ModelClass: TModel","defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Knex;\n faker: FakerFactory;\n }) =>\n | Partial<InstanceType<TModel>>\n | Promise<Partial<InstanceType<TModel>>>","autoInsert?: boolean","attrs: Attrs","factory: Factory","db: Knex","fakerInstance: FakerFactory","data: Partial<InstanceType<TModel>>","builders: Builders","seeds: Seeds","builderName: K","attrs?: Parameters<Builders[K]>[0]","count: number","attrs?: any","records: any[]","record: any","seedName: K","attrs?: ExtractSeedAttrs<Seeds[K]>"],"sources":["../src/ObjectionFactory.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport type { Model } from 'objection';\nimport { type ExtractSeedAttrs, Factory, type FactorySeed } from './Factory.ts';\nimport { type FakerFactory, faker } from './faker.ts';\n\n/**\n * Factory implementation for Objection.js ORM, providing test data creation utilities.\n * Extends the base Factory class with Objection.js-specific database operations.\n *\n * @template Builders - Record of builder functions for creating entities\n * @template Seeds - Record of seed functions for complex test scenarios\n *\n * @example\n * ```typescript\n * // Define your models with Objection.js\n * class User extends Model {\n * static tableName = 'users';\n * }\n *\n * // Create builders\n * const builders = {\n * user: ObjectionFactory.createBuilder(User, ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * ...attrs\n * })),\n * post: ObjectionFactory.createBuilder(Post, ({ attrs }) => ({\n * title: 'Test Post',\n * content: 'Test content',\n * ...attrs\n * })),\n * };\n *\n * // Create factory instance\n * const factory = new ObjectionFactory(builders, seeds, knex);\n *\n * // Use in tests\n * const user = await factory.insert('user', { name: 'John Doe' });\n * ```\n */\nexport class ObjectionFactory<\n Builders extends Record<string, any>,\n Seeds extends Record<string, any>,\n> extends Factory<Builders, Seeds> {\n /**\n * Creates a typed seed function with proper type inference.\n * Inherits from the base Factory class implementation.\n *\n * @template Seed - The seed function type\n * @param seedFn - The seed function to wrap (receives { attrs, factory, db } object)\n * @returns The same seed function with proper typing\n *\n * @example\n * ```typescript\n * const seeds = {\n * userWithPosts: ObjectionFactory.createSeed(\n * async ({ attrs, factory }) => {\n * const user = await factory.insert('user', attrs);\n * await factory.insertMany(3, 'post', { userId: user.id });\n * return user;\n * },\n * ),\n * };\n * ```\n */\n static createSeed<Seed extends FactorySeed>(seedFn: Seed): Seed {\n return Factory.createSeed(seedFn);\n }\n\n /**\n * Creates a typed builder function for Objection.js models.\n * This is a utility method that helps create builders with proper type inference.\n *\n * @template TModel - The Objection.js Model class type\n * @template Attrs - The attributes type for the builder (defaults to Partial of model)\n * @template Factory - The factory instance type\n * @template Result - The result type (defaults to the model instance)\n *\n * @param ModelClass - The Objection.js Model class\n * @param defaults - Optional function to provide default values (receives destructured context)\n * @param autoInsert - Whether to automatically insert the record (default: true)\n * @returns A builder function that creates and optionally inserts records\n *\n * @example\n * ```typescript\n * // Create a simple builder with defaults - destructure only what you need\n * const userBuilder = ObjectionFactory.createBuilder(User,\n * ({ attrs, faker }) => ({\n * id: faker.string.uuid(),\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * createdAt: new Date(),\n * ...attrs\n * })\n * );\n *\n * // Only need faker? Just destructure that\n * const leaveTypeBuilder = ObjectionFactory.createBuilder(LeaveType,\n * ({ faker }) => ({\n * name: faker.helpers.arrayElement(['Annual', 'Sick', 'Maternity']),\n * code: faker.string.alpha({ length: 3, casing: 'upper' }),\n * })\n * );\n *\n * // Create a builder that doesn't auto-insert (useful for nested inserts)\n * const addressBuilder = ObjectionFactory.createBuilder(Address,\n * ({ attrs }) => ({\n * street: '123 Main St',\n * city: 'Anytown',\n * ...attrs\n * }),\n * false // Don't auto-insert\n * );\n *\n * // Use with relations\n * const postBuilder = ObjectionFactory.createBuilder(Post,\n * async ({ attrs, factory, faker }) => ({\n * title: faker.lorem.sentence(),\n * content: faker.lorem.paragraphs(),\n * authorId: attrs.authorId || (await factory.insert('user')).id,\n * ...attrs\n * })\n * );\n * ```\n */\n static createBuilder<\n TModel extends typeof Model,\n Attrs extends Partial<InstanceType<TModel>> = Partial<InstanceType<TModel>>,\n Factory = any,\n Result = InstanceType<TModel>,\n >(\n ModelClass: TModel,\n defaults?: (context: {\n attrs: Attrs;\n factory: Factory;\n db: Knex;\n faker: FakerFactory;\n }) =>\n | Partial<InstanceType<TModel>>\n | Promise<Partial<InstanceType<TModel>>>,\n autoInsert?: boolean,\n ): (\n attrs: Attrs,\n factory: Factory,\n db: Knex,\n faker: FakerFactory,\n ) => Promise<Result> {\n return async (\n attrs: Attrs,\n factory: Factory,\n db: Knex,\n fakerInstance: FakerFactory,\n ) => {\n // Start with attributes\n let data: Partial<InstanceType<TModel>> = { ...attrs };\n\n // Apply defaults\n if (defaults) {\n const defaultValues = await defaults({\n attrs,\n factory,\n db,\n faker: fakerInstance,\n });\n data = { ...defaultValues, ...data };\n }\n\n // Create model instance\n const model = ModelClass.fromJson(data) as InstanceType<TModel>;\n\n // Handle insertion based on autoInsert flag\n if (autoInsert !== false) {\n // Auto insert is enabled by default\n // Extract only defined values for insertion\n const insertData = Object.entries(model).reduce((acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n }, {} as any);\n\n // Use static query method to insert data directly\n // @ts-ignore\n const result = await ModelClass.query(db).insert(insertData);\n return result as Result;\n } else {\n // Return model for factory to handle insertion\n return model as Result;\n }\n };\n }\n\n /**\n * Creates a new ObjectionFactory instance.\n *\n * @param builders - Record of builder functions for creating individual entities\n * @param seeds - Record of seed functions for creating complex test scenarios\n * @param db - Knex database connection instance\n */\n constructor(\n private builders: Builders,\n private seeds: Seeds,\n private db: Knex,\n ) {\n super();\n }\n\n /**\n * Inserts a single record into the database using the specified builder.\n * Uses Objection.js's insertGraph method to handle nested relations.\n *\n * @template K - The builder name (must be a key of Builders)\n * @param builderName - The name of the builder to use\n * @param attrs - Optional attributes to override builder defaults\n * @returns A promise resolving to the inserted record with all relations\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert with defaults\n * const user = await factory.insert('user');\n *\n * // Insert with overrides\n * const adminUser = await factory.insert('user', {\n * email: 'admin@example.com',\n * role: 'admin'\n * });\n *\n * // Insert with nested relations\n * const userWithProfile = await factory.insert('user', {\n * name: 'John Doe',\n * profile: {\n * bio: 'Software Developer',\n * avatar: 'avatar.jpg'\n * }\n * });\n * ```\n */\n async insert<K extends keyof Builders>(\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Factory \"${\n builderName as string\n }\" does not exist. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const result = await this.builders[builderName](\n attrs || {},\n this,\n this.db,\n faker,\n );\n\n // If the builder returns a model instance, insert it\n if (result && typeof result.$query === 'function') {\n // Extract data from model, excluding undefined values and id\n const insertData = Object.entries(result).reduce((acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n }, {} as any);\n\n // Use the model's constructor to get the query builder\n return await result.constructor.query(this.db).insert(insertData);\n }\n\n // Otherwise, assume the builder handled insertion itself\n return result;\n }\n /**\n * Inserts multiple records into the database using the specified builder.\n * Supports both static attributes and dynamic attribute generation via a function.\n *\n * @param count - The number of records to insert\n * @param builderName - The name of the builder to use\n * @param attrs - Static attributes or a function that generates attributes for each record\n * @returns A promise resolving to an array of inserted records\n * @throws Error if the specified builder doesn't exist\n *\n * @example\n * ```typescript\n * // Insert multiple with same attributes\n * const users = await factory.insertMany(5, 'user', { role: 'member' });\n *\n * // Insert multiple with dynamic attributes\n * const posts = await factory.insertMany(10, 'post', (idx) => ({\n * title: `Post ${idx + 1}`,\n * content: `Content for post ${idx + 1}`,\n * publishedAt: new Date()\n * }));\n *\n * // Create users with sequential emails\n * const admins = await factory.insertMany(3, 'user', (idx) => ({\n * email: `admin${idx + 1}@example.com`,\n * role: 'admin'\n * }));\n * ```\n */\n // Method overloads for better type inference\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs: (idx: number, faker: FakerFactory) => Parameters<Builders[K]>[0],\n ): Promise<Awaited<ReturnType<Builders[K]>>[]>;\n async insertMany<K extends keyof Builders>(\n count: number,\n builderName: K,\n attrs?: any,\n ): Promise<Awaited<ReturnType<Builders[K]>>[]> {\n if (!(builderName in this.builders)) {\n throw new Error(\n `Builder \"${\n builderName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n const records: any[] = [];\n for (let i = 0; i < count; i++) {\n const newAttrs =\n typeof attrs === 'function' ? await (attrs as any)(i, faker) : attrs;\n\n records.push(\n this.builders[builderName](newAttrs, this, this.db, faker).then(\n (record: any) => {\n // If the builder returns a model instance, insert it\n if (record && typeof record.$query === 'function') {\n // Extract data from model, excluding undefined values and id\n const insertData = Object.entries(record).reduce(\n (acc, [key, value]) => {\n if (value !== undefined && key !== 'id') {\n acc[key] = value;\n }\n return acc;\n },\n {} as any,\n );\n\n // Use the model's constructor to get the query builder\n return record.constructor.query(this.db).insert(insertData);\n }\n // Otherwise, assume the builder handled insertion itself\n return record;\n },\n ),\n );\n }\n\n return Promise.all(records);\n }\n /**\n * Executes a seed function to create complex test scenarios with multiple related records.\n * Seeds are useful for setting up complete test environments with realistic data relationships.\n *\n * @template K - The seed name (must be a key of Seeds)\n * @param seedName - The name of the seed to execute\n * @param attrs - Optional configuration attributes for the seed\n * @returns The result of the seed function (typically the primary record created)\n * @throws Error if the specified seed doesn't exist\n *\n * @example\n * ```typescript\n * // Execute a simple seed\n * const user = await factory.seed('userWithProfile');\n *\n * // Execute a seed with configuration\n * const author = await factory.seed('authorWithBooks', {\n * bookCount: 5,\n * includeReviews: true\n * });\n *\n * // Use seed result in tests with Objection.js relations\n * const company = await factory.seed('companyWithDepartments', {\n * departmentCount: 3,\n * employeesPerDepartment: 10\n * });\n *\n * // Access eager loaded relations\n * const companyWithRelations = await Company.query()\n * .findById(company.id)\n * .withGraphFetched('[departments.employees]');\n * ```\n */\n seed<K extends keyof Seeds>(\n seedName: K,\n attrs?: ExtractSeedAttrs<Seeds[K]>,\n ): ReturnType<Seeds[K]> {\n if (!(seedName in this.seeds)) {\n throw new Error(\n `Seed \"${\n seedName as string\n }\" is not registered in this factory. Make sure it is correct and registered in src/test/setup.ts`,\n );\n }\n\n return this.seeds[seedName]({\n attrs: attrs || {},\n factory: this,\n db: this.db,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,mBAAb,cAGU,QAAyB;;;;;;;;;;;;;;;;;;;;;;CAsBjC,OAAO,WAAqCA,QAAoB;AAC9D,SAAO,QAAQ,WAAW,OAAO;CAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DD,OAAO,cAMLC,YACAC,UAQAC,YAMmB;AACnB,SAAO,OACLC,OACAC,SACAC,IACAC,kBACG;GAEH,IAAIC,OAAsC,EAAE,GAAG,MAAO;AAGtD,OAAI,UAAU;IACZ,MAAM,gBAAgB,MAAM,SAAS;KACnC;KACA;KACA;KACA,OAAO;IACR,EAAC;AACF,WAAO;KAAE,GAAG;KAAe,GAAG;IAAM;GACrC;GAGD,MAAM,QAAQ,WAAW,SAAS,KAAK;AAGvC,OAAI,eAAe,OAAO;IAGxB,MAAM,aAAa,OAAO,QAAQ,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,MAAM,KAAK;AACrE,SAAI,oBAAuB,QAAQ,KACjC,KAAI,OAAO;AAEb,YAAO;IACR,GAAE,CAAE,EAAQ;IAIb,MAAM,SAAS,MAAM,WAAW,MAAM,GAAG,CAAC,OAAO,WAAW;AAC5D,WAAO;GACR,MAEC,QAAO;EAEV;CACF;;;;;;;;CASD,YACUC,UACAC,OACAJ,IACR;AACA,SAAO;EAJC;EACA;EACA;CAGT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiCD,MAAM,OACJK,aACAC,OAC2C;AAC3C,QAAM,eAAe,KAAK,UACxB,OAAM,IAAI,OACP,WACC,YACD;EAIL,MAAM,SAAS,MAAM,KAAK,SAAS,aACjC,SAAS,CAAE,GACX,MACA,KAAK,IACL,MACD;AAGD,MAAI,iBAAiB,OAAO,WAAW,YAAY;GAEjD,MAAM,aAAa,OAAO,QAAQ,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,MAAM,KAAK;AACtE,QAAI,oBAAuB,QAAQ,KACjC,KAAI,OAAO;AAEb,WAAO;GACR,GAAE,CAAE,EAAQ;AAGb,UAAO,MAAM,OAAO,YAAY,MAAM,KAAK,GAAG,CAAC,OAAO,WAAW;EAClE;AAGD,SAAO;CACR;CAyCD,MAAM,WACJC,OACAF,aACAG,OAC6C;AAC7C,QAAM,eAAe,KAAK,UACxB,OAAM,IAAI,OACP,WACC,YACD;EAIL,MAAMC,UAAiB,CAAE;AACzB,OAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;GAC9B,MAAM,kBACG,UAAU,aAAa,MAAM,AAAC,MAAc,GAAG,MAAM,GAAG;AAEjE,WAAQ,KACN,KAAK,SAAS,aAAa,UAAU,MAAM,KAAK,IAAI,MAAM,CAAC,KACzD,CAACC,WAAgB;AAEf,QAAI,iBAAiB,OAAO,WAAW,YAAY;KAEjD,MAAM,aAAa,OAAO,QAAQ,OAAO,CAAC,OACxC,CAAC,KAAK,CAAC,KAAK,MAAM,KAAK;AACrB,UAAI,oBAAuB,QAAQ,KACjC,KAAI,OAAO;AAEb,aAAO;KACR,GACD,CAAE,EACH;AAGD,YAAO,OAAO,YAAY,MAAM,KAAK,GAAG,CAAC,OAAO,WAAW;IAC5D;AAED,WAAO;GACR,EACF,CACF;EACF;AAED,SAAO,QAAQ,IAAI,QAAQ;CAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCD,KACEC,UACAC,OACsB;AACtB,QAAM,YAAY,KAAK,OACrB,OAAM,IAAI,OACP,QACC,SACD;AAIL,SAAO,KAAK,MAAM,UAAU;GAC1B,OAAO,SAAS,CAAE;GAClB,SAAS;GACT,IAAI,KAAK;EACV,EAAC;CACH;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
require('./Factory-
|
|
1
|
+
require('./Factory-BhjUOBWN.cjs');
|
|
2
2
|
require('./faker-B14IEMIN.cjs');
|
|
3
|
-
const require_ObjectionFactory = require('./ObjectionFactory-
|
|
3
|
+
const require_ObjectionFactory = require('./ObjectionFactory-BeFBYcan.cjs');
|
|
4
4
|
|
|
5
5
|
exports.ObjectionFactory = require_ObjectionFactory.ObjectionFactory;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./faker-
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { ObjectionFactory } from "./ObjectionFactory-
|
|
1
|
+
import "./faker-CbYiF-8_.cjs";
|
|
2
|
+
import "./Factory-IdfEkOeT.cjs";
|
|
3
|
+
import { ObjectionFactory } from "./ObjectionFactory-BRAkAByP.cjs";
|
|
4
4
|
export { ObjectionFactory };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import "./faker-DHh7xs4u.mjs";
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { ObjectionFactory } from "./ObjectionFactory-
|
|
2
|
+
import "./Factory-BcGJjLc8.mjs";
|
|
3
|
+
import { ObjectionFactory } from "./ObjectionFactory-DL4qkuF1.mjs";
|
|
4
4
|
export { ObjectionFactory };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./Factory-
|
|
1
|
+
import "./Factory-BFVnMMCC.mjs";
|
|
2
2
|
import "./faker-BGKYFoCT.mjs";
|
|
3
|
-
import { ObjectionFactory } from "./ObjectionFactory-
|
|
3
|
+
import { ObjectionFactory } from "./ObjectionFactory-QCJ7u0Ql.mjs";
|
|
4
4
|
|
|
5
5
|
export { ObjectionFactory };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/benchmark.ts
|
|
3
|
+
/**
|
|
4
|
+
* Generates an array of test records for benchmark data sets.
|
|
5
|
+
*
|
|
6
|
+
* @param count - Number of records to generate
|
|
7
|
+
* @returns Array of test data objects
|
|
8
|
+
*/
|
|
9
|
+
function generateTestData(count) {
|
|
10
|
+
return Array.from({ length: count }, (_, i) => ({
|
|
11
|
+
id: `id-${i}`,
|
|
12
|
+
name: `Item ${i}`,
|
|
13
|
+
value: Math.random() * 1e3
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generates unique keys for cache benchmarks to avoid collisions.
|
|
18
|
+
*
|
|
19
|
+
* @param prefix - Key prefix
|
|
20
|
+
* @param count - Number of keys to generate
|
|
21
|
+
* @returns Array of unique cache keys
|
|
22
|
+
*/
|
|
23
|
+
function generateCacheKeys(prefix, count) {
|
|
24
|
+
return Array.from({ length: count }, (_, i) => `${prefix}:${i}`);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Generates IP addresses for rate limit benchmarks.
|
|
28
|
+
*
|
|
29
|
+
* @param count - Number of IPs to generate
|
|
30
|
+
* @param subnet - Subnet prefix (default: '192.168.1')
|
|
31
|
+
* @returns Array of IP addresses
|
|
32
|
+
*/
|
|
33
|
+
function generateIpAddresses(count, subnet = "192.168.1") {
|
|
34
|
+
return Array.from({ length: count }, (_, i) => `${subnet}.${i % 256}`);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates a random IP address for rate limit benchmarks.
|
|
38
|
+
*/
|
|
39
|
+
function randomIpAddress() {
|
|
40
|
+
const octet = () => Math.floor(Math.random() * 256);
|
|
41
|
+
return `${octet()}.${octet()}.${octet()}.${octet()}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
exports.generateCacheKeys = generateCacheKeys;
|
|
46
|
+
exports.generateIpAddresses = generateIpAddresses;
|
|
47
|
+
exports.generateTestData = generateTestData;
|
|
48
|
+
exports.randomIpAddress = randomIpAddress;
|
|
49
|
+
//# sourceMappingURL=benchmark.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"benchmark.cjs","names":["count: number","prefix: string","subnet: string"],"sources":["../src/benchmark.ts"],"sourcesContent":["/**\n * Generates an array of test records for benchmark data sets.\n *\n * @param count - Number of records to generate\n * @returns Array of test data objects\n */\nexport function generateTestData(\n count: number,\n): Array<{ id: string; name: string; value: number }> {\n return Array.from({ length: count }, (_, i) => ({\n id: `id-${i}`,\n name: `Item ${i}`,\n value: Math.random() * 1000,\n }));\n}\n\n/**\n * Generates unique keys for cache benchmarks to avoid collisions.\n *\n * @param prefix - Key prefix\n * @param count - Number of keys to generate\n * @returns Array of unique cache keys\n */\nexport function generateCacheKeys(prefix: string, count: number): string[] {\n return Array.from({ length: count }, (_, i) => `${prefix}:${i}`);\n}\n\n/**\n * Generates IP addresses for rate limit benchmarks.\n *\n * @param count - Number of IPs to generate\n * @param subnet - Subnet prefix (default: '192.168.1')\n * @returns Array of IP addresses\n */\nexport function generateIpAddresses(\n count: number,\n subnet: string = '192.168.1',\n): string[] {\n return Array.from({ length: count }, (_, i) => `${subnet}.${i % 256}`);\n}\n\n/**\n * Creates a random IP address for rate limit benchmarks.\n */\nexport function randomIpAddress(): string {\n const octet = () => Math.floor(Math.random() * 256);\n return `${octet()}.${octet()}.${octet()}.${octet()}`;\n}\n"],"mappings":";;;;;;;;AAMA,SAAgB,iBACdA,OACoD;AACpD,QAAO,MAAM,KAAK,EAAE,QAAQ,MAAO,GAAE,CAAC,GAAG,OAAO;EAC9C,KAAK,KAAK,EAAE;EACZ,OAAO,OAAO,EAAE;EAChB,OAAO,KAAK,QAAQ,GAAG;CACxB,GAAE;AACJ;;;;;;;;AASD,SAAgB,kBAAkBC,QAAgBD,OAAyB;AACzE,QAAO,MAAM,KAAK,EAAE,QAAQ,MAAO,GAAE,CAAC,GAAG,OAAO,EAAE,OAAO,GAAG,EAAE,EAAE;AACjE;;;;;;;;AASD,SAAgB,oBACdA,OACAE,SAAiB,aACP;AACV,QAAO,MAAM,KAAK,EAAE,QAAQ,MAAO,GAAE,CAAC,GAAG,OAAO,EAAE,OAAO,GAAG,IAAI,IAAI,EAAE;AACvE;;;;AAKD,SAAgB,kBAA0B;CACxC,MAAM,QAAQ,MAAM,KAAK,MAAM,KAAK,QAAQ,GAAG,IAAI;AACnD,SAAQ,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC;AACpD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/benchmark.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Generates an array of test records for benchmark data sets.
|
|
4
|
+
*
|
|
5
|
+
* @param count - Number of records to generate
|
|
6
|
+
* @returns Array of test data objects
|
|
7
|
+
*/
|
|
8
|
+
declare function generateTestData(count: number): Array<{
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
value: number;
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* Generates unique keys for cache benchmarks to avoid collisions.
|
|
15
|
+
*
|
|
16
|
+
* @param prefix - Key prefix
|
|
17
|
+
* @param count - Number of keys to generate
|
|
18
|
+
* @returns Array of unique cache keys
|
|
19
|
+
*/
|
|
20
|
+
declare function generateCacheKeys(prefix: string, count: number): string[];
|
|
21
|
+
/**
|
|
22
|
+
* Generates IP addresses for rate limit benchmarks.
|
|
23
|
+
*
|
|
24
|
+
* @param count - Number of IPs to generate
|
|
25
|
+
* @param subnet - Subnet prefix (default: '192.168.1')
|
|
26
|
+
* @returns Array of IP addresses
|
|
27
|
+
*/
|
|
28
|
+
declare function generateIpAddresses(count: number, subnet?: string): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Creates a random IP address for rate limit benchmarks.
|
|
31
|
+
*/
|
|
32
|
+
declare function randomIpAddress(): string;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { generateCacheKeys, generateIpAddresses, generateTestData, randomIpAddress };
|
|
35
|
+
//# sourceMappingURL=benchmark.d.cts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/benchmark.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Generates an array of test records for benchmark data sets.
|
|
4
|
+
*
|
|
5
|
+
* @param count - Number of records to generate
|
|
6
|
+
* @returns Array of test data objects
|
|
7
|
+
*/
|
|
8
|
+
declare function generateTestData(count: number): Array<{
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
value: number;
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* Generates unique keys for cache benchmarks to avoid collisions.
|
|
15
|
+
*
|
|
16
|
+
* @param prefix - Key prefix
|
|
17
|
+
* @param count - Number of keys to generate
|
|
18
|
+
* @returns Array of unique cache keys
|
|
19
|
+
*/
|
|
20
|
+
declare function generateCacheKeys(prefix: string, count: number): string[];
|
|
21
|
+
/**
|
|
22
|
+
* Generates IP addresses for rate limit benchmarks.
|
|
23
|
+
*
|
|
24
|
+
* @param count - Number of IPs to generate
|
|
25
|
+
* @param subnet - Subnet prefix (default: '192.168.1')
|
|
26
|
+
* @returns Array of IP addresses
|
|
27
|
+
*/
|
|
28
|
+
declare function generateIpAddresses(count: number, subnet?: string): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Creates a random IP address for rate limit benchmarks.
|
|
31
|
+
*/
|
|
32
|
+
declare function randomIpAddress(): string;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { generateCacheKeys, generateIpAddresses, generateTestData, randomIpAddress };
|
|
35
|
+
//# sourceMappingURL=benchmark.d.mts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/benchmark.ts
|
|
2
|
+
/**
|
|
3
|
+
* Generates an array of test records for benchmark data sets.
|
|
4
|
+
*
|
|
5
|
+
* @param count - Number of records to generate
|
|
6
|
+
* @returns Array of test data objects
|
|
7
|
+
*/
|
|
8
|
+
function generateTestData(count) {
|
|
9
|
+
return Array.from({ length: count }, (_, i) => ({
|
|
10
|
+
id: `id-${i}`,
|
|
11
|
+
name: `Item ${i}`,
|
|
12
|
+
value: Math.random() * 1e3
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Generates unique keys for cache benchmarks to avoid collisions.
|
|
17
|
+
*
|
|
18
|
+
* @param prefix - Key prefix
|
|
19
|
+
* @param count - Number of keys to generate
|
|
20
|
+
* @returns Array of unique cache keys
|
|
21
|
+
*/
|
|
22
|
+
function generateCacheKeys(prefix, count) {
|
|
23
|
+
return Array.from({ length: count }, (_, i) => `${prefix}:${i}`);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Generates IP addresses for rate limit benchmarks.
|
|
27
|
+
*
|
|
28
|
+
* @param count - Number of IPs to generate
|
|
29
|
+
* @param subnet - Subnet prefix (default: '192.168.1')
|
|
30
|
+
* @returns Array of IP addresses
|
|
31
|
+
*/
|
|
32
|
+
function generateIpAddresses(count, subnet = "192.168.1") {
|
|
33
|
+
return Array.from({ length: count }, (_, i) => `${subnet}.${i % 256}`);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a random IP address for rate limit benchmarks.
|
|
37
|
+
*/
|
|
38
|
+
function randomIpAddress() {
|
|
39
|
+
const octet = () => Math.floor(Math.random() * 256);
|
|
40
|
+
return `${octet()}.${octet()}.${octet()}.${octet()}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { generateCacheKeys, generateIpAddresses, generateTestData, randomIpAddress };
|
|
45
|
+
//# sourceMappingURL=benchmark.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"benchmark.mjs","names":["count: number","prefix: string","subnet: string"],"sources":["../src/benchmark.ts"],"sourcesContent":["/**\n * Generates an array of test records for benchmark data sets.\n *\n * @param count - Number of records to generate\n * @returns Array of test data objects\n */\nexport function generateTestData(\n count: number,\n): Array<{ id: string; name: string; value: number }> {\n return Array.from({ length: count }, (_, i) => ({\n id: `id-${i}`,\n name: `Item ${i}`,\n value: Math.random() * 1000,\n }));\n}\n\n/**\n * Generates unique keys for cache benchmarks to avoid collisions.\n *\n * @param prefix - Key prefix\n * @param count - Number of keys to generate\n * @returns Array of unique cache keys\n */\nexport function generateCacheKeys(prefix: string, count: number): string[] {\n return Array.from({ length: count }, (_, i) => `${prefix}:${i}`);\n}\n\n/**\n * Generates IP addresses for rate limit benchmarks.\n *\n * @param count - Number of IPs to generate\n * @param subnet - Subnet prefix (default: '192.168.1')\n * @returns Array of IP addresses\n */\nexport function generateIpAddresses(\n count: number,\n subnet: string = '192.168.1',\n): string[] {\n return Array.from({ length: count }, (_, i) => `${subnet}.${i % 256}`);\n}\n\n/**\n * Creates a random IP address for rate limit benchmarks.\n */\nexport function randomIpAddress(): string {\n const octet = () => Math.floor(Math.random() * 256);\n return `${octet()}.${octet()}.${octet()}.${octet()}`;\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,iBACdA,OACoD;AACpD,QAAO,MAAM,KAAK,EAAE,QAAQ,MAAO,GAAE,CAAC,GAAG,OAAO;EAC9C,KAAK,KAAK,EAAE;EACZ,OAAO,OAAO,EAAE;EAChB,OAAO,KAAK,QAAQ,GAAG;CACxB,GAAE;AACJ;;;;;;;;AASD,SAAgB,kBAAkBC,QAAgBD,OAAyB;AACzE,QAAO,MAAM,KAAK,EAAE,QAAQ,MAAO,GAAE,CAAC,GAAG,OAAO,EAAE,OAAO,GAAG,EAAE,EAAE;AACjE;;;;;;;;AASD,SAAgB,oBACdA,OACAE,SAAiB,aACP;AACV,QAAO,MAAM,KAAK,EAAE,QAAQ,MAAO,GAAE,CAAC,GAAG,OAAO,EAAE,OAAO,GAAG,IAAI,IAAI,EAAE;AACvE;;;;AAKD,SAAgB,kBAA0B;CACxC,MAAM,QAAQ,MAAM,KAAK,MAAM,KAAK,QAAQ,GAAG,IAAI;AACnD,SAAQ,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC;AACpD"}
|
package/dist/better-auth.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as better_auth_adapters0 from "better-auth/adapters";
|
|
2
2
|
import { DBAdapterDebugLogOption } from "better-auth/adapters";
|
|
3
3
|
|
|
4
4
|
//#region src/better-auth.d.ts
|
|
@@ -7,7 +7,7 @@ interface MemoryAdapterConfig {
|
|
|
7
7
|
usePlural?: boolean;
|
|
8
8
|
initialData?: Record<string, any[]>;
|
|
9
9
|
}
|
|
10
|
-
declare const memoryAdapter: (config?: MemoryAdapterConfig, store?: Map<any, any>) =>
|
|
10
|
+
declare const memoryAdapter: (config?: MemoryAdapterConfig, store?: Map<any, any>) => better_auth_adapters0.AdapterFactory & {
|
|
11
11
|
clear: () => void;
|
|
12
12
|
getAllData: () => Record<string, any[]>;
|
|
13
13
|
getStore: () => Map<any, any>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as vitest4 from "vitest";
|
|
2
2
|
|
|
3
3
|
//#region src/os/directory.d.ts
|
|
4
|
-
declare const itWithDir:
|
|
4
|
+
declare const itWithDir: vitest4.TestAPI<{
|
|
5
5
|
dir: string;
|
|
6
6
|
}>;
|
|
7
7
|
interface DirectoryFixtures {
|
|
@@ -9,4 +9,4 @@ interface DirectoryFixtures {
|
|
|
9
9
|
}
|
|
10
10
|
//#endregion
|
|
11
11
|
export { DirectoryFixtures, itWithDir };
|
|
12
|
-
//# sourceMappingURL=directory-
|
|
12
|
+
//# sourceMappingURL=directory-Mi7tdOuD.d.cts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _faker_js_faker3 from "@faker-js/faker";
|
|
2
2
|
|
|
3
3
|
//#region src/faker.d.ts
|
|
4
4
|
|
|
@@ -134,7 +134,7 @@ declare function coordinateOutsideRadius(center: Coordinate, minRadiusMeters: nu
|
|
|
134
134
|
* const productPrice = faker.price();
|
|
135
135
|
* ```
|
|
136
136
|
*/
|
|
137
|
-
declare const faker: Readonly<
|
|
137
|
+
declare const faker: Readonly<_faker_js_faker3.Faker & {
|
|
138
138
|
timestamps: typeof timestamps;
|
|
139
139
|
identifier: typeof identifier;
|
|
140
140
|
sequence: typeof sequence;
|
|
@@ -163,4 +163,4 @@ type Timestamps = {
|
|
|
163
163
|
type FakerFactory = typeof faker;
|
|
164
164
|
//#endregion
|
|
165
165
|
export { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
|
166
|
-
//# sourceMappingURL=faker-
|
|
166
|
+
//# sourceMappingURL=faker-CbYiF-8_.d.cts.map
|
package/dist/faker.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps } from "./faker-
|
|
1
|
+
import { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps } from "./faker-CbYiF-8_.cjs";
|
|
2
2
|
export { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
package/dist/kysely.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
require('./Factory-
|
|
1
|
+
require('./Factory-BhjUOBWN.cjs');
|
|
2
2
|
const require_faker = require('./faker-B14IEMIN.cjs');
|
|
3
|
-
const require_KyselyFactory = require('./KyselyFactory-
|
|
3
|
+
const require_KyselyFactory = require('./KyselyFactory-BFqVIn_0.cjs');
|
|
4
4
|
require('./PostgresMigrator-DFcNdCvD.cjs');
|
|
5
5
|
const require_PostgresKyselyMigrator = require('./PostgresKyselyMigrator-CfytARcA.cjs');
|
|
6
6
|
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-CMfJXZP8.cjs');
|
package/dist/kysely.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kysely.cjs","names":["api: TestAPI","options: KyselyTransactionOptions<Database, Extended>","VitestKyselyTransactionIsolator","extendWithFixtures","wrappedTest: T","fixtures: FixtureCreators<Transaction<Database>, Extended>"],"sources":["../src/kysely.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport type { TestAPI } from 'vitest';\nimport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nimport {\n type DatabaseConnection,\n type FixtureCreators,\n type IsolationLevel,\n extendWithFixtures as baseExtendWithFixtures,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific exports for test utilities.\n * Provides factories, migrators, and transaction isolators for Kysely ORM.\n */\n\nexport { KyselyFactory } from './KyselyFactory';\nexport { PostgresKyselyMigrator } from './PostgresKyselyMigrator';\nexport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\nexport type {\n DatabaseFixtures,\n ExtendedDatabaseFixtures,\n FixtureCreators,\n TestWithExtendedFixtures,\n TransactionWrapperOptions,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific options for transaction wrapping.\n */\nexport interface KyselyTransactionOptions<\n Database,\n Extended extends Record<string, unknown> = {},\n> {\n /** Function that creates or returns a Kysely database instance */\n connection: DatabaseConnection<Kysely<Database>>;\n /** Optional setup function to run within the transaction before each test */\n setup?: (trx: Transaction<Database>) => Promise<void>;\n /** Transaction isolation level (defaults to REPEATABLE_READ) */\n isolationLevel?: IsolationLevel;\n /** Additional fixtures that depend on the transaction */\n fixtures?: FixtureCreators<Transaction<Database>, Extended>;\n}\n\n// Re-export faker and FakerFactory for type portability in declaration files\nexport { faker, type FakerFactory } from './faker';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Database - The database schema type\n * @template Extended - Additional fixtures to provide\n * @param api - The Vitest test API (usually `test` from vitest)\n * @param options - Configuration options for transaction wrapping\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction } from '@geekmidas/testkit/kysely';\n * import { db } from './database';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestKyselyTransaction(test, {\n * connection: db,\n * });\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await trx\n * .insertInto('users')\n * .values({ name: 'Test User', email: 'test@example.com' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * });\n *\n * // With fixtures for factories\n * const it = wrapVitestKyselyTransaction<DB, { factory: Factory }>(test, {\n * connection: db,\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user.id).toBeDefined();\n * });\n * ```\n */\nexport function wrapVitestKyselyTransaction<\n Database,\n Extended extends Record<string, unknown> = {},\n>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>) {\n const wrapper = new VitestKyselyTransactionIsolator<Database>(api);\n\n return wrapper.wrapVitestWithTransaction(options);\n}\n\n/**\n * Extends a Kysely transaction-wrapped test with additional fixtures.\n * Each fixture receives the transaction and can create dependencies like factories or repositories.\n *\n * @template Database - The database schema type\n * @template Extended - The type of additional fixtures to provide\n * @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction\n * @param fixtures - Object mapping fixture names to creator functions\n * @returns An extended test API with both trx and the additional fixtures\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';\n *\n * // Define your builders\n * const builders = {\n * user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * })),\n * };\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestKyselyTransaction<DB>(test, {\n * connection: db,\n * setup: createTestTables,\n * });\n *\n * // Extend with fixtures - each fixture receives the transaction\n * const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(\n * baseTest,\n * {\n * factory: (trx) => new KyselyFactory(builders, {}, trx),\n * }\n * );\n *\n * // Use in tests - both trx and factory are available\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test User' });\n * expect(user.id).toBeDefined();\n *\n * // Verify in database\n * const found = await trx\n * .selectFrom('users')\n * .where('id', '=', user.id)\n * .selectAll()\n * .executeTakeFirst();\n * expect(found?.name).toBe('Test User');\n * });\n * ```\n */\nexport function extendWithFixtures<\n Database,\n Extended extends Record<string, unknown>,\n T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,\n>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>) {\n return baseExtendWithFixtures<Transaction<Database>, Extended, T>(\n wrappedTest,\n fixtures,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"kysely.cjs","names":["api: TestAPI","options: KyselyTransactionOptions<Database, Extended>","VitestKyselyTransactionIsolator","extendWithFixtures","wrappedTest: T","fixtures: FixtureCreators<Transaction<Database>, Extended>"],"sources":["../src/kysely.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport type { TestAPI } from 'vitest';\nimport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nimport {\n type DatabaseConnection,\n type FixtureCreators,\n type IsolationLevel,\n extendWithFixtures as baseExtendWithFixtures,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific exports for test utilities.\n * Provides factories, migrators, and transaction isolators for Kysely ORM.\n */\n\nexport { KyselyFactory } from './KyselyFactory';\nexport type { ExtractSeedAttrs, FactorySeed } from './Factory';\nexport { PostgresKyselyMigrator } from './PostgresKyselyMigrator';\nexport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\nexport type {\n DatabaseFixtures,\n ExtendedDatabaseFixtures,\n FixtureCreators,\n TestWithExtendedFixtures,\n TransactionWrapperOptions,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific options for transaction wrapping.\n */\nexport interface KyselyTransactionOptions<\n Database,\n Extended extends Record<string, unknown> = {},\n> {\n /** Function that creates or returns a Kysely database instance */\n connection: DatabaseConnection<Kysely<Database>>;\n /** Optional setup function to run within the transaction before each test */\n setup?: (trx: Transaction<Database>) => Promise<void>;\n /** Transaction isolation level (defaults to REPEATABLE_READ) */\n isolationLevel?: IsolationLevel;\n /** Additional fixtures that depend on the transaction */\n fixtures?: FixtureCreators<Transaction<Database>, Extended>;\n}\n\n// Re-export faker and FakerFactory for type portability in declaration files\nexport { faker, type FakerFactory } from './faker';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Database - The database schema type\n * @template Extended - Additional fixtures to provide\n * @param api - The Vitest test API (usually `test` from vitest)\n * @param options - Configuration options for transaction wrapping\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction } from '@geekmidas/testkit/kysely';\n * import { db } from './database';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestKyselyTransaction(test, {\n * connection: db,\n * });\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await trx\n * .insertInto('users')\n * .values({ name: 'Test User', email: 'test@example.com' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * });\n *\n * // With fixtures for factories\n * const it = wrapVitestKyselyTransaction<DB, { factory: Factory }>(test, {\n * connection: db,\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user.id).toBeDefined();\n * });\n * ```\n */\nexport function wrapVitestKyselyTransaction<\n Database,\n Extended extends Record<string, unknown> = {},\n>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>) {\n const wrapper = new VitestKyselyTransactionIsolator<Database>(api);\n\n return wrapper.wrapVitestWithTransaction(options);\n}\n\n/**\n * Extends a Kysely transaction-wrapped test with additional fixtures.\n * Each fixture receives the transaction and can create dependencies like factories or repositories.\n *\n * @template Database - The database schema type\n * @template Extended - The type of additional fixtures to provide\n * @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction\n * @param fixtures - Object mapping fixture names to creator functions\n * @returns An extended test API with both trx and the additional fixtures\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';\n *\n * // Define your builders\n * const builders = {\n * user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * })),\n * };\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestKyselyTransaction<DB>(test, {\n * connection: db,\n * setup: createTestTables,\n * });\n *\n * // Extend with fixtures - each fixture receives the transaction\n * const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(\n * baseTest,\n * {\n * factory: (trx) => new KyselyFactory(builders, {}, trx),\n * }\n * );\n *\n * // Use in tests - both trx and factory are available\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test User' });\n * expect(user.id).toBeDefined();\n *\n * // Verify in database\n * const found = await trx\n * .selectFrom('users')\n * .where('id', '=', user.id)\n * .selectAll()\n * .executeTakeFirst();\n * expect(found?.name).toBe('Test User');\n * });\n * ```\n */\nexport function extendWithFixtures<\n Database,\n Extended extends Record<string, unknown>,\n T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,\n>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>) {\n return baseExtendWithFixtures<Transaction<Database>, Extended, T>(\n wrappedTest,\n fixtures,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,4BAGdA,KAAcC,SAAuD;CACrE,MAAM,UAAU,IAAIC,wEAA0C;AAE9D,QAAO,QAAQ,0BAA0B,QAAQ;AAClD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDD,SAAgBC,qBAIdC,aAAgBC,UAA4D;AAC5E,QAAO,qDACL,aACA,SACD;AACF"}
|
package/dist/kysely.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FakerFactory, faker } from "./faker-
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-
|
|
1
|
+
import { FakerFactory, faker } from "./faker-CbYiF-8_.cjs";
|
|
2
|
+
import { ExtractSeedAttrs, FactorySeed } from "./Factory-IdfEkOeT.cjs";
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-Dxhi_ZkA.cjs";
|
|
4
4
|
import "./PostgresMigrator-D5UkK1_K.cjs";
|
|
5
5
|
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CQ3aUoy_.cjs";
|
|
6
6
|
import { DatabaseConnection, DatabaseFixtures, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions } from "./VitestTransactionIsolator-CwQaxZLP.cjs";
|
|
@@ -125,5 +125,5 @@ declare function wrapVitestKyselyTransaction<Database, Extended extends Record<s
|
|
|
125
125
|
*/
|
|
126
126
|
declare function extendWithFixtures<Database, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>): TestWithExtendedFixtures<Transaction<Database>, Extended, T>;
|
|
127
127
|
//#endregion
|
|
128
|
-
export { DatabaseFixtures, ExtendedDatabaseFixtures, FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, KyselyTransactionOptions, PostgresKyselyMigrator, TestWithExtendedFixtures, TransactionWrapperOptions, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
|
|
128
|
+
export { DatabaseFixtures, ExtendedDatabaseFixtures, ExtractSeedAttrs, FactorySeed, FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, KyselyTransactionOptions, PostgresKyselyMigrator, TestWithExtendedFixtures, TransactionWrapperOptions, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
|
|
129
129
|
//# sourceMappingURL=kysely.d.cts.map
|
package/dist/kysely.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FakerFactory, faker } from "./faker-DHh7xs4u.mjs";
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-
|
|
2
|
+
import { ExtractSeedAttrs, FactorySeed } from "./Factory-BcGJjLc8.mjs";
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-Cj-EultY.mjs";
|
|
4
4
|
import "./PostgresMigrator-DQaRxoaY.mjs";
|
|
5
5
|
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CIx3AFSR.mjs";
|
|
6
6
|
import { DatabaseConnection, DatabaseFixtures, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions } from "./VitestTransactionIsolator-BvR19bYn.mjs";
|
|
@@ -125,5 +125,5 @@ declare function wrapVitestKyselyTransaction<Database, Extended extends Record<s
|
|
|
125
125
|
*/
|
|
126
126
|
declare function extendWithFixtures<Database, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>): TestWithExtendedFixtures<Transaction<Database>, Extended, T>;
|
|
127
127
|
//#endregion
|
|
128
|
-
export { DatabaseFixtures, ExtendedDatabaseFixtures, FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, KyselyTransactionOptions, PostgresKyselyMigrator, TestWithExtendedFixtures, TransactionWrapperOptions, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
|
|
128
|
+
export { DatabaseFixtures, ExtendedDatabaseFixtures, ExtractSeedAttrs, FactorySeed, FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, KyselyTransactionOptions, PostgresKyselyMigrator, TestWithExtendedFixtures, TransactionWrapperOptions, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
|
|
129
129
|
//# sourceMappingURL=kysely.d.mts.map
|
package/dist/kysely.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./Factory-
|
|
1
|
+
import "./Factory-BFVnMMCC.mjs";
|
|
2
2
|
import { faker } from "./faker-BGKYFoCT.mjs";
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-DMswpwji.mjs";
|
|
4
4
|
import "./PostgresMigrator-DbuJGAVy.mjs";
|
|
5
5
|
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-upT-hmrz.mjs";
|
|
6
6
|
import { IsolationLevel, extendWithFixtures } from "./VitestTransactionIsolator-DQ7tLqgV.mjs";
|
package/dist/kysely.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kysely.mjs","names":["api: TestAPI","options: KyselyTransactionOptions<Database, Extended>","extendWithFixtures","wrappedTest: T","fixtures: FixtureCreators<Transaction<Database>, Extended>"],"sources":["../src/kysely.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport type { TestAPI } from 'vitest';\nimport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nimport {\n type DatabaseConnection,\n type FixtureCreators,\n type IsolationLevel,\n extendWithFixtures as baseExtendWithFixtures,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific exports for test utilities.\n * Provides factories, migrators, and transaction isolators for Kysely ORM.\n */\n\nexport { KyselyFactory } from './KyselyFactory';\nexport { PostgresKyselyMigrator } from './PostgresKyselyMigrator';\nexport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\nexport type {\n DatabaseFixtures,\n ExtendedDatabaseFixtures,\n FixtureCreators,\n TestWithExtendedFixtures,\n TransactionWrapperOptions,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific options for transaction wrapping.\n */\nexport interface KyselyTransactionOptions<\n Database,\n Extended extends Record<string, unknown> = {},\n> {\n /** Function that creates or returns a Kysely database instance */\n connection: DatabaseConnection<Kysely<Database>>;\n /** Optional setup function to run within the transaction before each test */\n setup?: (trx: Transaction<Database>) => Promise<void>;\n /** Transaction isolation level (defaults to REPEATABLE_READ) */\n isolationLevel?: IsolationLevel;\n /** Additional fixtures that depend on the transaction */\n fixtures?: FixtureCreators<Transaction<Database>, Extended>;\n}\n\n// Re-export faker and FakerFactory for type portability in declaration files\nexport { faker, type FakerFactory } from './faker';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Database - The database schema type\n * @template Extended - Additional fixtures to provide\n * @param api - The Vitest test API (usually `test` from vitest)\n * @param options - Configuration options for transaction wrapping\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction } from '@geekmidas/testkit/kysely';\n * import { db } from './database';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestKyselyTransaction(test, {\n * connection: db,\n * });\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await trx\n * .insertInto('users')\n * .values({ name: 'Test User', email: 'test@example.com' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * });\n *\n * // With fixtures for factories\n * const it = wrapVitestKyselyTransaction<DB, { factory: Factory }>(test, {\n * connection: db,\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user.id).toBeDefined();\n * });\n * ```\n */\nexport function wrapVitestKyselyTransaction<\n Database,\n Extended extends Record<string, unknown> = {},\n>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>) {\n const wrapper = new VitestKyselyTransactionIsolator<Database>(api);\n\n return wrapper.wrapVitestWithTransaction(options);\n}\n\n/**\n * Extends a Kysely transaction-wrapped test with additional fixtures.\n * Each fixture receives the transaction and can create dependencies like factories or repositories.\n *\n * @template Database - The database schema type\n * @template Extended - The type of additional fixtures to provide\n * @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction\n * @param fixtures - Object mapping fixture names to creator functions\n * @returns An extended test API with both trx and the additional fixtures\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';\n *\n * // Define your builders\n * const builders = {\n * user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * })),\n * };\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestKyselyTransaction<DB>(test, {\n * connection: db,\n * setup: createTestTables,\n * });\n *\n * // Extend with fixtures - each fixture receives the transaction\n * const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(\n * baseTest,\n * {\n * factory: (trx) => new KyselyFactory(builders, {}, trx),\n * }\n * );\n *\n * // Use in tests - both trx and factory are available\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test User' });\n * expect(user.id).toBeDefined();\n *\n * // Verify in database\n * const found = await trx\n * .selectFrom('users')\n * .where('id', '=', user.id)\n * .selectAll()\n * .executeTakeFirst();\n * expect(found?.name).toBe('Test User');\n * });\n * ```\n */\nexport function extendWithFixtures<\n Database,\n Extended extends Record<string, unknown>,\n T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,\n>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>) {\n return baseExtendWithFixtures<Transaction<Database>, Extended, T>(\n wrappedTest,\n fixtures,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"kysely.mjs","names":["api: TestAPI","options: KyselyTransactionOptions<Database, Extended>","extendWithFixtures","wrappedTest: T","fixtures: FixtureCreators<Transaction<Database>, Extended>"],"sources":["../src/kysely.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport type { TestAPI } from 'vitest';\nimport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nimport {\n type DatabaseConnection,\n type FixtureCreators,\n type IsolationLevel,\n extendWithFixtures as baseExtendWithFixtures,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific exports for test utilities.\n * Provides factories, migrators, and transaction isolators for Kysely ORM.\n */\n\nexport { KyselyFactory } from './KyselyFactory';\nexport type { ExtractSeedAttrs, FactorySeed } from './Factory';\nexport { PostgresKyselyMigrator } from './PostgresKyselyMigrator';\nexport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\nexport type {\n DatabaseFixtures,\n ExtendedDatabaseFixtures,\n FixtureCreators,\n TestWithExtendedFixtures,\n TransactionWrapperOptions,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific options for transaction wrapping.\n */\nexport interface KyselyTransactionOptions<\n Database,\n Extended extends Record<string, unknown> = {},\n> {\n /** Function that creates or returns a Kysely database instance */\n connection: DatabaseConnection<Kysely<Database>>;\n /** Optional setup function to run within the transaction before each test */\n setup?: (trx: Transaction<Database>) => Promise<void>;\n /** Transaction isolation level (defaults to REPEATABLE_READ) */\n isolationLevel?: IsolationLevel;\n /** Additional fixtures that depend on the transaction */\n fixtures?: FixtureCreators<Transaction<Database>, Extended>;\n}\n\n// Re-export faker and FakerFactory for type portability in declaration files\nexport { faker, type FakerFactory } from './faker';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Database - The database schema type\n * @template Extended - Additional fixtures to provide\n * @param api - The Vitest test API (usually `test` from vitest)\n * @param options - Configuration options for transaction wrapping\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction } from '@geekmidas/testkit/kysely';\n * import { db } from './database';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestKyselyTransaction(test, {\n * connection: db,\n * });\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await trx\n * .insertInto('users')\n * .values({ name: 'Test User', email: 'test@example.com' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * });\n *\n * // With fixtures for factories\n * const it = wrapVitestKyselyTransaction<DB, { factory: Factory }>(test, {\n * connection: db,\n * fixtures: {\n * factory: (trx) => new Factory(trx),\n * },\n * });\n *\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test' });\n * expect(user.id).toBeDefined();\n * });\n * ```\n */\nexport function wrapVitestKyselyTransaction<\n Database,\n Extended extends Record<string, unknown> = {},\n>(api: TestAPI, options: KyselyTransactionOptions<Database, Extended>) {\n const wrapper = new VitestKyselyTransactionIsolator<Database>(api);\n\n return wrapper.wrapVitestWithTransaction(options);\n}\n\n/**\n * Extends a Kysely transaction-wrapped test with additional fixtures.\n * Each fixture receives the transaction and can create dependencies like factories or repositories.\n *\n * @template Database - The database schema type\n * @template Extended - The type of additional fixtures to provide\n * @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction\n * @param fixtures - Object mapping fixture names to creator functions\n * @returns An extended test API with both trx and the additional fixtures\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';\n *\n * // Define your builders\n * const builders = {\n * user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * })),\n * };\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestKyselyTransaction<DB>(test, {\n * connection: db,\n * setup: createTestTables,\n * });\n *\n * // Extend with fixtures - each fixture receives the transaction\n * const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(\n * baseTest,\n * {\n * factory: (trx) => new KyselyFactory(builders, {}, trx),\n * }\n * );\n *\n * // Use in tests - both trx and factory are available\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test User' });\n * expect(user.id).toBeDefined();\n *\n * // Verify in database\n * const found = await trx\n * .selectFrom('users')\n * .where('id', '=', user.id)\n * .selectAll()\n * .executeTakeFirst();\n * expect(found?.name).toBe('Test User');\n * });\n * ```\n */\nexport function extendWithFixtures<\n Database,\n Extended extends Record<string, unknown>,\n T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,\n>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>) {\n return baseExtendWithFixtures<Transaction<Database>, Extended, T>(\n wrappedTest,\n fixtures,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,4BAGdA,KAAcC,SAAuD;CACrE,MAAM,UAAU,IAAI,gCAA0C;AAE9D,QAAO,QAAQ,0BAA0B,QAAQ;AAClD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDD,SAAgBC,qBAIdC,aAAgBC,UAA4D;AAC5E,QAAO,mBACL,aACA,SACD;AACF"}
|
package/dist/objection.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
require('./Factory-
|
|
1
|
+
require('./Factory-BhjUOBWN.cjs');
|
|
2
2
|
const require_faker = require('./faker-B14IEMIN.cjs');
|
|
3
|
-
const require_ObjectionFactory = require('./ObjectionFactory-
|
|
3
|
+
const require_ObjectionFactory = require('./ObjectionFactory-BeFBYcan.cjs');
|
|
4
4
|
require('./PostgresMigrator-DFcNdCvD.cjs');
|
|
5
5
|
const require_PostgresObjectionMigrator = require('./PostgresObjectionMigrator-BG6ymgnt.cjs');
|
|
6
6
|
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-CMfJXZP8.cjs');
|