@geekmidas/testkit 0.1.1 → 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-DE3hE0WO.d.mts → Factory-BcGJjLc8.d.mts} +24 -10
- package/dist/{Factory-WMhTNZ9S.cjs → Factory-BhjUOBWN.cjs} +2 -2
- package/dist/Factory-BhjUOBWN.cjs.map +1 -0
- package/dist/{Factory-pNV7ZQ7-.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 +3 -3
- 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-CPZTUuMB.d.cts → KyselyFactory-Cj-EultY.d.mts} +18 -5
- package/dist/{KyselyFactory-CXY5gJk2.mjs → KyselyFactory-DMswpwji.mjs} +21 -4
- package/dist/KyselyFactory-DMswpwji.mjs.map +1 -0
- package/dist/{KyselyFactory-RAyvZ8Cj.d.mts → 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 +3 -3
- package/dist/KyselyFactory.mjs +2 -2
- package/dist/{ObjectionFactory-BlBicEia.d.mts → 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-BwpN4gMX.d.cts → ObjectionFactory-DL4qkuF1.d.mts} +18 -5
- 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 +3 -3
- package/dist/ObjectionFactory.mjs +2 -2
- package/dist/{VitestKyselyTransactionIsolator-XDL3ngs_.mjs → VitestKyselyTransactionIsolator-CNURW8y6.mjs} +2 -2
- package/dist/{VitestKyselyTransactionIsolator-XDL3ngs_.mjs.map → VitestKyselyTransactionIsolator-CNURW8y6.mjs.map} +1 -1
- package/dist/{VitestKyselyTransactionIsolator-DiskaURs.d.mts → VitestKyselyTransactionIsolator-D3EZZhjZ.d.cts} +2 -2
- package/dist/{VitestKyselyTransactionIsolator-BqrZDeaT.d.cts → VitestKyselyTransactionIsolator-Dxlp1u0f.d.mts} +2 -2
- package/dist/{VitestKyselyTransactionIsolator-DX_VPKS-.cjs → VitestKyselyTransactionIsolator-EvDLk5zg.cjs} +2 -2
- package/dist/{VitestKyselyTransactionIsolator-DX_VPKS-.cjs.map → VitestKyselyTransactionIsolator-EvDLk5zg.cjs.map} +1 -1
- package/dist/VitestKyselyTransactionIsolator.cjs +2 -2
- package/dist/VitestKyselyTransactionIsolator.d.cts +2 -2
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestKyselyTransactionIsolator.mjs +2 -2
- package/dist/{VitestObjectionTransactionIsolator-CD2ucJpH.d.cts → VitestObjectionTransactionIsolator-1TpsPqfG.d.cts} +2 -2
- package/dist/{VitestObjectionTransactionIsolator-D_tlOtq8.cjs → VitestObjectionTransactionIsolator-CM5KTAFA.cjs} +2 -2
- package/dist/{VitestObjectionTransactionIsolator-D_tlOtq8.cjs.map → VitestObjectionTransactionIsolator-CM5KTAFA.cjs.map} +1 -1
- package/dist/{VitestObjectionTransactionIsolator-DhQ8XGva.d.mts → VitestObjectionTransactionIsolator-i9jIgU8Q.d.mts} +2 -2
- package/dist/{VitestObjectionTransactionIsolator-_EhJKu_O.mjs → VitestObjectionTransactionIsolator-jQFaCz0u.mjs} +2 -2
- package/dist/{VitestObjectionTransactionIsolator-_EhJKu_O.mjs.map → VitestObjectionTransactionIsolator-jQFaCz0u.mjs.map} +1 -1
- package/dist/VitestObjectionTransactionIsolator.cjs +2 -2
- package/dist/VitestObjectionTransactionIsolator.d.cts +2 -2
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator.mjs +2 -2
- package/dist/{VitestTransactionIsolator-DLdQlfZ5.d.mts → VitestTransactionIsolator-BvR19bYn.d.mts} +31 -14
- package/dist/{VitestTransactionIsolator-BKIrj3Uy.cjs → VitestTransactionIsolator-CMfJXZP8.cjs} +52 -36
- package/dist/VitestTransactionIsolator-CMfJXZP8.cjs.map +1 -0
- package/dist/{VitestTransactionIsolator-DfA80g2M.d.cts → VitestTransactionIsolator-CwQaxZLP.d.cts} +31 -14
- package/dist/{VitestTransactionIsolator-BIaMs4c2.mjs → VitestTransactionIsolator-DQ7tLqgV.mjs} +52 -36
- package/dist/VitestTransactionIsolator-DQ7tLqgV.mjs.map +1 -0
- package/dist/VitestTransactionIsolator.cjs +1 -1
- package/dist/VitestTransactionIsolator.d.cts +2 -2
- package/dist/VitestTransactionIsolator.d.mts +2 -2
- package/dist/VitestTransactionIsolator.mjs +1 -1
- 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/better-auth.d.mts +2 -2
- package/dist/{directory-Q178x53k.d.mts → directory-BXavAeJZ.d.mts} +3 -3
- package/dist/{faker-BSH1EMtg.d.cts → faker-CbYiF-8_.d.cts} +3 -3
- package/dist/{faker-D9gz7KjY.d.mts → faker-DHh7xs4u.d.mts} +3 -3
- package/dist/faker.d.cts +1 -1
- package/dist/faker.d.mts +1 -1
- package/dist/kysely.cjs +25 -31
- package/dist/kysely.cjs.map +1 -1
- package/dist/kysely.d.cts +39 -34
- package/dist/kysely.d.mts +39 -34
- package/dist/kysely.mjs +25 -31
- package/dist/kysely.mjs.map +1 -1
- package/dist/objection.cjs +25 -49
- package/dist/objection.cjs.map +1 -1
- package/dist/objection.d.cts +39 -52
- package/dist/objection.d.mts +39 -52
- package/dist/objection.mjs +25 -49
- package/dist/objection.mjs.map +1 -1
- package/dist/os/directory.d.mts +1 -1
- package/dist/os/index.d.mts +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/VitestTransactionIsolator.ts +67 -16
- package/src/__tests__/Factory.spec.ts +16 -10
- package/src/__tests__/KyselyFactory.spec.ts +16 -11
- package/src/__tests__/ObjectionFactory.spec.ts +61 -53
- package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +6 -3
- package/src/__tests__/integration.spec.ts +24 -18
- package/src/benchmark.ts +48 -0
- package/src/kysely.ts +44 -33
- package/src/objection.ts +42 -51
- 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
- package/dist/VitestTransactionIsolator-BIaMs4c2.mjs.map +0 -1
- package/dist/VitestTransactionIsolator-BKIrj3Uy.cjs.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
|
-
import { FakerFactory } from "./faker-
|
|
2
|
-
import { Factory, FactorySeed } from "./Factory-
|
|
1
|
+
import { FakerFactory } from "./faker-DHh7xs4u.mjs";
|
|
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
|
-
import "./faker-
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { ObjectionFactory } from "./ObjectionFactory-
|
|
1
|
+
import "./faker-DHh7xs4u.mjs";
|
|
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 };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-
|
|
1
|
+
import { VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-DQ7tLqgV.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/VitestKyselyTransactionIsolator.ts
|
|
4
4
|
/**
|
|
@@ -57,4 +57,4 @@ var VitestKyselyTransactionIsolator = class extends VitestPostgresTransactionIso
|
|
|
57
57
|
|
|
58
58
|
//#endregion
|
|
59
59
|
export { VitestKyselyTransactionIsolator };
|
|
60
|
-
//# sourceMappingURL=VitestKyselyTransactionIsolator-
|
|
60
|
+
//# sourceMappingURL=VitestKyselyTransactionIsolator-CNURW8y6.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VitestKyselyTransactionIsolator-
|
|
1
|
+
{"version":3,"file":"VitestKyselyTransactionIsolator-CNURW8y6.mjs","names":["conn: Kysely<Database>","level: IsolationLevel","fn: (trx: Transaction<Database>) => Promise<void>"],"sources":["../src/VitestKyselyTransactionIsolator.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport {\n type IsolationLevel,\n VitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Kysely's transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @template Database - The database schema type\n *\n * @example\n * ```typescript\n * import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';\n * import { db } from './database';\n *\n * // Create isolator instance\n * const isolator = new VitestKyselyTransactionIsolator<Database>();\n *\n * // In your test setup\n * beforeEach(async () => {\n * await isolator.start(db);\n * });\n *\n * afterEach(async () => {\n * await isolator.rollback();\n * });\n *\n * // Tests run in isolated transactions\n * it('should create user', async () => {\n * const user = await db.insertInto('users')\n * .values({ name: 'Test User' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestKyselyTransactionIsolator<\n Database,\n> extends VitestPostgresTransactionIsolator<\n Kysely<Database>,\n Transaction<Database>\n> {\n async destroy(conn: Kysely<Database>): Promise<void> {\n // return conn.destroy();\n }\n /**\n * Creates a Kysely transaction with the specified isolation level.\n * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n *\n * @param conn - The Kysely database connection\n * @param level - The transaction isolation level\n * @param fn - The function to execute within the transaction\n * @returns Promise that resolves when the transaction completes\n */\n async transact(\n conn: Kysely<Database>,\n level: IsolationLevel,\n fn: (trx: Transaction<Database>) => Promise<void>,\n ): Promise<void> {\n const isolationLevel =\n level.toLocaleLowerCase() as Lowercase<IsolationLevel>;\n await conn.transaction().setIsolationLevel(isolationLevel).execute(fn);\n }\n // Implement any Kysely-specific transaction logic here\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,kCAAb,cAEU,kCAGR;CACA,MAAM,QAAQA,MAAuC,CAEpD;;;;;;;;;;CAUD,MAAM,SACJA,MACAC,OACAC,IACe;EACf,MAAM,iBACJ,MAAM,mBAAmB;AAC3B,QAAM,KAAK,aAAa,CAAC,kBAAkB,eAAe,CAAC,QAAQ,GAAG;CACvE;AAEF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-
|
|
1
|
+
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-CwQaxZLP.cjs";
|
|
2
2
|
import { Kysely, Transaction } from "kysely";
|
|
3
3
|
|
|
4
4
|
//#region src/VitestKyselyTransactionIsolator.d.ts
|
|
@@ -55,4 +55,4 @@ declare class VitestKyselyTransactionIsolator<Database> extends VitestPostgresTr
|
|
|
55
55
|
}
|
|
56
56
|
//#endregion
|
|
57
57
|
export { VitestKyselyTransactionIsolator };
|
|
58
|
-
//# sourceMappingURL=VitestKyselyTransactionIsolator-
|
|
58
|
+
//# sourceMappingURL=VitestKyselyTransactionIsolator-D3EZZhjZ.d.cts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-
|
|
1
|
+
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-BvR19bYn.mjs";
|
|
2
2
|
import { Kysely, Transaction } from "kysely";
|
|
3
3
|
|
|
4
4
|
//#region src/VitestKyselyTransactionIsolator.d.ts
|
|
@@ -55,4 +55,4 @@ declare class VitestKyselyTransactionIsolator<Database> extends VitestPostgresTr
|
|
|
55
55
|
}
|
|
56
56
|
//#endregion
|
|
57
57
|
export { VitestKyselyTransactionIsolator };
|
|
58
|
-
//# sourceMappingURL=VitestKyselyTransactionIsolator-
|
|
58
|
+
//# sourceMappingURL=VitestKyselyTransactionIsolator-Dxlp1u0f.d.mts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-
|
|
1
|
+
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-CMfJXZP8.cjs');
|
|
2
2
|
|
|
3
3
|
//#region src/VitestKyselyTransactionIsolator.ts
|
|
4
4
|
/**
|
|
@@ -62,4 +62,4 @@ Object.defineProperty(exports, 'VitestKyselyTransactionIsolator', {
|
|
|
62
62
|
return VitestKyselyTransactionIsolator;
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
|
-
//# sourceMappingURL=VitestKyselyTransactionIsolator-
|
|
65
|
+
//# sourceMappingURL=VitestKyselyTransactionIsolator-EvDLk5zg.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VitestKyselyTransactionIsolator-
|
|
1
|
+
{"version":3,"file":"VitestKyselyTransactionIsolator-EvDLk5zg.cjs","names":["VitestPostgresTransactionIsolator","conn: Kysely<Database>","level: IsolationLevel","fn: (trx: Transaction<Database>) => Promise<void>"],"sources":["../src/VitestKyselyTransactionIsolator.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport {\n type IsolationLevel,\n VitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Kysely's transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @template Database - The database schema type\n *\n * @example\n * ```typescript\n * import { VitestKyselyTransactionIsolator } from '@geekmidas/testkit';\n * import { db } from './database';\n *\n * // Create isolator instance\n * const isolator = new VitestKyselyTransactionIsolator<Database>();\n *\n * // In your test setup\n * beforeEach(async () => {\n * await isolator.start(db);\n * });\n *\n * afterEach(async () => {\n * await isolator.rollback();\n * });\n *\n * // Tests run in isolated transactions\n * it('should create user', async () => {\n * const user = await db.insertInto('users')\n * .values({ name: 'Test User' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestKyselyTransactionIsolator<\n Database,\n> extends VitestPostgresTransactionIsolator<\n Kysely<Database>,\n Transaction<Database>\n> {\n async destroy(conn: Kysely<Database>): Promise<void> {\n // return conn.destroy();\n }\n /**\n * Creates a Kysely transaction with the specified isolation level.\n * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n *\n * @param conn - The Kysely database connection\n * @param level - The transaction isolation level\n * @param fn - The function to execute within the transaction\n * @returns Promise that resolves when the transaction completes\n */\n async transact(\n conn: Kysely<Database>,\n level: IsolationLevel,\n fn: (trx: Transaction<Database>) => Promise<void>,\n ): Promise<void> {\n const isolationLevel =\n level.toLocaleLowerCase() as Lowercase<IsolationLevel>;\n await conn.transaction().setIsolationLevel(isolationLevel).execute(fn);\n }\n // Implement any Kysely-specific transaction logic here\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,kCAAb,cAEUA,oEAGR;CACA,MAAM,QAAQC,MAAuC,CAEpD;;;;;;;;;;CAUD,MAAM,SACJA,MACAC,OACAC,IACe;EACf,MAAM,iBACJ,MAAM,mBAAmB;AAC3B,QAAM,KAAK,aAAa,CAAC,kBAAkB,eAAe,CAAC,QAAQ,GAAG;CACvE;AAEF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require('./VitestTransactionIsolator-
|
|
2
|
-
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-
|
|
1
|
+
require('./VitestTransactionIsolator-CMfJXZP8.cjs');
|
|
2
|
+
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-EvDLk5zg.cjs');
|
|
3
3
|
|
|
4
4
|
exports.VitestKyselyTransactionIsolator = require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./VitestTransactionIsolator-
|
|
2
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-
|
|
1
|
+
import "./VitestTransactionIsolator-CwQaxZLP.cjs";
|
|
2
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-D3EZZhjZ.cjs";
|
|
3
3
|
export { VitestKyselyTransactionIsolator };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./VitestTransactionIsolator-
|
|
2
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-
|
|
1
|
+
import "./VitestTransactionIsolator-BvR19bYn.mjs";
|
|
2
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-Dxlp1u0f.mjs";
|
|
3
3
|
export { VitestKyselyTransactionIsolator };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./VitestTransactionIsolator-
|
|
2
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-
|
|
1
|
+
import "./VitestTransactionIsolator-DQ7tLqgV.mjs";
|
|
2
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-CNURW8y6.mjs";
|
|
3
3
|
|
|
4
4
|
export { VitestKyselyTransactionIsolator };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-
|
|
1
|
+
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-CwQaxZLP.cjs";
|
|
2
2
|
import { Knex } from "knex";
|
|
3
3
|
|
|
4
4
|
//#region src/VitestObjectionTransactionIsolator.d.ts
|
|
@@ -56,4 +56,4 @@ declare class VitestObjectionTransactionIsolator extends VitestPostgresTransacti
|
|
|
56
56
|
}
|
|
57
57
|
//#endregion
|
|
58
58
|
export { VitestObjectionTransactionIsolator };
|
|
59
|
-
//# sourceMappingURL=VitestObjectionTransactionIsolator-
|
|
59
|
+
//# sourceMappingURL=VitestObjectionTransactionIsolator-1TpsPqfG.d.cts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-
|
|
1
|
+
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-CMfJXZP8.cjs');
|
|
2
2
|
|
|
3
3
|
//#region src/VitestObjectionTransactionIsolator.ts
|
|
4
4
|
/**
|
|
@@ -65,4 +65,4 @@ Object.defineProperty(exports, 'VitestObjectionTransactionIsolator', {
|
|
|
65
65
|
return VitestObjectionTransactionIsolator;
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
|
-
//# sourceMappingURL=VitestObjectionTransactionIsolator-
|
|
68
|
+
//# sourceMappingURL=VitestObjectionTransactionIsolator-CM5KTAFA.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VitestObjectionTransactionIsolator-
|
|
1
|
+
{"version":3,"file":"VitestObjectionTransactionIsolator-CM5KTAFA.cjs","names":["VitestPostgresTransactionIsolator","conn: Knex<any, any[]>","connection: Knex","level: IsolationLevel","fn: (trx: Knex.Transaction) => Promise<void>"],"sources":["../src/VitestObjectionTransactionIsolator.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport {\n type IsolationLevel,\n VitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @example\n * ```typescript\n * import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';\n * import { knex } from './database';\n * import { User } from './models';\n * import { test } from 'vitest';\n *\n * // Create isolator instance\n * const isolator = new VitestObjectionTransactionIsolator(test);\n *\n * // Use with wrapped test API\n * const isolatedTest = isolator.wrapVitestWithTransaction(knex);\n *\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await User.query(trx)\n * .insert({ name: 'Test User' });\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<\n Knex,\n Knex.Transaction\n> {\n async destroy(conn: Knex<any, any[]>): Promise<void> {}\n /**\n * Creates a Knex transaction with the specified isolation level.\n * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n * This transaction can be used with Objection.js models via Model.query(trx).\n *\n * @param conn - The Knex database connection\n * @param level - The transaction isolation level\n * @param fn - The function to execute within the transaction\n * @returns Promise that resolves when the transaction completes\n *\n * @example\n * ```typescript\n * await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {\n * // Use transaction with Objection models\n * await User.query(trx).insert({ name: 'Test' });\n * await Post.query(trx).where('userId', user.id).delete();\n * });\n * ```\n */\n async transact(\n connection: Knex,\n level: IsolationLevel,\n fn: (trx: Knex.Transaction) => Promise<void>,\n ): Promise<void> {\n const isolationLevel = level.toLowerCase() as Lowercase<IsolationLevel>;\n\n await connection.transaction(\n async (trx) => {\n await fn(trx);\n },\n {\n isolationLevel,\n },\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,qCAAb,cAAwDA,oEAGtD;CACA,MAAM,QAAQC,MAAuC,CAAE;;;;;;;;;;;;;;;;;;;;CAoBvD,MAAM,SACJC,YACAC,OACAC,IACe;EACf,MAAM,iBAAiB,MAAM,aAAa;AAE1C,QAAM,WAAW,YACf,OAAO,QAAQ;AACb,SAAM,GAAG,IAAI;EACd,GACD,EACE,eACD,EACF;CACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-
|
|
1
|
+
import { IsolationLevel, VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-BvR19bYn.mjs";
|
|
2
2
|
import { Knex } from "knex";
|
|
3
3
|
|
|
4
4
|
//#region src/VitestObjectionTransactionIsolator.d.ts
|
|
@@ -56,4 +56,4 @@ declare class VitestObjectionTransactionIsolator extends VitestPostgresTransacti
|
|
|
56
56
|
}
|
|
57
57
|
//#endregion
|
|
58
58
|
export { VitestObjectionTransactionIsolator };
|
|
59
|
-
//# sourceMappingURL=VitestObjectionTransactionIsolator-
|
|
59
|
+
//# sourceMappingURL=VitestObjectionTransactionIsolator-i9jIgU8Q.d.mts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-
|
|
1
|
+
import { VitestPostgresTransactionIsolator } from "./VitestTransactionIsolator-DQ7tLqgV.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/VitestObjectionTransactionIsolator.ts
|
|
4
4
|
/**
|
|
@@ -60,4 +60,4 @@ var VitestObjectionTransactionIsolator = class extends VitestPostgresTransaction
|
|
|
60
60
|
|
|
61
61
|
//#endregion
|
|
62
62
|
export { VitestObjectionTransactionIsolator };
|
|
63
|
-
//# sourceMappingURL=VitestObjectionTransactionIsolator-
|
|
63
|
+
//# sourceMappingURL=VitestObjectionTransactionIsolator-jQFaCz0u.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VitestObjectionTransactionIsolator-
|
|
1
|
+
{"version":3,"file":"VitestObjectionTransactionIsolator-jQFaCz0u.mjs","names":["conn: Knex<any, any[]>","connection: Knex","level: IsolationLevel","fn: (trx: Knex.Transaction) => Promise<void>"],"sources":["../src/VitestObjectionTransactionIsolator.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport {\n type IsolationLevel,\n VitestPostgresTransactionIsolator,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific implementation of the Vitest transaction isolator.\n * Provides automatic transaction rollback for test isolation using Objection.js and Knex transaction API.\n * Each test runs within a database transaction that is rolled back after completion,\n * ensuring a clean state between tests without the overhead of recreating data.\n *\n * @example\n * ```typescript\n * import { VitestObjectionTransactionIsolator } from '@geekmidas/testkit';\n * import { knex } from './database';\n * import { User } from './models';\n * import { test } from 'vitest';\n *\n * // Create isolator instance\n * const isolator = new VitestObjectionTransactionIsolator(test);\n *\n * // Use with wrapped test API\n * const isolatedTest = isolator.wrapVitestWithTransaction(knex);\n *\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await User.query(trx)\n * .insert({ name: 'Test User' });\n *\n * expect(user).toBeDefined();\n * // This data will be rolled back after the test\n * });\n * ```\n */\nexport class VitestObjectionTransactionIsolator extends VitestPostgresTransactionIsolator<\n Knex,\n Knex.Transaction\n> {\n async destroy(conn: Knex<any, any[]>): Promise<void> {}\n /**\n * Creates a Knex transaction with the specified isolation level.\n * Implements the abstract transact method from VitestPostgresTransactionIsolator.\n * This transaction can be used with Objection.js models via Model.query(trx).\n *\n * @param conn - The Knex database connection\n * @param level - The transaction isolation level\n * @param fn - The function to execute within the transaction\n * @returns Promise that resolves when the transaction completes\n *\n * @example\n * ```typescript\n * await isolator.transact(knex, IsolationLevel.REPEATABLE_READ, async (trx) => {\n * // Use transaction with Objection models\n * await User.query(trx).insert({ name: 'Test' });\n * await Post.query(trx).where('userId', user.id).delete();\n * });\n * ```\n */\n async transact(\n connection: Knex,\n level: IsolationLevel,\n fn: (trx: Knex.Transaction) => Promise<void>,\n ): Promise<void> {\n const isolationLevel = level.toLowerCase() as Lowercase<IsolationLevel>;\n\n await connection.transaction(\n async (trx) => {\n await fn(trx);\n },\n {\n isolationLevel,\n },\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,qCAAb,cAAwD,kCAGtD;CACA,MAAM,QAAQA,MAAuC,CAAE;;;;;;;;;;;;;;;;;;;;CAoBvD,MAAM,SACJC,YACAC,OACAC,IACe;EACf,MAAM,iBAAiB,MAAM,aAAa;AAE1C,QAAM,WAAW,YACf,OAAO,QAAQ;AACb,SAAM,GAAG,IAAI;EACd,GACD,EACE,eACD,EACF;CACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require('./VitestTransactionIsolator-
|
|
2
|
-
const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-
|
|
1
|
+
require('./VitestTransactionIsolator-CMfJXZP8.cjs');
|
|
2
|
+
const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-CM5KTAFA.cjs');
|
|
3
3
|
|
|
4
4
|
exports.VitestObjectionTransactionIsolator = require_VitestObjectionTransactionIsolator.VitestObjectionTransactionIsolator;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./VitestTransactionIsolator-
|
|
2
|
-
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-
|
|
1
|
+
import "./VitestTransactionIsolator-CwQaxZLP.cjs";
|
|
2
|
+
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-1TpsPqfG.cjs";
|
|
3
3
|
export { VitestObjectionTransactionIsolator };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./VitestTransactionIsolator-
|
|
2
|
-
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-
|
|
1
|
+
import "./VitestTransactionIsolator-BvR19bYn.mjs";
|
|
2
|
+
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-i9jIgU8Q.mjs";
|
|
3
3
|
export { VitestObjectionTransactionIsolator };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./VitestTransactionIsolator-
|
|
2
|
-
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-
|
|
1
|
+
import "./VitestTransactionIsolator-DQ7tLqgV.mjs";
|
|
2
|
+
import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-jQFaCz0u.mjs";
|
|
3
3
|
|
|
4
4
|
export { VitestObjectionTransactionIsolator };
|
package/dist/{VitestTransactionIsolator-DLdQlfZ5.d.mts → VitestTransactionIsolator-BvR19bYn.d.mts}
RENAMED
|
@@ -112,30 +112,44 @@ declare abstract class VitestPostgresTransactionIsolator<TConn, Transaction> {
|
|
|
112
112
|
* Creates a wrapped version of Vitest's test API that provides transaction isolation.
|
|
113
113
|
* Each test will run within a database transaction that is automatically rolled back.
|
|
114
114
|
*
|
|
115
|
-
* @param
|
|
116
|
-
* @param setup - Optional setup function to run within the transaction before each test
|
|
117
|
-
* @param level - The transaction isolation level (defaults to REPEATABLE_READ)
|
|
115
|
+
* @param options - Configuration options for transaction wrapping
|
|
118
116
|
* @returns A wrapped test API with transaction support
|
|
119
117
|
*
|
|
120
118
|
* @example
|
|
121
119
|
* ```typescript
|
|
122
|
-
* const isolatedTest = isolator.wrapVitestWithTransaction(
|
|
123
|
-
*
|
|
124
|
-
*
|
|
120
|
+
* const isolatedTest = isolator.wrapVitestWithTransaction({
|
|
121
|
+
* connection: db,
|
|
122
|
+
* setup: async (trx) => {
|
|
123
|
+
* await trx.insert('settings', { key: 'test', value: 'true' });
|
|
124
|
+
* },
|
|
125
|
+
* fixtures: {
|
|
126
|
+
* factory: (trx) => new Factory(trx),
|
|
127
|
+
* },
|
|
125
128
|
* });
|
|
126
129
|
*
|
|
127
|
-
* isolatedTest('test with transaction', async ({ trx }) => {
|
|
128
|
-
* const user = await
|
|
130
|
+
* isolatedTest('test with transaction', async ({ trx, factory }) => {
|
|
131
|
+
* const user = await factory.insert('user', { name: 'Test' });
|
|
129
132
|
* expect(user).toBeDefined();
|
|
130
133
|
* });
|
|
131
134
|
* ```
|
|
132
135
|
*/
|
|
133
|
-
wrapVitestWithTransaction
|
|
134
|
-
trx: Transaction;
|
|
135
|
-
}>;
|
|
136
|
+
wrapVitestWithTransaction<Extended extends Record<string, unknown> = {}>(options: TransactionWrapperOptions<TConn, Transaction, Extended>): TestAPI<DatabaseFixtures<Transaction, object> & Extended>;
|
|
136
137
|
}
|
|
137
138
|
type DatabaseConnectionFn<Conn> = () => Conn | Promise<Conn>;
|
|
138
139
|
type DatabaseConnection<Conn> = DatabaseConnectionFn<Conn>;
|
|
140
|
+
/**
|
|
141
|
+
* Options for wrapping Vitest tests with database transaction isolation.
|
|
142
|
+
*/
|
|
143
|
+
interface TransactionWrapperOptions<TConn, Transaction, Extended extends Record<string, unknown> = {}> {
|
|
144
|
+
/** Function that creates or returns a database connection */
|
|
145
|
+
connection: DatabaseConnection<TConn>;
|
|
146
|
+
/** Optional setup function to run within the transaction before each test */
|
|
147
|
+
setup?: (trx: Transaction) => Promise<void>;
|
|
148
|
+
/** Transaction isolation level (defaults to REPEATABLE_READ) */
|
|
149
|
+
isolationLevel?: IsolationLevel;
|
|
150
|
+
/** Additional fixtures that depend on the transaction */
|
|
151
|
+
fixtures?: FixtureCreators<Transaction, Extended>;
|
|
152
|
+
}
|
|
139
153
|
/**
|
|
140
154
|
* Type for fixture creator functions that depend on the transaction.
|
|
141
155
|
* Each function receives the transaction and returns the fixture value.
|
|
@@ -168,7 +182,10 @@ type TestWithExtendedFixtures<Transaction, Extended extends Record<string, unkno
|
|
|
168
182
|
* import { wrapVitestKyselyTransaction, extendWithFixtures } from '@geekmidas/testkit/kysely';
|
|
169
183
|
*
|
|
170
184
|
* // Create base wrapped test
|
|
171
|
-
* const baseTest = wrapVitestKyselyTransaction(test,
|
|
185
|
+
* const baseTest = wrapVitestKyselyTransaction(test, {
|
|
186
|
+
* connection: db,
|
|
187
|
+
* setup: createTestTables,
|
|
188
|
+
* });
|
|
172
189
|
*
|
|
173
190
|
* // Extend with fixtures
|
|
174
191
|
* const it = extendWithFixtures(baseTest, {
|
|
@@ -185,5 +202,5 @@ type TestWithExtendedFixtures<Transaction, Extended extends Record<string, unkno
|
|
|
185
202
|
*/
|
|
186
203
|
declare function extendWithFixtures<Transaction, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = any>(wrappedTest: T, fixtures: FixtureCreators<Transaction, Extended>): TestWithExtendedFixtures<Transaction, Extended, T>;
|
|
187
204
|
//#endregion
|
|
188
|
-
export { DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, ExtendContextFn, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, VitestPostgresTransactionIsolator, extendWithFixtures };
|
|
189
|
-
//# sourceMappingURL=VitestTransactionIsolator-
|
|
205
|
+
export { DatabaseConnection, DatabaseConnectionFn, DatabaseFixtures, ExtendContextFn, ExtendedDatabaseFixtures, FixtureCreators, IsolationLevel, TestWithExtendedFixtures, TransactionWrapperOptions, VitestPostgresTransactionIsolator, extendWithFixtures };
|
|
206
|
+
//# sourceMappingURL=VitestTransactionIsolator-BvR19bYn.d.mts.map
|