@geekmidas/testkit 0.0.15 → 0.0.16

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.
Files changed (177) hide show
  1. package/dist/{Factory-D7P3bKKb.d.mts → Factory-BZ8uMoXl.d.cts} +3 -2
  2. package/dist/{Factory-pNV7ZQ7-.d.cts → Factory-Cmr3s3-s.d.mts} +3 -2
  3. package/dist/Factory-WMhTNZ9S.cjs +2 -1
  4. package/dist/Factory-WMhTNZ9S.cjs.map +1 -0
  5. package/dist/Factory-z2m01hMj.mjs +2 -1
  6. package/dist/Factory-z2m01hMj.mjs.map +1 -0
  7. package/dist/Factory.d.cts +2 -2
  8. package/dist/Factory.d.mts +2 -2
  9. package/dist/KyselyFactory-BcYkC0t2.mjs +2 -1
  10. package/dist/KyselyFactory-BcYkC0t2.mjs.map +1 -0
  11. package/dist/KyselyFactory-Cf0o2YxO.cjs +2 -1
  12. package/dist/KyselyFactory-Cf0o2YxO.cjs.map +1 -0
  13. package/dist/{KyselyFactory-72P98y5I.d.mts → KyselyFactory-Cx3sezwH.d.mts} +4 -3
  14. package/dist/{KyselyFactory-DLBrYWxU.d.cts → KyselyFactory-DRQ83r0o.d.cts} +4 -3
  15. package/dist/KyselyFactory.d.cts +3 -3
  16. package/dist/KyselyFactory.d.mts +3 -3
  17. package/dist/ObjectionFactory-8hebmnai.mjs +2 -1
  18. package/dist/ObjectionFactory-8hebmnai.mjs.map +1 -0
  19. package/dist/{ObjectionFactory-B40NQWSe.d.mts → ObjectionFactory-C-59Hjwj.d.mts} +4 -3
  20. package/dist/{ObjectionFactory-D3l1VuyX.d.cts → ObjectionFactory-C4X78k0B.d.cts} +4 -3
  21. package/dist/ObjectionFactory-CDriunkS.cjs +2 -1
  22. package/dist/ObjectionFactory-CDriunkS.cjs.map +1 -0
  23. package/dist/ObjectionFactory.d.cts +3 -3
  24. package/dist/ObjectionFactory.d.mts +3 -3
  25. package/dist/{PostgresKyselyMigrator-_6yHZigp.d.mts → PostgresKyselyMigrator-CIx3AFSR.d.mts} +3 -2
  26. package/dist/PostgresKyselyMigrator-CQ3aUoy_.d.cts +2 -1
  27. package/dist/PostgresKyselyMigrator-CfytARcA.cjs +2 -1
  28. package/dist/PostgresKyselyMigrator-CfytARcA.cjs.map +1 -0
  29. package/dist/{PostgresKyselyMigrator-Bdhl251C.mjs → PostgresKyselyMigrator-upT-hmrz.mjs} +3 -2
  30. package/dist/PostgresKyselyMigrator-upT-hmrz.mjs.map +1 -0
  31. package/dist/PostgresKyselyMigrator.d.mts +2 -2
  32. package/dist/PostgresKyselyMigrator.mjs +2 -2
  33. package/dist/PostgresMigrator-D5UkK1_K.d.cts +2 -1
  34. package/dist/PostgresMigrator-DFcNdCvD.cjs +2 -1
  35. package/dist/PostgresMigrator-DFcNdCvD.cjs.map +1 -0
  36. package/dist/{PostgresMigrator-BlvuQl7d.d.mts → PostgresMigrator-DQaRxoaY.d.mts} +2 -1
  37. package/dist/{PostgresMigrator-DxPC_gGu.mjs → PostgresMigrator-DbuJGAVy.mjs} +4 -3
  38. package/dist/PostgresMigrator-DbuJGAVy.mjs.map +1 -0
  39. package/dist/PostgresMigrator.d.mts +1 -1
  40. package/dist/PostgresMigrator.mjs +1 -1
  41. package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs +2 -1
  42. package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs.map +1 -0
  43. package/dist/PostgresObjectionMigrator-CZHHcCOv.d.cts +2 -1
  44. package/dist/{PostgresObjectionMigrator-G4h5FLvU.mjs → PostgresObjectionMigrator-DPj2pOpX.mjs} +3 -2
  45. package/dist/PostgresObjectionMigrator-DPj2pOpX.mjs.map +1 -0
  46. package/dist/{PostgresObjectionMigrator-C69n7vzr.d.mts → PostgresObjectionMigrator-D_hCcrQu.d.mts} +3 -2
  47. package/dist/PostgresObjectionMigrator.d.mts +2 -2
  48. package/dist/PostgresObjectionMigrator.mjs +2 -2
  49. package/dist/VitestKyselyTransactionIsolator-BxjlD1YM.mjs +2 -1
  50. package/dist/VitestKyselyTransactionIsolator-BxjlD1YM.mjs.map +1 -0
  51. package/dist/{VitestKyselyTransactionIsolator-CnxpE9cH.d.mts → VitestKyselyTransactionIsolator-COCVfvfr.d.mts} +3 -2
  52. package/dist/VitestKyselyTransactionIsolator-Cst3vFjb.cjs +2 -1
  53. package/dist/VitestKyselyTransactionIsolator-Cst3vFjb.cjs.map +1 -0
  54. package/dist/VitestKyselyTransactionIsolator-DYUYVEh9.d.cts +2 -1
  55. package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
  56. package/dist/VitestObjectionTransactionIsolator-BU-jXEhz.mjs +2 -1
  57. package/dist/VitestObjectionTransactionIsolator-BU-jXEhz.mjs.map +1 -0
  58. package/dist/VitestObjectionTransactionIsolator-CJ4ds5Qv.d.cts +2 -1
  59. package/dist/VitestObjectionTransactionIsolator-DzeF4UAq.cjs +2 -1
  60. package/dist/VitestObjectionTransactionIsolator-DzeF4UAq.cjs.map +1 -0
  61. package/dist/{VitestObjectionTransactionIsolator-DIM79dCq.d.mts → VitestObjectionTransactionIsolator-b973r9O1.d.mts} +3 -2
  62. package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
  63. package/dist/VitestTransactionIsolator-BQ5FpLtC.cjs +2 -1
  64. package/dist/VitestTransactionIsolator-BQ5FpLtC.cjs.map +1 -0
  65. package/dist/{VitestTransactionIsolator-zdyiS_SY.d.mts → VitestTransactionIsolator-CsfJBxcb.d.mts} +2 -1
  66. package/dist/VitestTransactionIsolator-CskiiJbW.mjs +2 -1
  67. package/dist/VitestTransactionIsolator-CskiiJbW.mjs.map +1 -0
  68. package/dist/VitestTransactionIsolator-DdLNODZg.d.cts +2 -1
  69. package/dist/VitestTransactionIsolator.d.mts +1 -1
  70. package/dist/aws.cjs +126 -0
  71. package/dist/aws.cjs.map +1 -0
  72. package/dist/aws.d.cts +22 -0
  73. package/dist/aws.d.mts +22 -0
  74. package/dist/aws.mjs +123 -0
  75. package/dist/aws.mjs.map +1 -0
  76. package/dist/directory-B-Ozljzk.mjs +22 -0
  77. package/dist/directory-B-Ozljzk.mjs.map +1 -0
  78. package/dist/directory-B4oYx02C.d.mts +12 -0
  79. package/dist/directory-BUcnztHI.d.cts +12 -0
  80. package/dist/directory-BVC8g7cX.cjs +28 -0
  81. package/dist/directory-BVC8g7cX.cjs.map +1 -0
  82. package/dist/faker-B14IEMIN.cjs +2 -1
  83. package/dist/faker-B14IEMIN.cjs.map +1 -0
  84. package/dist/faker-BGKYFoCT.mjs +2 -1
  85. package/dist/faker-BGKYFoCT.mjs.map +1 -0
  86. package/dist/{faker-BSH1EMtg.d.cts → faker-Cg76aFNO.d.cts} +4 -3
  87. package/dist/{faker-C-Iuk_R1.d.mts → faker-DHh7xs4u.d.mts} +4 -3
  88. package/dist/faker.d.cts +1 -1
  89. package/dist/faker.d.mts +1 -1
  90. package/dist/helpers.cjs +48 -2
  91. package/dist/helpers.cjs.map +1 -0
  92. package/dist/helpers.d.cts +2 -1
  93. package/dist/helpers.d.mts +2 -1
  94. package/dist/helpers.mjs +47 -2
  95. package/dist/helpers.mjs.map +1 -0
  96. package/dist/kysely.cjs +65 -2
  97. package/dist/kysely.cjs.map +1 -0
  98. package/dist/kysely.d.cts +5 -4
  99. package/dist/kysely.d.mts +9 -8
  100. package/dist/kysely.mjs +67 -4
  101. package/dist/kysely.mjs.map +1 -0
  102. package/dist/logger.cjs +23 -0
  103. package/dist/logger.cjs.map +1 -0
  104. package/dist/logger.d.cts +11 -0
  105. package/dist/logger.d.mts +11 -0
  106. package/dist/logger.mjs +22 -0
  107. package/dist/logger.mjs.map +1 -0
  108. package/dist/objection.cjs +80 -2
  109. package/dist/objection.cjs.map +1 -0
  110. package/dist/objection.d.cts +5 -4
  111. package/dist/objection.d.mts +9 -8
  112. package/dist/objection.mjs +82 -4
  113. package/dist/objection.mjs.map +1 -0
  114. package/dist/os/directory.cjs +3 -0
  115. package/dist/os/directory.d.cts +2 -0
  116. package/dist/os/directory.d.mts +2 -0
  117. package/dist/os/directory.mjs +3 -0
  118. package/dist/os/index.cjs +3 -0
  119. package/dist/os/index.d.cts +2 -0
  120. package/dist/os/index.d.mts +2 -0
  121. package/dist/os/index.mjs +3 -0
  122. package/dist/timer.cjs +9 -0
  123. package/dist/timer.cjs.map +1 -0
  124. package/dist/timer.d.cts +5 -0
  125. package/dist/timer.d.mts +5 -0
  126. package/dist/timer.mjs +8 -0
  127. package/dist/timer.mjs.map +1 -0
  128. package/package.json +24 -2
  129. package/src/aws.ts +131 -0
  130. package/src/logger.ts +18 -0
  131. package/src/os/directory.ts +21 -0
  132. package/src/os/index.ts +1 -0
  133. package/src/timer.ts +3 -0
  134. package/dist/__tests__/Factory.spec.cjs +0 -139
  135. package/dist/__tests__/Factory.spec.d.cts +0 -1
  136. package/dist/__tests__/Factory.spec.d.mts +0 -1
  137. package/dist/__tests__/Factory.spec.mjs +0 -138
  138. package/dist/__tests__/KyselyFactory.spec.cjs +0 -235
  139. package/dist/__tests__/KyselyFactory.spec.d.cts +0 -1
  140. package/dist/__tests__/KyselyFactory.spec.d.mts +0 -1
  141. package/dist/__tests__/KyselyFactory.spec.mjs +0 -234
  142. package/dist/__tests__/ObjectionFactory.spec.cjs +0 -340
  143. package/dist/__tests__/ObjectionFactory.spec.d.cts +0 -1
  144. package/dist/__tests__/ObjectionFactory.spec.d.mts +0 -1
  145. package/dist/__tests__/ObjectionFactory.spec.mjs +0 -339
  146. package/dist/__tests__/PostgresKyselyMigrator.spec.cjs +0 -397
  147. package/dist/__tests__/PostgresKyselyMigrator.spec.d.cts +0 -1
  148. package/dist/__tests__/PostgresKyselyMigrator.spec.d.mts +0 -1
  149. package/dist/__tests__/PostgresKyselyMigrator.spec.mjs +0 -396
  150. package/dist/__tests__/PostgresMigrator.spec.cjs +0 -256
  151. package/dist/__tests__/PostgresMigrator.spec.d.cts +0 -1
  152. package/dist/__tests__/PostgresMigrator.spec.d.mts +0 -1
  153. package/dist/__tests__/PostgresMigrator.spec.mjs +0 -255
  154. package/dist/__tests__/PostgresObjectionMigrator.spec.cjs +0 -432
  155. package/dist/__tests__/PostgresObjectionMigrator.spec.d.cts +0 -1
  156. package/dist/__tests__/PostgresObjectionMigrator.spec.d.mts +0 -1
  157. package/dist/__tests__/PostgresObjectionMigrator.spec.mjs +0 -431
  158. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.cjs +0 -122
  159. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.cts +0 -1
  160. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.mts +0 -1
  161. package/dist/__tests__/VitestObjectionTransactionIsolator.spec.mjs +0 -121
  162. package/dist/__tests__/faker.spec.cjs +0 -115
  163. package/dist/__tests__/faker.spec.d.cts +0 -1
  164. package/dist/__tests__/faker.spec.d.mts +0 -1
  165. package/dist/__tests__/faker.spec.mjs +0 -114
  166. package/dist/__tests__/integration.spec.cjs +0 -282
  167. package/dist/__tests__/integration.spec.d.cts +0 -1
  168. package/dist/__tests__/integration.spec.d.mts +0 -1
  169. package/dist/__tests__/integration.spec.mjs +0 -281
  170. package/dist/helpers-B4TXg3Wp.mjs +0 -86
  171. package/dist/helpers-Bf0nXhbu.cjs +0 -116
  172. package/dist/helpers-BuPmgzyQ.mjs +0 -47
  173. package/dist/helpers-nEUtQ7eo.cjs +0 -53
  174. package/dist/kysely-C3h7kitU.mjs +0 -67
  175. package/dist/kysely-VU3MwvMD.cjs +0 -72
  176. package/dist/objection-BI7F86qf.mjs +0 -82
  177. package/dist/objection-BpLv_ZfC.cjs +0 -87
@@ -5,10 +5,88 @@ require('./PostgresMigrator-DFcNdCvD.cjs');
5
5
  const require_PostgresObjectionMigrator = require('./PostgresObjectionMigrator-BG6ymgnt.cjs');
6
6
  const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BQ5FpLtC.cjs');
7
7
  const require_VitestObjectionTransactionIsolator = require('./VitestObjectionTransactionIsolator-DzeF4UAq.cjs');
8
- const require_objection = require('./objection-BpLv_ZfC.cjs');
9
8
 
9
+ //#region src/objection.ts
10
+ /**
11
+ * Creates a wrapped Vitest test API with automatic transaction rollback for Objection.js.
12
+ * Each test runs in an isolated database transaction that is rolled back after completion.
13
+ * This ensures tests don't affect each other's data and run faster than truncating tables.
14
+ *
15
+ * @param api - The Vitest test API (usually `test` from vitest)
16
+ * @param conn - The Knex database connection instance
17
+ * @param setup - Optional setup function to run before each test in the transaction
18
+ * @param level - Transaction isolation level (defaults to REPEATABLE_READ)
19
+ * @returns A wrapped test API that provides transaction isolation
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * import { test } from 'vitest';
24
+ * import { wrapVitestObjectionTransaction } from '@geekmidas/testkit/objection';
25
+ * import { knex } from './database';
26
+ * import { User, Post } from './models';
27
+ *
28
+ * // Create isolated test with automatic rollback
29
+ * const isolatedTest = wrapVitestObjectionTransaction(test, knex);
30
+ *
31
+ * // Use in tests - each test gets its own transaction
32
+ * isolatedTest('should create user', async ({ trx }) => {
33
+ * const user = await User.query(trx)
34
+ * .insert({ name: 'Test User', email: 'test@example.com' });
35
+ *
36
+ * expect(user).toBeDefined();
37
+ * // User is automatically rolled back after test
38
+ * });
39
+ *
40
+ * // With setup function for common test data
41
+ * const testWithSetup = wrapVitestObjectionTransaction(
42
+ * test,
43
+ * knex,
44
+ * async (trx) => {
45
+ * // Create common test data
46
+ * await knex('settings')
47
+ * .transacting(trx)
48
+ * .insert({ key: 'test_mode', value: 'true' });
49
+ * }
50
+ * );
51
+ *
52
+ * testWithSetup('should have test settings', async ({ trx }) => {
53
+ * const setting = await knex('settings')
54
+ * .transacting(trx)
55
+ * .where('key', 'test_mode')
56
+ * .first();
57
+ *
58
+ * expect(setting?.value).toBe('true');
59
+ * });
60
+ *
61
+ * // Example with factory and transaction
62
+ * const isolatedTest = wrapVitestObjectionTransaction(test, knex);
63
+ * const factory = new ObjectionFactory(builders, seeds, knex);
64
+ *
65
+ * isolatedTest('creates related data', async ({ trx }) => {
66
+ * // Factory can use the transaction
67
+ * const user = await User.query(trx).insert({ name: 'Author' });
68
+ * const posts = await Post.query(trx).insert([
69
+ * { title: 'Post 1', userId: user.id },
70
+ * { title: 'Post 2', userId: user.id }
71
+ * ]);
72
+ *
73
+ * const userWithPosts = await User.query(trx)
74
+ * .findById(user.id)
75
+ * .withGraphFetched('posts');
76
+ *
77
+ * expect(userWithPosts.posts).toHaveLength(2);
78
+ * });
79
+ * ```
80
+ */
81
+ function wrapVitestObjectionTransaction(api, conn, setup, level = require_VitestTransactionIsolator.IsolationLevel.REPEATABLE_READ) {
82
+ const wrapper = new require_VitestObjectionTransactionIsolator.VitestObjectionTransactionIsolator(api);
83
+ return wrapper.wrapVitestWithTransaction(conn, setup, level);
84
+ }
85
+
86
+ //#endregion
10
87
  exports.IsolationLevel = require_VitestTransactionIsolator.IsolationLevel;
11
88
  exports.ObjectionFactory = require_ObjectionFactory.ObjectionFactory;
12
89
  exports.PostgresObjectionMigrator = require_PostgresObjectionMigrator.PostgresObjectionMigrator;
13
90
  exports.VitestObjectionTransactionIsolator = require_VitestObjectionTransactionIsolator.VitestObjectionTransactionIsolator;
14
- exports.wrapVitestObjectionTransaction = require_objection.wrapVitestObjectionTransaction;
91
+ exports.wrapVitestObjectionTransaction = wrapVitestObjectionTransaction;
92
+ //# sourceMappingURL=objection.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objection.cjs","names":["api: TestAPI","conn: DatabaseConnection<Knex>","setup?: (trx: Knex.Transaction) => Promise<void>","level: IsolationLevel","IsolationLevel","VitestObjectionTransactionIsolator"],"sources":["../src/objection.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport type { TestAPI } from 'vitest';\nimport { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';\nimport {\n type DatabaseConnection,\n IsolationLevel,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific exports for test utilities.\n * Provides factory implementation for creating test data with Objection.js ORM\n * and transaction isolation for test suites.\n */\n\nexport { ObjectionFactory } from './ObjectionFactory';\nexport { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\nexport { PostgresObjectionMigrator } from './PostgresObjectionMigrator';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Objection.js.\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 * @param api - The Vitest test API (usually `test` from vitest)\n * @param conn - The Knex database connection instance\n * @param setup - Optional setup function to run before each test in the transaction\n * @param level - Transaction isolation level (defaults to REPEATABLE_READ)\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestObjectionTransaction } from '@geekmidas/testkit/objection';\n * import { knex } from './database';\n * import { User, Post } from './models';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestObjectionTransaction(test, knex);\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await User.query(trx)\n * .insert({ name: 'Test User', email: 'test@example.com' });\n *\n * expect(user).toBeDefined();\n * // User is automatically rolled back after test\n * });\n *\n * // With setup function for common test data\n * const testWithSetup = wrapVitestObjectionTransaction(\n * test,\n * knex,\n * async (trx) => {\n * // Create common test data\n * await knex('settings')\n * .transacting(trx)\n * .insert({ key: 'test_mode', value: 'true' });\n * }\n * );\n *\n * testWithSetup('should have test settings', async ({ trx }) => {\n * const setting = await knex('settings')\n * .transacting(trx)\n * .where('key', 'test_mode')\n * .first();\n *\n * expect(setting?.value).toBe('true');\n * });\n *\n * // Example with factory and transaction\n * const isolatedTest = wrapVitestObjectionTransaction(test, knex);\n * const factory = new ObjectionFactory(builders, seeds, knex);\n *\n * isolatedTest('creates related data', async ({ trx }) => {\n * // Factory can use the transaction\n * const user = await User.query(trx).insert({ name: 'Author' });\n * const posts = await Post.query(trx).insert([\n * { title: 'Post 1', userId: user.id },\n * { title: 'Post 2', userId: user.id }\n * ]);\n *\n * const userWithPosts = await User.query(trx)\n * .findById(user.id)\n * .withGraphFetched('posts');\n *\n * expect(userWithPosts.posts).toHaveLength(2);\n * });\n * ```\n */\nexport function wrapVitestObjectionTransaction(\n api: TestAPI,\n conn: DatabaseConnection<Knex>,\n setup?: (trx: Knex.Transaction) => Promise<void>,\n level: IsolationLevel = IsolationLevel.REPEATABLE_READ,\n) {\n const wrapper = new VitestObjectionTransactionIsolator(api);\n\n return wrapper.wrapVitestWithTransaction(conn, setup, level);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0FA,SAAgB,+BACdA,KACAC,MACAC,OACAC,QAAwBC,iDAAe,iBACvC;CACA,MAAM,UAAU,IAAIC,8EAAmC;AAEvD,QAAO,QAAQ,0BAA0B,MAAM,OAAO,MAAM;AAC7D"}
@@ -1,6 +1,6 @@
1
- import "./faker-BSH1EMtg.cjs";
2
- import "./Factory-pNV7ZQ7-.cjs";
3
- import { ObjectionFactory } from "./ObjectionFactory-D3l1VuyX.cjs";
1
+ import "./faker-Cg76aFNO.cjs";
2
+ import "./Factory-BZ8uMoXl.cjs";
3
+ import { ObjectionFactory } from "./ObjectionFactory-C4X78k0B.cjs";
4
4
  import "./PostgresMigrator-D5UkK1_K.cjs";
5
5
  import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-CZHHcCOv.cjs";
6
6
  import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-DdLNODZg.cjs";
@@ -85,4 +85,5 @@ declare function wrapVitestObjectionTransaction(api: TestAPI, conn: DatabaseConn
85
85
  trx: Knex.Transaction<any, any[]>;
86
86
  }>;
87
87
  //#endregion
88
- export { IsolationLevel, ObjectionFactory, PostgresObjectionMigrator, VitestObjectionTransactionIsolator, wrapVitestObjectionTransaction };
88
+ export { IsolationLevel, ObjectionFactory, PostgresObjectionMigrator, VitestObjectionTransactionIsolator, wrapVitestObjectionTransaction };
89
+ //# sourceMappingURL=objection.d.cts.map
@@ -1,10 +1,10 @@
1
- import "./faker-C-Iuk_R1.mjs";
2
- import "./Factory-D7P3bKKb.mjs";
3
- import { ObjectionFactory } from "./ObjectionFactory-B40NQWSe.mjs";
4
- import "./PostgresMigrator-BlvuQl7d.mjs";
5
- import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-C69n7vzr.mjs";
6
- import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-zdyiS_SY.mjs";
7
- import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-DIM79dCq.mjs";
1
+ import "./faker-DHh7xs4u.mjs";
2
+ import "./Factory-Cmr3s3-s.mjs";
3
+ import { ObjectionFactory } from "./ObjectionFactory-C-59Hjwj.mjs";
4
+ import "./PostgresMigrator-DQaRxoaY.mjs";
5
+ import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-D_hCcrQu.mjs";
6
+ import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-CsfJBxcb.mjs";
7
+ import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-b973r9O1.mjs";
8
8
  import { TestAPI } from "vitest";
9
9
  import { Knex } from "knex";
10
10
 
@@ -85,4 +85,5 @@ declare function wrapVitestObjectionTransaction(api: TestAPI, conn: DatabaseConn
85
85
  trx: Knex.Transaction<any, any[]>;
86
86
  }>;
87
87
  //#endregion
88
- export { IsolationLevel, ObjectionFactory, PostgresObjectionMigrator, VitestObjectionTransactionIsolator, wrapVitestObjectionTransaction };
88
+ export { IsolationLevel, ObjectionFactory, PostgresObjectionMigrator, VitestObjectionTransactionIsolator, wrapVitestObjectionTransaction };
89
+ //# sourceMappingURL=objection.d.mts.map
@@ -1,10 +1,88 @@
1
1
  import "./Factory-z2m01hMj.mjs";
2
2
  import "./faker-BGKYFoCT.mjs";
3
3
  import { ObjectionFactory } from "./ObjectionFactory-8hebmnai.mjs";
4
- import "./PostgresMigrator-DxPC_gGu.mjs";
5
- import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-G4h5FLvU.mjs";
4
+ import "./PostgresMigrator-DbuJGAVy.mjs";
5
+ import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-DPj2pOpX.mjs";
6
6
  import { IsolationLevel } from "./VitestTransactionIsolator-CskiiJbW.mjs";
7
7
  import { VitestObjectionTransactionIsolator } from "./VitestObjectionTransactionIsolator-BU-jXEhz.mjs";
8
- import { wrapVitestObjectionTransaction } from "./objection-BI7F86qf.mjs";
9
8
 
10
- export { IsolationLevel, ObjectionFactory, PostgresObjectionMigrator, VitestObjectionTransactionIsolator, wrapVitestObjectionTransaction };
9
+ //#region src/objection.ts
10
+ /**
11
+ * Creates a wrapped Vitest test API with automatic transaction rollback for Objection.js.
12
+ * Each test runs in an isolated database transaction that is rolled back after completion.
13
+ * This ensures tests don't affect each other's data and run faster than truncating tables.
14
+ *
15
+ * @param api - The Vitest test API (usually `test` from vitest)
16
+ * @param conn - The Knex database connection instance
17
+ * @param setup - Optional setup function to run before each test in the transaction
18
+ * @param level - Transaction isolation level (defaults to REPEATABLE_READ)
19
+ * @returns A wrapped test API that provides transaction isolation
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * import { test } from 'vitest';
24
+ * import { wrapVitestObjectionTransaction } from '@geekmidas/testkit/objection';
25
+ * import { knex } from './database';
26
+ * import { User, Post } from './models';
27
+ *
28
+ * // Create isolated test with automatic rollback
29
+ * const isolatedTest = wrapVitestObjectionTransaction(test, knex);
30
+ *
31
+ * // Use in tests - each test gets its own transaction
32
+ * isolatedTest('should create user', async ({ trx }) => {
33
+ * const user = await User.query(trx)
34
+ * .insert({ name: 'Test User', email: 'test@example.com' });
35
+ *
36
+ * expect(user).toBeDefined();
37
+ * // User is automatically rolled back after test
38
+ * });
39
+ *
40
+ * // With setup function for common test data
41
+ * const testWithSetup = wrapVitestObjectionTransaction(
42
+ * test,
43
+ * knex,
44
+ * async (trx) => {
45
+ * // Create common test data
46
+ * await knex('settings')
47
+ * .transacting(trx)
48
+ * .insert({ key: 'test_mode', value: 'true' });
49
+ * }
50
+ * );
51
+ *
52
+ * testWithSetup('should have test settings', async ({ trx }) => {
53
+ * const setting = await knex('settings')
54
+ * .transacting(trx)
55
+ * .where('key', 'test_mode')
56
+ * .first();
57
+ *
58
+ * expect(setting?.value).toBe('true');
59
+ * });
60
+ *
61
+ * // Example with factory and transaction
62
+ * const isolatedTest = wrapVitestObjectionTransaction(test, knex);
63
+ * const factory = new ObjectionFactory(builders, seeds, knex);
64
+ *
65
+ * isolatedTest('creates related data', async ({ trx }) => {
66
+ * // Factory can use the transaction
67
+ * const user = await User.query(trx).insert({ name: 'Author' });
68
+ * const posts = await Post.query(trx).insert([
69
+ * { title: 'Post 1', userId: user.id },
70
+ * { title: 'Post 2', userId: user.id }
71
+ * ]);
72
+ *
73
+ * const userWithPosts = await User.query(trx)
74
+ * .findById(user.id)
75
+ * .withGraphFetched('posts');
76
+ *
77
+ * expect(userWithPosts.posts).toHaveLength(2);
78
+ * });
79
+ * ```
80
+ */
81
+ function wrapVitestObjectionTransaction(api, conn, setup, level = IsolationLevel.REPEATABLE_READ) {
82
+ const wrapper = new VitestObjectionTransactionIsolator(api);
83
+ return wrapper.wrapVitestWithTransaction(conn, setup, level);
84
+ }
85
+
86
+ //#endregion
87
+ export { IsolationLevel, ObjectionFactory, PostgresObjectionMigrator, VitestObjectionTransactionIsolator, wrapVitestObjectionTransaction };
88
+ //# sourceMappingURL=objection.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objection.mjs","names":["api: TestAPI","conn: DatabaseConnection<Knex>","setup?: (trx: Knex.Transaction) => Promise<void>","level: IsolationLevel"],"sources":["../src/objection.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport type { TestAPI } from 'vitest';\nimport { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';\nimport {\n type DatabaseConnection,\n IsolationLevel,\n} from './VitestTransactionIsolator';\n\n/**\n * Objection.js-specific exports for test utilities.\n * Provides factory implementation for creating test data with Objection.js ORM\n * and transaction isolation for test suites.\n */\n\nexport { ObjectionFactory } from './ObjectionFactory';\nexport { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\nexport { PostgresObjectionMigrator } from './PostgresObjectionMigrator';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Objection.js.\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 * @param api - The Vitest test API (usually `test` from vitest)\n * @param conn - The Knex database connection instance\n * @param setup - Optional setup function to run before each test in the transaction\n * @param level - Transaction isolation level (defaults to REPEATABLE_READ)\n * @returns A wrapped test API that provides transaction isolation\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestObjectionTransaction } from '@geekmidas/testkit/objection';\n * import { knex } from './database';\n * import { User, Post } from './models';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestObjectionTransaction(test, knex);\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await User.query(trx)\n * .insert({ name: 'Test User', email: 'test@example.com' });\n *\n * expect(user).toBeDefined();\n * // User is automatically rolled back after test\n * });\n *\n * // With setup function for common test data\n * const testWithSetup = wrapVitestObjectionTransaction(\n * test,\n * knex,\n * async (trx) => {\n * // Create common test data\n * await knex('settings')\n * .transacting(trx)\n * .insert({ key: 'test_mode', value: 'true' });\n * }\n * );\n *\n * testWithSetup('should have test settings', async ({ trx }) => {\n * const setting = await knex('settings')\n * .transacting(trx)\n * .where('key', 'test_mode')\n * .first();\n *\n * expect(setting?.value).toBe('true');\n * });\n *\n * // Example with factory and transaction\n * const isolatedTest = wrapVitestObjectionTransaction(test, knex);\n * const factory = new ObjectionFactory(builders, seeds, knex);\n *\n * isolatedTest('creates related data', async ({ trx }) => {\n * // Factory can use the transaction\n * const user = await User.query(trx).insert({ name: 'Author' });\n * const posts = await Post.query(trx).insert([\n * { title: 'Post 1', userId: user.id },\n * { title: 'Post 2', userId: user.id }\n * ]);\n *\n * const userWithPosts = await User.query(trx)\n * .findById(user.id)\n * .withGraphFetched('posts');\n *\n * expect(userWithPosts.posts).toHaveLength(2);\n * });\n * ```\n */\nexport function wrapVitestObjectionTransaction(\n api: TestAPI,\n conn: DatabaseConnection<Knex>,\n setup?: (trx: Knex.Transaction) => Promise<void>,\n level: IsolationLevel = IsolationLevel.REPEATABLE_READ,\n) {\n const wrapper = new VitestObjectionTransactionIsolator(api);\n\n return wrapper.wrapVitestWithTransaction(conn, setup, level);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0FA,SAAgB,+BACdA,KACAC,MACAC,OACAC,QAAwB,eAAe,iBACvC;CACA,MAAM,UAAU,IAAI,mCAAmC;AAEvD,QAAO,QAAQ,0BAA0B,MAAM,OAAO,MAAM;AAC7D"}
@@ -0,0 +1,3 @@
1
+ const require_directory = require('../directory-BVC8g7cX.cjs');
2
+
3
+ exports.itWithDir = require_directory.itWithDir;
@@ -0,0 +1,2 @@
1
+ import { DirectoryFixtures, itWithDir } from "../directory-BUcnztHI.cjs";
2
+ export { DirectoryFixtures, itWithDir };
@@ -0,0 +1,2 @@
1
+ import { DirectoryFixtures, itWithDir } from "../directory-B4oYx02C.mjs";
2
+ export { DirectoryFixtures, itWithDir };
@@ -0,0 +1,3 @@
1
+ import { itWithDir } from "../directory-B-Ozljzk.mjs";
2
+
3
+ export { itWithDir };
@@ -0,0 +1,3 @@
1
+ const require_directory = require('../directory-BVC8g7cX.cjs');
2
+
3
+ exports.itWithDir = require_directory.itWithDir;
@@ -0,0 +1,2 @@
1
+ import { itWithDir } from "../directory-BUcnztHI.cjs";
2
+ export { itWithDir };
@@ -0,0 +1,2 @@
1
+ import { itWithDir } from "../directory-B4oYx02C.mjs";
2
+ export { itWithDir };
@@ -0,0 +1,3 @@
1
+ import { itWithDir } from "../directory-B-Ozljzk.mjs";
2
+
3
+ export { itWithDir };
package/dist/timer.cjs ADDED
@@ -0,0 +1,9 @@
1
+
2
+ //#region src/timer.ts
3
+ function waitFor(ms) {
4
+ return new Promise((resolve) => setTimeout(resolve, ms));
5
+ }
6
+
7
+ //#endregion
8
+ exports.waitFor = waitFor;
9
+ //# sourceMappingURL=timer.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer.cjs","names":["ms: number"],"sources":["../src/timer.ts"],"sourcesContent":["export function waitFor(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"],"mappings":";;AAAA,SAAgB,QAAQA,IAAY;AAClC,QAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAG;AACxD"}
@@ -0,0 +1,5 @@
1
+ //#region src/timer.d.ts
2
+ declare function waitFor(ms: number): Promise<unknown>;
3
+ //#endregion
4
+ export { waitFor };
5
+ //# sourceMappingURL=timer.d.cts.map
@@ -0,0 +1,5 @@
1
+ //#region src/timer.d.ts
2
+ declare function waitFor(ms: number): Promise<unknown>;
3
+ //#endregion
4
+ export { waitFor };
5
+ //# sourceMappingURL=timer.d.mts.map
package/dist/timer.mjs ADDED
@@ -0,0 +1,8 @@
1
+ //#region src/timer.ts
2
+ function waitFor(ms) {
3
+ return new Promise((resolve) => setTimeout(resolve, ms));
4
+ }
5
+
6
+ //#endregion
7
+ export { waitFor };
8
+ //# sourceMappingURL=timer.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer.mjs","names":["ms: number"],"sources":["../src/timer.ts"],"sourcesContent":["export function waitFor(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"],"mappings":";AAAA,SAAgB,QAAQA,IAAY;AAClC,QAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAG;AACxD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/testkit",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -9,19 +9,40 @@
9
9
  "import": "./dist/objection.mjs",
10
10
  "require": "./dist/objection.cjs"
11
11
  },
12
+ "./timer": {
13
+ "types": "./dist/timer.d.ts",
14
+ "import": "./dist/timer.mjs",
15
+ "require": "./dist/timer.cjs"
16
+ },
12
17
  "./kysely": {
13
18
  "types": "./dist/kysely.d.ts",
14
19
  "import": "./dist/kysely.mjs",
15
20
  "require": "./dist/kysely.cjs"
16
21
  },
22
+ "./os": {
23
+ "types": "./dist/os/index.d.ts",
24
+ "import": "./dist/os/index.mjs",
25
+ "require": "./dist/os/index.cjs"
26
+ },
17
27
  "./faker": {
18
28
  "types": "./dist/faker.d.ts",
19
29
  "import": "./dist/faker.mjs",
20
30
  "require": "./dist/faker.cjs"
31
+ },
32
+ "./aws": {
33
+ "types": "./dist/aws.d.ts",
34
+ "import": "./dist/aws.mjs",
35
+ "require": "./dist/aws.cjs"
36
+ },
37
+ "./logger": {
38
+ "types": "./dist/logger.d.ts",
39
+ "import": "./dist/logger.mjs",
40
+ "require": "./dist/logger.cjs"
21
41
  }
22
42
  },
23
43
  "dependencies": {
24
- "@faker-js/faker": "~9.9.0"
44
+ "@faker-js/faker": "~9.9.0",
45
+ "@geekmidas/logger": "0.0.1"
25
46
  },
26
47
  "devDependencies": {
27
48
  "@types/pg": "~8.15.4"
@@ -37,6 +58,7 @@
37
58
  "objection": "~3.1.5",
38
59
  "db-errors": "~0.2.3",
39
60
  "vitest": "~3.2.4",
61
+ "@types/aws-lambda": ">=8.10.92",
40
62
  "@geekmidas/envkit": "0.0.7"
41
63
  }
42
64
  }
package/src/aws.ts ADDED
@@ -0,0 +1,131 @@
1
+ import type {
2
+ APIGatewayProxyEvent,
3
+ APIGatewayProxyEventV2,
4
+ Context,
5
+ } from 'aws-lambda';
6
+ import { vi } from 'vitest';
7
+
8
+ /**
9
+ * Shared test utilities for AWS Lambda adapter testing
10
+ */
11
+
12
+ /**
13
+ * Creates a mock AWS Lambda Context for testing
14
+ */
15
+ export function createMockContext(): Context {
16
+ return {
17
+ awsRequestId: 'test-request-id',
18
+ callbackWaitsForEmptyEventLoop: false,
19
+ functionName: 'test-function',
20
+ functionVersion: '1',
21
+ invokedFunctionArn:
22
+ 'arn:aws:lambda:us-east-1:123456789012:function:test-function',
23
+ memoryLimitInMB: '128',
24
+ logGroupName: '/aws/lambda/test-function',
25
+ logStreamName: '2024/01/01/[$LATEST]abcdef123456',
26
+ getRemainingTimeInMillis: () => 5000,
27
+ done: vi.fn(),
28
+ fail: vi.fn(),
29
+ succeed: vi.fn(),
30
+ };
31
+ }
32
+
33
+ /**
34
+ * Creates a mock AWS API Gateway V1 (REST API) event for testing
35
+ */
36
+ export function createMockV1Event(
37
+ overrides: Partial<APIGatewayProxyEvent> = {},
38
+ ): APIGatewayProxyEvent {
39
+ return {
40
+ body: null,
41
+ headers: {
42
+ 'content-type': 'application/json',
43
+ 'user-agent': 'test-agent',
44
+ host: 'test.example.com',
45
+ },
46
+ multiValueHeaders: {},
47
+ httpMethod: 'GET',
48
+ isBase64Encoded: false,
49
+ path: '/test',
50
+ pathParameters: null,
51
+ queryStringParameters: null,
52
+ multiValueQueryStringParameters: null,
53
+ stageVariables: null,
54
+ requestContext: {
55
+ accountId: '123456789012',
56
+ apiId: 'api-id',
57
+ authorizer: null,
58
+ protocol: 'HTTP/1.1',
59
+ httpMethod: 'GET',
60
+ path: '/test',
61
+ stage: 'test',
62
+ requestId: 'request-id',
63
+ requestTimeEpoch: 1704067200000,
64
+ resourceId: 'resource-id',
65
+ resourcePath: '/test',
66
+ identity: {
67
+ accessKey: null,
68
+ accountId: null,
69
+ apiKey: null,
70
+ apiKeyId: null,
71
+ caller: null,
72
+ cognitoAuthenticationProvider: null,
73
+ cognitoAuthenticationType: null,
74
+ cognitoIdentityId: null,
75
+ cognitoIdentityPoolId: null,
76
+ principalOrgId: null,
77
+ sourceIp: '127.0.0.1',
78
+ user: null,
79
+ userAgent: 'test-agent',
80
+ userArn: null,
81
+ clientCert: null,
82
+ },
83
+ },
84
+ resource: '/test',
85
+ ...overrides,
86
+ };
87
+ }
88
+
89
+ /**
90
+ * Creates a mock AWS API Gateway V2 (HTTP API) event for testing
91
+ */
92
+ export function createMockV2Event(
93
+ overrides: Partial<APIGatewayProxyEventV2> = {},
94
+ ): APIGatewayProxyEventV2 {
95
+ return {
96
+ version: '2.0',
97
+ routeKey: 'GET /test',
98
+ rawPath: '/test',
99
+ rawQueryString: '',
100
+ headers: {
101
+ 'content-type': 'application/json',
102
+ 'user-agent': 'test-agent',
103
+ host: 'test.example.com',
104
+ },
105
+ requestContext: {
106
+ accountId: '123456789012',
107
+ apiId: 'api-id',
108
+ domainName: 'test.example.com',
109
+ domainPrefix: 'api',
110
+ requestId: 'request-id',
111
+ routeKey: 'GET /test',
112
+ stage: 'test',
113
+ time: '01/Jan/2024:00:00:00 +0000',
114
+ timeEpoch: 1704067200000,
115
+ http: {
116
+ method: 'GET',
117
+ path: '/test',
118
+ protocol: 'HTTP/1.1',
119
+ sourceIp: '127.0.0.1',
120
+ userAgent: 'test-agent',
121
+ },
122
+ },
123
+ body: undefined,
124
+ pathParameters: undefined,
125
+ isBase64Encoded: false,
126
+ stageVariables: undefined,
127
+ queryStringParameters: undefined,
128
+ cookies: undefined,
129
+ ...overrides,
130
+ };
131
+ }
package/src/logger.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { Logger } from '@geekmidas/logger';
2
+ import { vi } from 'vitest';
3
+
4
+ /**
5
+ * Creates a mock Logger for testing
6
+ */
7
+ export function createMockLogger(): Logger {
8
+ const logger: Logger = {
9
+ debug: vi.fn(),
10
+ info: vi.fn(),
11
+ warn: vi.fn(),
12
+ error: vi.fn(),
13
+ fatal: vi.fn(),
14
+ trace: vi.fn(),
15
+ child: vi.fn(() => logger),
16
+ };
17
+ return logger;
18
+ }
@@ -0,0 +1,21 @@
1
+ import crypto from 'node:crypto';
2
+ import fs from 'node:fs/promises';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { it } from 'vitest';
6
+
7
+ export const itWithDir = it.extend<DirectoryFixtures>({
8
+ // This fixture automatically provides a transaction to each test
9
+ dir: async ({}, use) => {
10
+ const tempDir = os.tmpdir();
11
+ const directoryName = crypto.randomUUID().replace(/-/g, '').toUpperCase();
12
+ const dir = path.join(tempDir, directoryName);
13
+ await fs.mkdir(dir, { recursive: true });
14
+ await use(dir);
15
+ await fs.rm(dir, { recursive: true, force: true });
16
+ },
17
+ });
18
+
19
+ export interface DirectoryFixtures {
20
+ dir: string;
21
+ }
@@ -0,0 +1 @@
1
+ export { itWithDir } from './directory';
package/src/timer.ts ADDED
@@ -0,0 +1,3 @@
1
+ export function waitFor(ms: number) {
2
+ return new Promise((resolve) => setTimeout(resolve, ms));
3
+ }