@geekmidas/testkit 0.0.14 → 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.
- package/dist/{Factory-D7P3bKKb.d.mts → Factory-BZ8uMoXl.d.cts} +3 -2
- package/dist/{Factory-pNV7ZQ7-.d.cts → Factory-Cmr3s3-s.d.mts} +3 -2
- package/dist/Factory-WMhTNZ9S.cjs +2 -1
- package/dist/Factory-WMhTNZ9S.cjs.map +1 -0
- package/dist/Factory-z2m01hMj.mjs +2 -1
- package/dist/Factory-z2m01hMj.mjs.map +1 -0
- package/dist/Factory.d.cts +2 -2
- package/dist/Factory.d.mts +2 -2
- package/dist/KyselyFactory-BcYkC0t2.mjs +2 -1
- package/dist/KyselyFactory-BcYkC0t2.mjs.map +1 -0
- package/dist/KyselyFactory-Cf0o2YxO.cjs +2 -1
- package/dist/KyselyFactory-Cf0o2YxO.cjs.map +1 -0
- package/dist/{KyselyFactory-72P98y5I.d.mts → KyselyFactory-Cx3sezwH.d.mts} +4 -3
- package/dist/{KyselyFactory-DLBrYWxU.d.cts → KyselyFactory-DRQ83r0o.d.cts} +4 -3
- package/dist/KyselyFactory.d.cts +3 -3
- package/dist/KyselyFactory.d.mts +3 -3
- package/dist/ObjectionFactory-8hebmnai.mjs +2 -1
- package/dist/ObjectionFactory-8hebmnai.mjs.map +1 -0
- package/dist/{ObjectionFactory-B40NQWSe.d.mts → ObjectionFactory-C-59Hjwj.d.mts} +4 -3
- package/dist/{ObjectionFactory-D3l1VuyX.d.cts → ObjectionFactory-C4X78k0B.d.cts} +4 -3
- package/dist/ObjectionFactory-CDriunkS.cjs +2 -1
- package/dist/ObjectionFactory-CDriunkS.cjs.map +1 -0
- package/dist/ObjectionFactory.d.cts +3 -3
- package/dist/ObjectionFactory.d.mts +3 -3
- package/dist/{PostgresKyselyMigrator-_6yHZigp.d.mts → PostgresKyselyMigrator-CIx3AFSR.d.mts} +3 -2
- package/dist/PostgresKyselyMigrator-CQ3aUoy_.d.cts +2 -1
- package/dist/PostgresKyselyMigrator-CfytARcA.cjs +2 -1
- package/dist/PostgresKyselyMigrator-CfytARcA.cjs.map +1 -0
- package/dist/{PostgresKyselyMigrator-Bdhl251C.mjs → PostgresKyselyMigrator-upT-hmrz.mjs} +3 -2
- package/dist/PostgresKyselyMigrator-upT-hmrz.mjs.map +1 -0
- package/dist/PostgresKyselyMigrator.d.mts +2 -2
- package/dist/PostgresKyselyMigrator.mjs +2 -2
- package/dist/PostgresMigrator-D5UkK1_K.d.cts +2 -1
- package/dist/PostgresMigrator-DFcNdCvD.cjs +2 -1
- package/dist/PostgresMigrator-DFcNdCvD.cjs.map +1 -0
- package/dist/{PostgresMigrator-BlvuQl7d.d.mts → PostgresMigrator-DQaRxoaY.d.mts} +2 -1
- package/dist/{PostgresMigrator-DxPC_gGu.mjs → PostgresMigrator-DbuJGAVy.mjs} +4 -3
- package/dist/PostgresMigrator-DbuJGAVy.mjs.map +1 -0
- package/dist/PostgresMigrator.d.mts +1 -1
- package/dist/PostgresMigrator.mjs +1 -1
- package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs +2 -1
- package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs.map +1 -0
- package/dist/PostgresObjectionMigrator-CZHHcCOv.d.cts +2 -1
- package/dist/{PostgresObjectionMigrator-G4h5FLvU.mjs → PostgresObjectionMigrator-DPj2pOpX.mjs} +3 -2
- package/dist/PostgresObjectionMigrator-DPj2pOpX.mjs.map +1 -0
- package/dist/{PostgresObjectionMigrator-C69n7vzr.d.mts → PostgresObjectionMigrator-D_hCcrQu.d.mts} +3 -2
- package/dist/PostgresObjectionMigrator.d.mts +2 -2
- package/dist/PostgresObjectionMigrator.mjs +2 -2
- package/dist/{VitestKyselyTransactionIsolator-Dq4Oeh-Y.mjs → VitestKyselyTransactionIsolator-BxjlD1YM.mjs} +3 -4
- package/dist/VitestKyselyTransactionIsolator-BxjlD1YM.mjs.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-CnxpE9cH.d.mts → VitestKyselyTransactionIsolator-COCVfvfr.d.mts} +3 -2
- package/dist/{VitestKyselyTransactionIsolator-Dqy3qNoJ.cjs → VitestKyselyTransactionIsolator-Cst3vFjb.cjs} +3 -4
- package/dist/VitestKyselyTransactionIsolator-Cst3vFjb.cjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator-DYUYVEh9.d.cts +2 -1
- package/dist/VitestKyselyTransactionIsolator.cjs +1 -1
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestKyselyTransactionIsolator.mjs +1 -1
- package/dist/{VitestObjectionTransactionIsolator-DVtJG2F3.mjs → VitestObjectionTransactionIsolator-BU-jXEhz.mjs} +3 -4
- package/dist/VitestObjectionTransactionIsolator-BU-jXEhz.mjs.map +1 -0
- package/dist/VitestObjectionTransactionIsolator-CJ4ds5Qv.d.cts +2 -1
- package/dist/{VitestObjectionTransactionIsolator-LP4B0cqW.cjs → VitestObjectionTransactionIsolator-DzeF4UAq.cjs} +3 -4
- package/dist/VitestObjectionTransactionIsolator-DzeF4UAq.cjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-DIM79dCq.d.mts → VitestObjectionTransactionIsolator-b973r9O1.d.mts} +3 -2
- package/dist/VitestObjectionTransactionIsolator.cjs +1 -1
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator.mjs +1 -1
- package/dist/VitestTransactionIsolator-BQ5FpLtC.cjs +2 -1
- package/dist/VitestTransactionIsolator-BQ5FpLtC.cjs.map +1 -0
- package/dist/{VitestTransactionIsolator-zdyiS_SY.d.mts → VitestTransactionIsolator-CsfJBxcb.d.mts} +2 -1
- package/dist/VitestTransactionIsolator-CskiiJbW.mjs +2 -1
- package/dist/VitestTransactionIsolator-CskiiJbW.mjs.map +1 -0
- package/dist/VitestTransactionIsolator-DdLNODZg.d.cts +2 -1
- package/dist/VitestTransactionIsolator.d.mts +1 -1
- package/dist/aws.cjs +126 -0
- package/dist/aws.cjs.map +1 -0
- package/dist/aws.d.cts +22 -0
- package/dist/aws.d.mts +22 -0
- package/dist/aws.mjs +123 -0
- package/dist/aws.mjs.map +1 -0
- package/dist/directory-B-Ozljzk.mjs +22 -0
- package/dist/directory-B-Ozljzk.mjs.map +1 -0
- package/dist/directory-B4oYx02C.d.mts +12 -0
- package/dist/directory-BUcnztHI.d.cts +12 -0
- package/dist/directory-BVC8g7cX.cjs +28 -0
- package/dist/directory-BVC8g7cX.cjs.map +1 -0
- package/dist/faker-B14IEMIN.cjs +2 -1
- package/dist/faker-B14IEMIN.cjs.map +1 -0
- package/dist/faker-BGKYFoCT.mjs +2 -1
- package/dist/faker-BGKYFoCT.mjs.map +1 -0
- package/dist/{faker-BSH1EMtg.d.cts → faker-Cg76aFNO.d.cts} +4 -3
- package/dist/{faker-C-Iuk_R1.d.mts → faker-DHh7xs4u.d.mts} +4 -3
- package/dist/faker.d.cts +1 -1
- package/dist/faker.d.mts +1 -1
- package/dist/helpers.cjs +48 -2
- package/dist/helpers.cjs.map +1 -0
- package/dist/helpers.d.cts +2 -1
- package/dist/helpers.d.mts +2 -1
- package/dist/helpers.mjs +47 -2
- package/dist/helpers.mjs.map +1 -0
- package/dist/kysely.cjs +66 -3
- package/dist/kysely.cjs.map +1 -0
- package/dist/kysely.d.cts +5 -4
- package/dist/kysely.d.mts +9 -8
- package/dist/kysely.mjs +68 -5
- package/dist/kysely.mjs.map +1 -0
- package/dist/logger.cjs +23 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +11 -0
- package/dist/logger.d.mts +11 -0
- package/dist/logger.mjs +22 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/objection.cjs +81 -3
- package/dist/objection.cjs.map +1 -0
- package/dist/objection.d.cts +5 -4
- package/dist/objection.d.mts +9 -8
- package/dist/objection.mjs +83 -5
- package/dist/objection.mjs.map +1 -0
- package/dist/os/directory.cjs +3 -0
- package/dist/os/directory.d.cts +2 -0
- package/dist/os/directory.d.mts +2 -0
- package/dist/os/directory.mjs +3 -0
- package/dist/os/index.cjs +3 -0
- package/dist/os/index.d.cts +2 -0
- package/dist/os/index.d.mts +2 -0
- package/dist/os/index.mjs +3 -0
- package/dist/timer.cjs +9 -0
- package/dist/timer.cjs.map +1 -0
- package/dist/timer.d.cts +5 -0
- package/dist/timer.d.mts +5 -0
- package/dist/timer.mjs +8 -0
- package/dist/timer.mjs.map +1 -0
- package/package.json +25 -3
- package/src/VitestKyselyTransactionIsolator.ts +2 -2
- package/src/VitestObjectionTransactionIsolator.ts +1 -3
- package/src/aws.ts +131 -0
- package/src/logger.ts +18 -0
- package/src/os/directory.ts +21 -0
- package/src/os/index.ts +1 -0
- package/src/timer.ts +3 -0
- package/dist/__tests__/Factory.spec.cjs +0 -139
- package/dist/__tests__/Factory.spec.d.cts +0 -1
- package/dist/__tests__/Factory.spec.d.mts +0 -1
- package/dist/__tests__/Factory.spec.mjs +0 -138
- package/dist/__tests__/KyselyFactory.spec.cjs +0 -235
- package/dist/__tests__/KyselyFactory.spec.d.cts +0 -1
- package/dist/__tests__/KyselyFactory.spec.d.mts +0 -1
- package/dist/__tests__/KyselyFactory.spec.mjs +0 -234
- package/dist/__tests__/ObjectionFactory.spec.cjs +0 -340
- package/dist/__tests__/ObjectionFactory.spec.d.cts +0 -1
- package/dist/__tests__/ObjectionFactory.spec.d.mts +0 -1
- package/dist/__tests__/ObjectionFactory.spec.mjs +0 -339
- package/dist/__tests__/PostgresKyselyMigrator.spec.cjs +0 -397
- package/dist/__tests__/PostgresKyselyMigrator.spec.d.cts +0 -1
- package/dist/__tests__/PostgresKyselyMigrator.spec.d.mts +0 -1
- package/dist/__tests__/PostgresKyselyMigrator.spec.mjs +0 -396
- package/dist/__tests__/PostgresMigrator.spec.cjs +0 -256
- package/dist/__tests__/PostgresMigrator.spec.d.cts +0 -1
- package/dist/__tests__/PostgresMigrator.spec.d.mts +0 -1
- package/dist/__tests__/PostgresMigrator.spec.mjs +0 -255
- package/dist/__tests__/PostgresObjectionMigrator.spec.cjs +0 -432
- package/dist/__tests__/PostgresObjectionMigrator.spec.d.cts +0 -1
- package/dist/__tests__/PostgresObjectionMigrator.spec.d.mts +0 -1
- package/dist/__tests__/PostgresObjectionMigrator.spec.mjs +0 -431
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.cjs +0 -122
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.cts +0 -1
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.mts +0 -1
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.mjs +0 -121
- package/dist/__tests__/faker.spec.cjs +0 -115
- package/dist/__tests__/faker.spec.d.cts +0 -1
- package/dist/__tests__/faker.spec.d.mts +0 -1
- package/dist/__tests__/faker.spec.mjs +0 -114
- package/dist/__tests__/integration.spec.cjs +0 -282
- package/dist/__tests__/integration.spec.d.cts +0 -1
- package/dist/__tests__/integration.spec.d.mts +0 -1
- package/dist/__tests__/integration.spec.mjs +0 -281
- package/dist/helpers-B4TXg3Wp.mjs +0 -86
- package/dist/helpers-Bf0nXhbu.cjs +0 -116
- package/dist/helpers-BuPmgzyQ.mjs +0 -47
- package/dist/helpers-nEUtQ7eo.cjs +0 -53
- package/dist/kysely-BsDbvw3r.mjs +0 -67
- package/dist/kysely-CP1iJMvq.cjs +0 -72
- package/dist/objection-BEPk9h-g.mjs +0 -82
- package/dist/objection-Di7JSist.cjs +0 -87
package/dist/aws.mjs
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
//#region src/aws.ts
|
|
4
|
+
/**
|
|
5
|
+
* Shared test utilities for AWS Lambda adapter testing
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Creates a mock AWS Lambda Context for testing
|
|
9
|
+
*/
|
|
10
|
+
function createMockContext() {
|
|
11
|
+
return {
|
|
12
|
+
awsRequestId: "test-request-id",
|
|
13
|
+
callbackWaitsForEmptyEventLoop: false,
|
|
14
|
+
functionName: "test-function",
|
|
15
|
+
functionVersion: "1",
|
|
16
|
+
invokedFunctionArn: "arn:aws:lambda:us-east-1:123456789012:function:test-function",
|
|
17
|
+
memoryLimitInMB: "128",
|
|
18
|
+
logGroupName: "/aws/lambda/test-function",
|
|
19
|
+
logStreamName: "2024/01/01/[$LATEST]abcdef123456",
|
|
20
|
+
getRemainingTimeInMillis: () => 5e3,
|
|
21
|
+
done: vi.fn(),
|
|
22
|
+
fail: vi.fn(),
|
|
23
|
+
succeed: vi.fn()
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates a mock AWS API Gateway V1 (REST API) event for testing
|
|
28
|
+
*/
|
|
29
|
+
function createMockV1Event(overrides = {}) {
|
|
30
|
+
return {
|
|
31
|
+
body: null,
|
|
32
|
+
headers: {
|
|
33
|
+
"content-type": "application/json",
|
|
34
|
+
"user-agent": "test-agent",
|
|
35
|
+
host: "test.example.com"
|
|
36
|
+
},
|
|
37
|
+
multiValueHeaders: {},
|
|
38
|
+
httpMethod: "GET",
|
|
39
|
+
isBase64Encoded: false,
|
|
40
|
+
path: "/test",
|
|
41
|
+
pathParameters: null,
|
|
42
|
+
queryStringParameters: null,
|
|
43
|
+
multiValueQueryStringParameters: null,
|
|
44
|
+
stageVariables: null,
|
|
45
|
+
requestContext: {
|
|
46
|
+
accountId: "123456789012",
|
|
47
|
+
apiId: "api-id",
|
|
48
|
+
authorizer: null,
|
|
49
|
+
protocol: "HTTP/1.1",
|
|
50
|
+
httpMethod: "GET",
|
|
51
|
+
path: "/test",
|
|
52
|
+
stage: "test",
|
|
53
|
+
requestId: "request-id",
|
|
54
|
+
requestTimeEpoch: 17040672e5,
|
|
55
|
+
resourceId: "resource-id",
|
|
56
|
+
resourcePath: "/test",
|
|
57
|
+
identity: {
|
|
58
|
+
accessKey: null,
|
|
59
|
+
accountId: null,
|
|
60
|
+
apiKey: null,
|
|
61
|
+
apiKeyId: null,
|
|
62
|
+
caller: null,
|
|
63
|
+
cognitoAuthenticationProvider: null,
|
|
64
|
+
cognitoAuthenticationType: null,
|
|
65
|
+
cognitoIdentityId: null,
|
|
66
|
+
cognitoIdentityPoolId: null,
|
|
67
|
+
principalOrgId: null,
|
|
68
|
+
sourceIp: "127.0.0.1",
|
|
69
|
+
user: null,
|
|
70
|
+
userAgent: "test-agent",
|
|
71
|
+
userArn: null,
|
|
72
|
+
clientCert: null
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
resource: "/test",
|
|
76
|
+
...overrides
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Creates a mock AWS API Gateway V2 (HTTP API) event for testing
|
|
81
|
+
*/
|
|
82
|
+
function createMockV2Event(overrides = {}) {
|
|
83
|
+
return {
|
|
84
|
+
version: "2.0",
|
|
85
|
+
routeKey: "GET /test",
|
|
86
|
+
rawPath: "/test",
|
|
87
|
+
rawQueryString: "",
|
|
88
|
+
headers: {
|
|
89
|
+
"content-type": "application/json",
|
|
90
|
+
"user-agent": "test-agent",
|
|
91
|
+
host: "test.example.com"
|
|
92
|
+
},
|
|
93
|
+
requestContext: {
|
|
94
|
+
accountId: "123456789012",
|
|
95
|
+
apiId: "api-id",
|
|
96
|
+
domainName: "test.example.com",
|
|
97
|
+
domainPrefix: "api",
|
|
98
|
+
requestId: "request-id",
|
|
99
|
+
routeKey: "GET /test",
|
|
100
|
+
stage: "test",
|
|
101
|
+
time: "01/Jan/2024:00:00:00 +0000",
|
|
102
|
+
timeEpoch: 17040672e5,
|
|
103
|
+
http: {
|
|
104
|
+
method: "GET",
|
|
105
|
+
path: "/test",
|
|
106
|
+
protocol: "HTTP/1.1",
|
|
107
|
+
sourceIp: "127.0.0.1",
|
|
108
|
+
userAgent: "test-agent"
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
body: void 0,
|
|
112
|
+
pathParameters: void 0,
|
|
113
|
+
isBase64Encoded: false,
|
|
114
|
+
stageVariables: void 0,
|
|
115
|
+
queryStringParameters: void 0,
|
|
116
|
+
cookies: void 0,
|
|
117
|
+
...overrides
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
//#endregion
|
|
122
|
+
export { createMockContext, createMockV1Event, createMockV2Event };
|
|
123
|
+
//# sourceMappingURL=aws.mjs.map
|
package/dist/aws.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws.mjs","names":["overrides: Partial<APIGatewayProxyEvent>","overrides: Partial<APIGatewayProxyEventV2>"],"sources":["../src/aws.ts"],"sourcesContent":["import type {\n APIGatewayProxyEvent,\n APIGatewayProxyEventV2,\n Context,\n} from 'aws-lambda';\nimport { vi } from 'vitest';\n\n/**\n * Shared test utilities for AWS Lambda adapter testing\n */\n\n/**\n * Creates a mock AWS Lambda Context for testing\n */\nexport function createMockContext(): Context {\n return {\n awsRequestId: 'test-request-id',\n callbackWaitsForEmptyEventLoop: false,\n functionName: 'test-function',\n functionVersion: '1',\n invokedFunctionArn:\n 'arn:aws:lambda:us-east-1:123456789012:function:test-function',\n memoryLimitInMB: '128',\n logGroupName: '/aws/lambda/test-function',\n logStreamName: '2024/01/01/[$LATEST]abcdef123456',\n getRemainingTimeInMillis: () => 5000,\n done: vi.fn(),\n fail: vi.fn(),\n succeed: vi.fn(),\n };\n}\n\n/**\n * Creates a mock AWS API Gateway V1 (REST API) event for testing\n */\nexport function createMockV1Event(\n overrides: Partial<APIGatewayProxyEvent> = {},\n): APIGatewayProxyEvent {\n return {\n body: null,\n headers: {\n 'content-type': 'application/json',\n 'user-agent': 'test-agent',\n host: 'test.example.com',\n },\n multiValueHeaders: {},\n httpMethod: 'GET',\n isBase64Encoded: false,\n path: '/test',\n pathParameters: null,\n queryStringParameters: null,\n multiValueQueryStringParameters: null,\n stageVariables: null,\n requestContext: {\n accountId: '123456789012',\n apiId: 'api-id',\n authorizer: null,\n protocol: 'HTTP/1.1',\n httpMethod: 'GET',\n path: '/test',\n stage: 'test',\n requestId: 'request-id',\n requestTimeEpoch: 1704067200000,\n resourceId: 'resource-id',\n resourcePath: '/test',\n identity: {\n accessKey: null,\n accountId: null,\n apiKey: null,\n apiKeyId: null,\n caller: null,\n cognitoAuthenticationProvider: null,\n cognitoAuthenticationType: null,\n cognitoIdentityId: null,\n cognitoIdentityPoolId: null,\n principalOrgId: null,\n sourceIp: '127.0.0.1',\n user: null,\n userAgent: 'test-agent',\n userArn: null,\n clientCert: null,\n },\n },\n resource: '/test',\n ...overrides,\n };\n}\n\n/**\n * Creates a mock AWS API Gateway V2 (HTTP API) event for testing\n */\nexport function createMockV2Event(\n overrides: Partial<APIGatewayProxyEventV2> = {},\n): APIGatewayProxyEventV2 {\n return {\n version: '2.0',\n routeKey: 'GET /test',\n rawPath: '/test',\n rawQueryString: '',\n headers: {\n 'content-type': 'application/json',\n 'user-agent': 'test-agent',\n host: 'test.example.com',\n },\n requestContext: {\n accountId: '123456789012',\n apiId: 'api-id',\n domainName: 'test.example.com',\n domainPrefix: 'api',\n requestId: 'request-id',\n routeKey: 'GET /test',\n stage: 'test',\n time: '01/Jan/2024:00:00:00 +0000',\n timeEpoch: 1704067200000,\n http: {\n method: 'GET',\n path: '/test',\n protocol: 'HTTP/1.1',\n sourceIp: '127.0.0.1',\n userAgent: 'test-agent',\n },\n },\n body: undefined,\n pathParameters: undefined,\n isBase64Encoded: false,\n stageVariables: undefined,\n queryStringParameters: undefined,\n cookies: undefined,\n ...overrides,\n };\n}\n"],"mappings":";;;;;;;;;AAcA,SAAgB,oBAA6B;AAC3C,QAAO;EACL,cAAc;EACd,gCAAgC;EAChC,cAAc;EACd,iBAAiB;EACjB,oBACE;EACF,iBAAiB;EACjB,cAAc;EACd,eAAe;EACf,0BAA0B,MAAM;EAChC,MAAM,GAAG,IAAI;EACb,MAAM,GAAG,IAAI;EACb,SAAS,GAAG,IAAI;CACjB;AACF;;;;AAKD,SAAgB,kBACdA,YAA2C,CAAE,GACvB;AACtB,QAAO;EACL,MAAM;EACN,SAAS;GACP,gBAAgB;GAChB,cAAc;GACd,MAAM;EACP;EACD,mBAAmB,CAAE;EACrB,YAAY;EACZ,iBAAiB;EACjB,MAAM;EACN,gBAAgB;EAChB,uBAAuB;EACvB,iCAAiC;EACjC,gBAAgB;EAChB,gBAAgB;GACd,WAAW;GACX,OAAO;GACP,YAAY;GACZ,UAAU;GACV,YAAY;GACZ,MAAM;GACN,OAAO;GACP,WAAW;GACX,kBAAkB;GAClB,YAAY;GACZ,cAAc;GACd,UAAU;IACR,WAAW;IACX,WAAW;IACX,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,+BAA+B;IAC/B,2BAA2B;IAC3B,mBAAmB;IACnB,uBAAuB;IACvB,gBAAgB;IAChB,UAAU;IACV,MAAM;IACN,WAAW;IACX,SAAS;IACT,YAAY;GACb;EACF;EACD,UAAU;EACV,GAAG;CACJ;AACF;;;;AAKD,SAAgB,kBACdC,YAA6C,CAAE,GACvB;AACxB,QAAO;EACL,SAAS;EACT,UAAU;EACV,SAAS;EACT,gBAAgB;EAChB,SAAS;GACP,gBAAgB;GAChB,cAAc;GACd,MAAM;EACP;EACD,gBAAgB;GACd,WAAW;GACX,OAAO;GACP,YAAY;GACZ,cAAc;GACd,WAAW;GACX,UAAU;GACV,OAAO;GACP,MAAM;GACN,WAAW;GACX,MAAM;IACJ,QAAQ;IACR,MAAM;IACN,UAAU;IACV,UAAU;IACV,WAAW;GACZ;EACF;EACD;EACA;EACA,iBAAiB;EACjB;EACA;EACA;EACA,GAAG;CACJ;AACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { it } from "vitest";
|
|
2
|
+
import crypto from "node:crypto";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
//#region src/os/directory.ts
|
|
8
|
+
const itWithDir = it.extend({ dir: async ({}, use) => {
|
|
9
|
+
const tempDir = os.tmpdir();
|
|
10
|
+
const directoryName = crypto.randomUUID().replace(/-/g, "").toUpperCase();
|
|
11
|
+
const dir = path.join(tempDir, directoryName);
|
|
12
|
+
await fs.mkdir(dir, { recursive: true });
|
|
13
|
+
await use(dir);
|
|
14
|
+
await fs.rm(dir, {
|
|
15
|
+
recursive: true,
|
|
16
|
+
force: true
|
|
17
|
+
});
|
|
18
|
+
} });
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { itWithDir };
|
|
22
|
+
//# sourceMappingURL=directory-B-Ozljzk.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory-B-Ozljzk.mjs","names":[],"sources":["../src/os/directory.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs/promises';\nimport os from 'node:os';\nimport path from 'node:path';\nimport { it } from 'vitest';\n\nexport const itWithDir = it.extend<DirectoryFixtures>({\n // This fixture automatically provides a transaction to each test\n dir: async ({}, use) => {\n const tempDir = os.tmpdir();\n const directoryName = crypto.randomUUID().replace(/-/g, '').toUpperCase();\n const dir = path.join(tempDir, directoryName);\n await fs.mkdir(dir, { recursive: true });\n await use(dir);\n await fs.rm(dir, { recursive: true, force: true });\n },\n});\n\nexport interface DirectoryFixtures {\n dir: string;\n}\n"],"mappings":";;;;;;;AAMA,MAAa,YAAY,GAAG,OAA0B,EAEpD,KAAK,OAAO,EAAE,EAAE,QAAQ;CACtB,MAAM,UAAU,GAAG,QAAQ;CAC3B,MAAM,gBAAgB,OAAO,YAAY,CAAC,QAAQ,MAAM,GAAG,CAAC,aAAa;CACzE,MAAM,MAAM,KAAK,KAAK,SAAS,cAAc;AAC7C,OAAM,GAAG,MAAM,KAAK,EAAE,WAAW,KAAM,EAAC;AACxC,OAAM,IAAI,IAAI;AACd,OAAM,GAAG,GAAG,KAAK;EAAE,WAAW;EAAM,OAAO;CAAM,EAAC;AACnD,EACF,EAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as vitest0 from "vitest";
|
|
2
|
+
|
|
3
|
+
//#region src/os/directory.d.ts
|
|
4
|
+
declare const itWithDir: vitest0.TestAPI<{
|
|
5
|
+
dir: string;
|
|
6
|
+
}>;
|
|
7
|
+
interface DirectoryFixtures {
|
|
8
|
+
dir: string;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { DirectoryFixtures, itWithDir };
|
|
12
|
+
//# sourceMappingURL=directory-B4oYx02C.d.mts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as vitest0 from "vitest";
|
|
2
|
+
|
|
3
|
+
//#region src/os/directory.d.ts
|
|
4
|
+
declare const itWithDir: vitest0.TestAPI<{
|
|
5
|
+
dir: string;
|
|
6
|
+
}>;
|
|
7
|
+
interface DirectoryFixtures {
|
|
8
|
+
dir: string;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { DirectoryFixtures, itWithDir };
|
|
12
|
+
//# sourceMappingURL=directory-BUcnztHI.d.cts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const vitest = require_chunk.__toESM(require("vitest"));
|
|
3
|
+
const node_crypto = require_chunk.__toESM(require("node:crypto"));
|
|
4
|
+
const node_fs_promises = require_chunk.__toESM(require("node:fs/promises"));
|
|
5
|
+
const node_os = require_chunk.__toESM(require("node:os"));
|
|
6
|
+
const node_path = require_chunk.__toESM(require("node:path"));
|
|
7
|
+
|
|
8
|
+
//#region src/os/directory.ts
|
|
9
|
+
const itWithDir = vitest.it.extend({ dir: async ({}, use) => {
|
|
10
|
+
const tempDir = node_os.default.tmpdir();
|
|
11
|
+
const directoryName = node_crypto.default.randomUUID().replace(/-/g, "").toUpperCase();
|
|
12
|
+
const dir = node_path.default.join(tempDir, directoryName);
|
|
13
|
+
await node_fs_promises.default.mkdir(dir, { recursive: true });
|
|
14
|
+
await use(dir);
|
|
15
|
+
await node_fs_promises.default.rm(dir, {
|
|
16
|
+
recursive: true,
|
|
17
|
+
force: true
|
|
18
|
+
});
|
|
19
|
+
} });
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
Object.defineProperty(exports, 'itWithDir', {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () {
|
|
25
|
+
return itWithDir;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=directory-BVC8g7cX.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory-BVC8g7cX.cjs","names":[],"sources":["../src/os/directory.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs/promises';\nimport os from 'node:os';\nimport path from 'node:path';\nimport { it } from 'vitest';\n\nexport const itWithDir = it.extend<DirectoryFixtures>({\n // This fixture automatically provides a transaction to each test\n dir: async ({}, use) => {\n const tempDir = os.tmpdir();\n const directoryName = crypto.randomUUID().replace(/-/g, '').toUpperCase();\n const dir = path.join(tempDir, directoryName);\n await fs.mkdir(dir, { recursive: true });\n await use(dir);\n await fs.rm(dir, { recursive: true, force: true });\n },\n});\n\nexport interface DirectoryFixtures {\n dir: string;\n}\n"],"mappings":";;;;;;;;AAMA,MAAa,YAAY,UAAG,OAA0B,EAEpD,KAAK,OAAO,EAAE,EAAE,QAAQ;CACtB,MAAM,UAAU,gBAAG,QAAQ;CAC3B,MAAM,gBAAgB,oBAAO,YAAY,CAAC,QAAQ,MAAM,GAAG,CAAC,aAAa;CACzE,MAAM,MAAM,kBAAK,KAAK,SAAS,cAAc;AAC7C,OAAM,yBAAG,MAAM,KAAK,EAAE,WAAW,KAAM,EAAC;AACxC,OAAM,IAAI,IAAI;AACd,OAAM,yBAAG,GAAG,KAAK;EAAE,WAAW;EAAM,OAAO;CAAM,EAAC;AACnD,EACF,EAAC"}
|
package/dist/faker-B14IEMIN.cjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faker-B14IEMIN.cjs","names":["suffix?: string","center: Coordinate","radius: number","minRadiusMeters: number","maxRadiusMeters: number","baseFaker"],"sources":["../src/faker.ts"],"sourcesContent":["import { faker as baseFaker } from '@faker-js/faker';\n\n// NOTE: This is a simple way to extend `faker` with additional methods\n\n/**\n * Atomic counter implementation for thread-safe sequence generation.\n * Provides a clean abstraction for generating sequential numbers in tests.\n * While JavaScript is single-threaded, this class makes the intent explicit.\n *\n * @example\n * ```typescript\n * const counter = new AtomicCounter(100);\n * console.log(counter.increment()); // 101\n * console.log(counter.increment()); // 102\n * console.log(counter.get()); // 102\n * counter.reset(200);\n * console.log(counter.increment()); // 201\n * ```\n */\nclass AtomicCounter {\n /**\n * The current counter value.\n * @private\n */\n private value: number;\n\n /**\n * Creates a new atomic counter.\n * @param initialValue - The starting value (default: 0)\n */\n constructor(initialValue = 0) {\n this.value = initialValue;\n }\n\n /**\n * Increments the counter and returns the new value.\n * @returns The incremented value\n */\n increment(): number {\n // In Node.js, JavaScript is single-threaded within the event loop,\n // so this operation is already atomic. However, this class provides\n // a cleaner abstraction and makes the intent explicit.\n return ++this.value;\n }\n\n /**\n * Gets the current counter value without incrementing.\n * @returns The current value\n */\n get(): number {\n return this.value;\n }\n\n /**\n * Resets the counter to a specific value.\n * @param value - The new value (default: 0)\n */\n reset(value = 0): void {\n this.value = value;\n }\n}\n\n/**\n * Generates random timestamp fields for database records.\n * Creates a createdAt date in the past and an updatedAt date between creation and now.\n * Milliseconds are set to 0 for cleaner database storage.\n *\n * @returns Object with createdAt and updatedAt Date fields\n *\n * @example\n * ```typescript\n * const { createdAt, updatedAt } = timestamps();\n * console.log(createdAt); // 2023-05-15T10:30:00.000Z\n * console.log(updatedAt); // 2023-11-20T14:45:00.000Z\n *\n * // Use in factory\n * const user = {\n * name: 'John Doe',\n * ...timestamps()\n * };\n * ```\n */\nexport function timestamps(): Timestamps {\n const createdAt = faker.date.past();\n const updatedAt = faker.date.between({\n from: createdAt,\n to: new Date(),\n });\n\n createdAt.setMilliseconds(0);\n updatedAt.setMilliseconds(0);\n\n return { createdAt, updatedAt };\n}\n\n/**\n * Generates a reverse domain name identifier.\n * Useful for creating unique identifiers that follow domain naming conventions.\n *\n * @param suffix - Optional suffix to append to the identifier\n * @returns A reverse domain name string (e.g., \"com.example.feature123\")\n *\n * @example\n * ```typescript\n * console.log(identifier()); // \"com.example.widget1\"\n * console.log(identifier('user')); // \"org.acme.user\"\n * console.log(identifier('api')); // \"net.demo.api\"\n * ```\n */\nexport function identifier(suffix?: string): string {\n return [\n faker.internet.domainSuffix(),\n faker.internet.domainWord(),\n suffix ? suffix : faker.internet.domainWord() + sequence('identifier'),\n ].join('.');\n}\n\n/**\n * Storage for named sequence counters.\n * Each sequence maintains its own independent counter.\n * @private\n */\nconst sequences = new Map<string, AtomicCounter>();\n\n/**\n * Generates sequential numbers for a named sequence.\n * Useful for creating unique IDs or numbered test data.\n * Each named sequence maintains its own counter.\n *\n * @param name - The sequence name (default: 'default')\n * @returns The next number in the sequence\n *\n * @example\n * ```typescript\n * console.log(sequence()); // 1\n * console.log(sequence()); // 2\n * console.log(sequence('user')); // 1\n * console.log(sequence('user')); // 2\n * console.log(sequence()); // 3\n *\n * // Use in factories\n * const email = `user${sequence('email')}@example.com`;\n * ```\n */\nexport function sequence(name = 'default'): number {\n if (!sequences.has(name)) {\n sequences.set(name, new AtomicCounter());\n }\n\n const counter = sequences.get(name) as AtomicCounter;\n return counter.increment();\n}\n\n/**\n * Resets a named sequence counter to a specific value.\n * Useful for resetting sequences between test suites.\n *\n * @param name - The sequence name to reset (default: 'default')\n * @param value - The new starting value (default: 0)\n *\n * @example\n * ```typescript\n * sequence('user'); // 1\n * sequence('user'); // 2\n * resetSequence('user');\n * sequence('user'); // 1\n *\n * resetSequence('order', 1000);\n * sequence('order'); // 1001\n * ```\n */\nexport function resetSequence(name = 'default', value = 0): void {\n if (sequences.has(name)) {\n const counter = sequences.get(name) as AtomicCounter;\n counter.reset(value);\n } else {\n sequences.set(name, new AtomicCounter(value));\n }\n}\n\n/**\n * Resets all sequence counters.\n * Useful for cleaning up between test suites to ensure predictable sequences.\n *\n * @example\n * ```typescript\n * // In test setup\n * beforeEach(() => {\n * resetAllSequences();\n * });\n *\n * it('starts sequences from 1', () => {\n * expect(sequence()).toBe(1);\n * expect(sequence('user')).toBe(1);\n * });\n * ```\n */\nexport function resetAllSequences(): void {\n sequences.clear();\n}\n\n/**\n * Generates a random price as a number.\n * Converts faker's string price to a numeric value.\n *\n * @returns A random price number\n *\n * @example\n * ```typescript\n * const productPrice = price(); // 29.99\n * const total = price() * quantity; // Numeric calculation\n * ```\n */\nfunction price(): number {\n return +faker.commerce.price();\n}\n\ntype Coordinate = {\n lat: number;\n lng: number;\n};\n\nexport function coordinateInRadius(\n center: Coordinate,\n radius: number,\n): Coordinate {\n // Earth's radius in meters\n const earth = 6378137;\n // Convert radius from meters to degrees\n const d = radius / earth;\n\n // Random bearing and distance\n const theta = 2 * Math.PI * Math.random();\n const r = d * Math.sqrt(Math.random());\n\n const lat1 = (center.lat * Math.PI) / 180;\n const lng1 = (center.lng * Math.PI) / 180;\n\n const lat2 = Math.asin(\n Math.sin(lat1) * Math.cos(r) +\n Math.cos(lat1) * Math.sin(r) * Math.cos(theta),\n );\n const lng2 =\n lng1 +\n Math.atan2(\n Math.sin(theta) * Math.sin(r) * Math.cos(lat1),\n Math.cos(r) - Math.sin(lat1) * Math.sin(lat2),\n );\n\n return {\n lat: (lat2 * 180) / Math.PI,\n lng: (lng2 * 180) / Math.PI,\n };\n}\n\nfunction coordinateOutsideRadius(\n center: Coordinate,\n minRadiusMeters: number,\n maxRadiusMeters: number,\n): Coordinate {\n // Earth's radius in meters\n const earth = 6378137;\n\n // Convert radii from meters to radians\n const minD = minRadiusMeters / earth;\n const maxD = maxRadiusMeters / earth;\n\n // Random bearing\n const theta = 2 * Math.PI * Math.random();\n\n // Random distance in annular ring (uniform distribution by area)\n // For uniform distribution in annulus: r = sqrt(r_min² + (r_max² - r_min²) * random)\n const r = Math.sqrt(\n minD * minD + (maxD * maxD - minD * minD) * Math.random(),\n );\n\n const lat1 = (center.lat * Math.PI) / 180;\n const lng1 = (center.lng * Math.PI) / 180;\n\n const lat2 = Math.asin(\n Math.sin(lat1) * Math.cos(r) +\n Math.cos(lat1) * Math.sin(r) * Math.cos(theta),\n );\n const lng2 =\n lng1 +\n Math.atan2(\n Math.sin(theta) * Math.sin(r) * Math.cos(lat1),\n Math.cos(r) - Math.sin(lat1) * Math.sin(lat2),\n );\n\n // Normalize longitude to [-180, 180]\n const normalizedLng = (((lng2 * 180) / Math.PI + 540) % 360) - 180;\n\n return {\n lat: (lat2 * 180) / Math.PI,\n lng: normalizedLng,\n };\n}\n\n/**\n * Enhanced faker instance with additional utility methods for testing.\n * Extends @faker-js/faker with custom methods for common test data generation patterns.\n *\n * @example\n * ```typescript\n * import { faker } from '@geekmidas/testkit';\n *\n * // Use standard faker methods\n * const name = faker.person.fullName();\n * const email = faker.internet.email();\n *\n * // Use custom extensions\n * const { createdAt, updatedAt } = faker.timestamps();\n * const id = faker.identifier('user');\n * const orderNumber = faker.sequence('order');\n * const productPrice = faker.price();\n * ```\n */\nexport const faker = Object.freeze(\n Object.assign({}, baseFaker, {\n timestamps,\n identifier,\n sequence,\n resetSequence,\n resetAllSequences,\n price,\n coordinates: {\n within: coordinateInRadius,\n outside: coordinateOutsideRadius,\n },\n }),\n);\n\n/**\n * Type definition for timestamp fields.\n * Used by the timestamps() function to generate date fields.\n */\nexport type Timestamps = {\n /** The creation date */\n createdAt: Date;\n /** The last update date */\n updatedAt: Date;\n};\n\n/**\n * Type definition for the enhanced faker factory.\n * Includes all standard faker methods plus custom extensions.\n */\nexport type FakerFactory = typeof faker;\n"],"mappings":"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"}
|
package/dist/faker-BGKYFoCT.mjs
CHANGED
|
@@ -258,4 +258,5 @@ const faker$1 = Object.freeze(Object.assign({}, faker, {
|
|
|
258
258
|
}));
|
|
259
259
|
|
|
260
260
|
//#endregion
|
|
261
|
-
export { coordinateInRadius, faker$1 as faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
|
261
|
+
export { coordinateInRadius, faker$1 as faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
|
262
|
+
//# sourceMappingURL=faker-BGKYFoCT.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faker-BGKYFoCT.mjs","names":["suffix?: string","center: Coordinate","radius: number","minRadiusMeters: number","maxRadiusMeters: number","faker","baseFaker"],"sources":["../src/faker.ts"],"sourcesContent":["import { faker as baseFaker } from '@faker-js/faker';\n\n// NOTE: This is a simple way to extend `faker` with additional methods\n\n/**\n * Atomic counter implementation for thread-safe sequence generation.\n * Provides a clean abstraction for generating sequential numbers in tests.\n * While JavaScript is single-threaded, this class makes the intent explicit.\n *\n * @example\n * ```typescript\n * const counter = new AtomicCounter(100);\n * console.log(counter.increment()); // 101\n * console.log(counter.increment()); // 102\n * console.log(counter.get()); // 102\n * counter.reset(200);\n * console.log(counter.increment()); // 201\n * ```\n */\nclass AtomicCounter {\n /**\n * The current counter value.\n * @private\n */\n private value: number;\n\n /**\n * Creates a new atomic counter.\n * @param initialValue - The starting value (default: 0)\n */\n constructor(initialValue = 0) {\n this.value = initialValue;\n }\n\n /**\n * Increments the counter and returns the new value.\n * @returns The incremented value\n */\n increment(): number {\n // In Node.js, JavaScript is single-threaded within the event loop,\n // so this operation is already atomic. However, this class provides\n // a cleaner abstraction and makes the intent explicit.\n return ++this.value;\n }\n\n /**\n * Gets the current counter value without incrementing.\n * @returns The current value\n */\n get(): number {\n return this.value;\n }\n\n /**\n * Resets the counter to a specific value.\n * @param value - The new value (default: 0)\n */\n reset(value = 0): void {\n this.value = value;\n }\n}\n\n/**\n * Generates random timestamp fields for database records.\n * Creates a createdAt date in the past and an updatedAt date between creation and now.\n * Milliseconds are set to 0 for cleaner database storage.\n *\n * @returns Object with createdAt and updatedAt Date fields\n *\n * @example\n * ```typescript\n * const { createdAt, updatedAt } = timestamps();\n * console.log(createdAt); // 2023-05-15T10:30:00.000Z\n * console.log(updatedAt); // 2023-11-20T14:45:00.000Z\n *\n * // Use in factory\n * const user = {\n * name: 'John Doe',\n * ...timestamps()\n * };\n * ```\n */\nexport function timestamps(): Timestamps {\n const createdAt = faker.date.past();\n const updatedAt = faker.date.between({\n from: createdAt,\n to: new Date(),\n });\n\n createdAt.setMilliseconds(0);\n updatedAt.setMilliseconds(0);\n\n return { createdAt, updatedAt };\n}\n\n/**\n * Generates a reverse domain name identifier.\n * Useful for creating unique identifiers that follow domain naming conventions.\n *\n * @param suffix - Optional suffix to append to the identifier\n * @returns A reverse domain name string (e.g., \"com.example.feature123\")\n *\n * @example\n * ```typescript\n * console.log(identifier()); // \"com.example.widget1\"\n * console.log(identifier('user')); // \"org.acme.user\"\n * console.log(identifier('api')); // \"net.demo.api\"\n * ```\n */\nexport function identifier(suffix?: string): string {\n return [\n faker.internet.domainSuffix(),\n faker.internet.domainWord(),\n suffix ? suffix : faker.internet.domainWord() + sequence('identifier'),\n ].join('.');\n}\n\n/**\n * Storage for named sequence counters.\n * Each sequence maintains its own independent counter.\n * @private\n */\nconst sequences = new Map<string, AtomicCounter>();\n\n/**\n * Generates sequential numbers for a named sequence.\n * Useful for creating unique IDs or numbered test data.\n * Each named sequence maintains its own counter.\n *\n * @param name - The sequence name (default: 'default')\n * @returns The next number in the sequence\n *\n * @example\n * ```typescript\n * console.log(sequence()); // 1\n * console.log(sequence()); // 2\n * console.log(sequence('user')); // 1\n * console.log(sequence('user')); // 2\n * console.log(sequence()); // 3\n *\n * // Use in factories\n * const email = `user${sequence('email')}@example.com`;\n * ```\n */\nexport function sequence(name = 'default'): number {\n if (!sequences.has(name)) {\n sequences.set(name, new AtomicCounter());\n }\n\n const counter = sequences.get(name) as AtomicCounter;\n return counter.increment();\n}\n\n/**\n * Resets a named sequence counter to a specific value.\n * Useful for resetting sequences between test suites.\n *\n * @param name - The sequence name to reset (default: 'default')\n * @param value - The new starting value (default: 0)\n *\n * @example\n * ```typescript\n * sequence('user'); // 1\n * sequence('user'); // 2\n * resetSequence('user');\n * sequence('user'); // 1\n *\n * resetSequence('order', 1000);\n * sequence('order'); // 1001\n * ```\n */\nexport function resetSequence(name = 'default', value = 0): void {\n if (sequences.has(name)) {\n const counter = sequences.get(name) as AtomicCounter;\n counter.reset(value);\n } else {\n sequences.set(name, new AtomicCounter(value));\n }\n}\n\n/**\n * Resets all sequence counters.\n * Useful for cleaning up between test suites to ensure predictable sequences.\n *\n * @example\n * ```typescript\n * // In test setup\n * beforeEach(() => {\n * resetAllSequences();\n * });\n *\n * it('starts sequences from 1', () => {\n * expect(sequence()).toBe(1);\n * expect(sequence('user')).toBe(1);\n * });\n * ```\n */\nexport function resetAllSequences(): void {\n sequences.clear();\n}\n\n/**\n * Generates a random price as a number.\n * Converts faker's string price to a numeric value.\n *\n * @returns A random price number\n *\n * @example\n * ```typescript\n * const productPrice = price(); // 29.99\n * const total = price() * quantity; // Numeric calculation\n * ```\n */\nfunction price(): number {\n return +faker.commerce.price();\n}\n\ntype Coordinate = {\n lat: number;\n lng: number;\n};\n\nexport function coordinateInRadius(\n center: Coordinate,\n radius: number,\n): Coordinate {\n // Earth's radius in meters\n const earth = 6378137;\n // Convert radius from meters to degrees\n const d = radius / earth;\n\n // Random bearing and distance\n const theta = 2 * Math.PI * Math.random();\n const r = d * Math.sqrt(Math.random());\n\n const lat1 = (center.lat * Math.PI) / 180;\n const lng1 = (center.lng * Math.PI) / 180;\n\n const lat2 = Math.asin(\n Math.sin(lat1) * Math.cos(r) +\n Math.cos(lat1) * Math.sin(r) * Math.cos(theta),\n );\n const lng2 =\n lng1 +\n Math.atan2(\n Math.sin(theta) * Math.sin(r) * Math.cos(lat1),\n Math.cos(r) - Math.sin(lat1) * Math.sin(lat2),\n );\n\n return {\n lat: (lat2 * 180) / Math.PI,\n lng: (lng2 * 180) / Math.PI,\n };\n}\n\nfunction coordinateOutsideRadius(\n center: Coordinate,\n minRadiusMeters: number,\n maxRadiusMeters: number,\n): Coordinate {\n // Earth's radius in meters\n const earth = 6378137;\n\n // Convert radii from meters to radians\n const minD = minRadiusMeters / earth;\n const maxD = maxRadiusMeters / earth;\n\n // Random bearing\n const theta = 2 * Math.PI * Math.random();\n\n // Random distance in annular ring (uniform distribution by area)\n // For uniform distribution in annulus: r = sqrt(r_min² + (r_max² - r_min²) * random)\n const r = Math.sqrt(\n minD * minD + (maxD * maxD - minD * minD) * Math.random(),\n );\n\n const lat1 = (center.lat * Math.PI) / 180;\n const lng1 = (center.lng * Math.PI) / 180;\n\n const lat2 = Math.asin(\n Math.sin(lat1) * Math.cos(r) +\n Math.cos(lat1) * Math.sin(r) * Math.cos(theta),\n );\n const lng2 =\n lng1 +\n Math.atan2(\n Math.sin(theta) * Math.sin(r) * Math.cos(lat1),\n Math.cos(r) - Math.sin(lat1) * Math.sin(lat2),\n );\n\n // Normalize longitude to [-180, 180]\n const normalizedLng = (((lng2 * 180) / Math.PI + 540) % 360) - 180;\n\n return {\n lat: (lat2 * 180) / Math.PI,\n lng: normalizedLng,\n };\n}\n\n/**\n * Enhanced faker instance with additional utility methods for testing.\n * Extends @faker-js/faker with custom methods for common test data generation patterns.\n *\n * @example\n * ```typescript\n * import { faker } from '@geekmidas/testkit';\n *\n * // Use standard faker methods\n * const name = faker.person.fullName();\n * const email = faker.internet.email();\n *\n * // Use custom extensions\n * const { createdAt, updatedAt } = faker.timestamps();\n * const id = faker.identifier('user');\n * const orderNumber = faker.sequence('order');\n * const productPrice = faker.price();\n * ```\n */\nexport const faker = Object.freeze(\n Object.assign({}, baseFaker, {\n timestamps,\n identifier,\n sequence,\n resetSequence,\n resetAllSequences,\n price,\n coordinates: {\n within: coordinateInRadius,\n outside: coordinateOutsideRadius,\n },\n }),\n);\n\n/**\n * Type definition for timestamp fields.\n * Used by the timestamps() function to generate date fields.\n */\nexport type Timestamps = {\n /** The creation date */\n createdAt: Date;\n /** The last update date */\n updatedAt: Date;\n};\n\n/**\n * Type definition for the enhanced faker factory.\n * Includes all standard faker methods plus custom extensions.\n */\nexport type FakerFactory = typeof faker;\n"],"mappings":"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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _faker_js_faker1 from "@faker-js/faker";
|
|
2
2
|
|
|
3
3
|
//#region src/faker.d.ts
|
|
4
4
|
|
|
@@ -134,7 +134,7 @@ declare function coordinateOutsideRadius(center: Coordinate, minRadiusMeters: nu
|
|
|
134
134
|
* const productPrice = faker.price();
|
|
135
135
|
* ```
|
|
136
136
|
*/
|
|
137
|
-
declare const faker: Readonly<
|
|
137
|
+
declare const faker: Readonly<_faker_js_faker1.Faker & {
|
|
138
138
|
timestamps: typeof timestamps;
|
|
139
139
|
identifier: typeof identifier;
|
|
140
140
|
sequence: typeof sequence;
|
|
@@ -162,4 +162,5 @@ type Timestamps = {
|
|
|
162
162
|
*/
|
|
163
163
|
type FakerFactory = typeof faker;
|
|
164
164
|
//#endregion
|
|
165
|
-
export { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
|
165
|
+
export { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
|
166
|
+
//# sourceMappingURL=faker-Cg76aFNO.d.cts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _faker_js_faker1 from "@faker-js/faker";
|
|
2
2
|
|
|
3
3
|
//#region src/faker.d.ts
|
|
4
4
|
|
|
@@ -134,7 +134,7 @@ declare function coordinateOutsideRadius(center: Coordinate, minRadiusMeters: nu
|
|
|
134
134
|
* const productPrice = faker.price();
|
|
135
135
|
* ```
|
|
136
136
|
*/
|
|
137
|
-
declare const faker$1: Readonly<
|
|
137
|
+
declare const faker$1: Readonly<_faker_js_faker1.Faker & {
|
|
138
138
|
timestamps: typeof timestamps;
|
|
139
139
|
identifier: typeof identifier;
|
|
140
140
|
sequence: typeof sequence;
|
|
@@ -162,4 +162,5 @@ type Timestamps = {
|
|
|
162
162
|
*/
|
|
163
163
|
type FakerFactory = typeof faker$1;
|
|
164
164
|
//#endregion
|
|
165
|
-
export { FakerFactory, Timestamps, coordinateInRadius, faker$1 as faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
|
165
|
+
export { FakerFactory, Timestamps, coordinateInRadius, faker$1 as faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
|
166
|
+
//# sourceMappingURL=faker-DHh7xs4u.d.mts.map
|
package/dist/faker.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps } from "./faker-
|
|
1
|
+
import { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps } from "./faker-Cg76aFNO.cjs";
|
|
2
2
|
export { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
package/dist/faker.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps } from "./faker-
|
|
1
|
+
import { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps } from "./faker-DHh7xs4u.mjs";
|
|
2
2
|
export { FakerFactory, Timestamps, coordinateInRadius, faker, identifier, resetAllSequences, resetSequence, sequence, timestamps };
|
package/dist/helpers.cjs
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const kysely = require_chunk.__toESM(require("kysely"));
|
|
3
|
+
const pg = require_chunk.__toESM(require("pg"));
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
//#region src/helpers.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Kysely database instance with PostgreSQL dialect and camelCase plugin.
|
|
8
|
+
* This is a convenience function for quickly setting up a Kysely connection for testing.
|
|
9
|
+
*
|
|
10
|
+
* @template Database - The database schema type
|
|
11
|
+
* @param config - PostgreSQL connection configuration (pg.Pool config)
|
|
12
|
+
* @returns A configured Kysely instance
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* interface Database {
|
|
17
|
+
* users: UsersTable;
|
|
18
|
+
* posts: PostsTable;
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* // Create from connection string
|
|
22
|
+
* const db = createKyselyDb<Database>({
|
|
23
|
+
* connectionString: 'postgresql://user:pass@localhost:5432/testdb'
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Create with detailed config
|
|
27
|
+
* const db = createKyselyDb<Database>({
|
|
28
|
+
* host: 'localhost',
|
|
29
|
+
* port: 5432,
|
|
30
|
+
* database: 'testdb',
|
|
31
|
+
* user: 'testuser',
|
|
32
|
+
* password: 'testpass',
|
|
33
|
+
* max: 10 // connection pool size
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* // Use in tests
|
|
37
|
+
* const users = await db.selectFrom('users').selectAll().execute();
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
function createKyselyDb(config) {
|
|
41
|
+
return new kysely.Kysely({
|
|
42
|
+
dialect: new kysely.PostgresDialect({ pool: new pg.default.Pool(config) }),
|
|
43
|
+
plugins: [new kysely.CamelCasePlugin()]
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
exports.createKyselyDb = createKyselyDb;
|
|
49
|
+
//# sourceMappingURL=helpers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.cjs","names":["config: any","Kysely","PostgresDialect","CamelCasePlugin"],"sources":["../src/helpers.ts"],"sourcesContent":["import { CamelCasePlugin, Kysely, PostgresDialect } from 'kysely';\nimport pg from 'pg';\n\n/**\n * Creates a Kysely database instance with PostgreSQL dialect and camelCase plugin.\n * This is a convenience function for quickly setting up a Kysely connection for testing.\n *\n * @template Database - The database schema type\n * @param config - PostgreSQL connection configuration (pg.Pool config)\n * @returns A configured Kysely instance\n *\n * @example\n * ```typescript\n * interface Database {\n * users: UsersTable;\n * posts: PostsTable;\n * }\n *\n * // Create from connection string\n * const db = createKyselyDb<Database>({\n * connectionString: 'postgresql://user:pass@localhost:5432/testdb'\n * });\n *\n * // Create with detailed config\n * const db = createKyselyDb<Database>({\n * host: 'localhost',\n * port: 5432,\n * database: 'testdb',\n * user: 'testuser',\n * password: 'testpass',\n * max: 10 // connection pool size\n * });\n *\n * // Use in tests\n * const users = await db.selectFrom('users').selectAll().execute();\n * ```\n */\nexport function createKyselyDb<Database>(config: any): Kysely<Database> {\n return new Kysely({\n dialect: new PostgresDialect({\n pool: new pg.Pool(config),\n }),\n plugins: [new CamelCasePlugin()],\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,eAAyBA,QAA+B;AACtE,QAAO,IAAIC,cAAO;EAChB,SAAS,IAAIC,uBAAgB,EAC3B,MAAM,IAAI,WAAG,KAAK,QACnB;EACD,SAAS,CAAC,IAAIC,wBAAkB;CACjC;AACF"}
|
package/dist/helpers.d.cts
CHANGED
package/dist/helpers.d.mts
CHANGED
package/dist/helpers.mjs
CHANGED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CamelCasePlugin, Kysely, PostgresDialect } from "kysely";
|
|
2
|
+
import pg from "pg";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
//#region src/helpers.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates a Kysely database instance with PostgreSQL dialect and camelCase plugin.
|
|
7
|
+
* This is a convenience function for quickly setting up a Kysely connection for testing.
|
|
8
|
+
*
|
|
9
|
+
* @template Database - The database schema type
|
|
10
|
+
* @param config - PostgreSQL connection configuration (pg.Pool config)
|
|
11
|
+
* @returns A configured Kysely instance
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* interface Database {
|
|
16
|
+
* users: UsersTable;
|
|
17
|
+
* posts: PostsTable;
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // Create from connection string
|
|
21
|
+
* const db = createKyselyDb<Database>({
|
|
22
|
+
* connectionString: 'postgresql://user:pass@localhost:5432/testdb'
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Create with detailed config
|
|
26
|
+
* const db = createKyselyDb<Database>({
|
|
27
|
+
* host: 'localhost',
|
|
28
|
+
* port: 5432,
|
|
29
|
+
* database: 'testdb',
|
|
30
|
+
* user: 'testuser',
|
|
31
|
+
* password: 'testpass',
|
|
32
|
+
* max: 10 // connection pool size
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* // Use in tests
|
|
36
|
+
* const users = await db.selectFrom('users').selectAll().execute();
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
function createKyselyDb(config) {
|
|
40
|
+
return new Kysely({
|
|
41
|
+
dialect: new PostgresDialect({ pool: new pg.Pool(config) }),
|
|
42
|
+
plugins: [new CamelCasePlugin()]
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { createKyselyDb };
|
|
48
|
+
//# sourceMappingURL=helpers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":["config: any"],"sources":["../src/helpers.ts"],"sourcesContent":["import { CamelCasePlugin, Kysely, PostgresDialect } from 'kysely';\nimport pg from 'pg';\n\n/**\n * Creates a Kysely database instance with PostgreSQL dialect and camelCase plugin.\n * This is a convenience function for quickly setting up a Kysely connection for testing.\n *\n * @template Database - The database schema type\n * @param config - PostgreSQL connection configuration (pg.Pool config)\n * @returns A configured Kysely instance\n *\n * @example\n * ```typescript\n * interface Database {\n * users: UsersTable;\n * posts: PostsTable;\n * }\n *\n * // Create from connection string\n * const db = createKyselyDb<Database>({\n * connectionString: 'postgresql://user:pass@localhost:5432/testdb'\n * });\n *\n * // Create with detailed config\n * const db = createKyselyDb<Database>({\n * host: 'localhost',\n * port: 5432,\n * database: 'testdb',\n * user: 'testuser',\n * password: 'testpass',\n * max: 10 // connection pool size\n * });\n *\n * // Use in tests\n * const users = await db.selectFrom('users').selectAll().execute();\n * ```\n */\nexport function createKyselyDb<Database>(config: any): Kysely<Database> {\n return new Kysely({\n dialect: new PostgresDialect({\n pool: new pg.Pool(config),\n }),\n plugins: [new CamelCasePlugin()],\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,eAAyBA,QAA+B;AACtE,QAAO,IAAI,OAAO;EAChB,SAAS,IAAI,gBAAgB,EAC3B,MAAM,IAAI,GAAG,KAAK,QACnB;EACD,SAAS,CAAC,IAAI,iBAAkB;CACjC;AACF"}
|
package/dist/kysely.cjs
CHANGED
|
@@ -4,11 +4,74 @@ const require_KyselyFactory = require('./KyselyFactory-Cf0o2YxO.cjs');
|
|
|
4
4
|
require('./PostgresMigrator-DFcNdCvD.cjs');
|
|
5
5
|
const require_PostgresKyselyMigrator = require('./PostgresKyselyMigrator-CfytARcA.cjs');
|
|
6
6
|
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BQ5FpLtC.cjs');
|
|
7
|
-
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-
|
|
8
|
-
const require_kysely = require('./kysely-CP1iJMvq.cjs');
|
|
7
|
+
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-Cst3vFjb.cjs');
|
|
9
8
|
|
|
9
|
+
//#region src/kysely.ts
|
|
10
|
+
/**
|
|
11
|
+
* Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.
|
|
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
|
+
* @template Database - The database schema type
|
|
16
|
+
* @param api - The Vitest test API (usually `test` from vitest)
|
|
17
|
+
* @param db - The Kysely database instance
|
|
18
|
+
* @param setup - Optional setup function to run before each test in the transaction
|
|
19
|
+
* @param level - Transaction isolation level (defaults to REPEATABLE_READ)
|
|
20
|
+
* @returns A wrapped test API that provides transaction isolation
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { test } from 'vitest';
|
|
25
|
+
* import { wrapVitestKyselyTransaction } from '@geekmidas/testkit/kysely';
|
|
26
|
+
* import { db } from './database';
|
|
27
|
+
*
|
|
28
|
+
* // Create isolated test with automatic rollback
|
|
29
|
+
* const isolatedTest = wrapVitestKyselyTransaction(test, db);
|
|
30
|
+
*
|
|
31
|
+
* // Use in tests - each test gets its own transaction
|
|
32
|
+
* isolatedTest('should create user', async ({ trx }) => {
|
|
33
|
+
* const user = await trx
|
|
34
|
+
* .insertInto('users')
|
|
35
|
+
* .values({ name: 'Test User', email: 'test@example.com' })
|
|
36
|
+
* .returningAll()
|
|
37
|
+
* .executeTakeFirst();
|
|
38
|
+
*
|
|
39
|
+
* expect(user).toBeDefined();
|
|
40
|
+
* // User is automatically rolled back after test
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // With setup function for common test data
|
|
44
|
+
* const testWithSetup = wrapVitestKyselyTransaction(
|
|
45
|
+
* test,
|
|
46
|
+
* db,
|
|
47
|
+
* async (trx) => {
|
|
48
|
+
* // Create common test data
|
|
49
|
+
* await trx.insertInto('settings')
|
|
50
|
+
* .values({ key: 'test_mode', value: 'true' })
|
|
51
|
+
* .execute();
|
|
52
|
+
* }
|
|
53
|
+
* );
|
|
54
|
+
*
|
|
55
|
+
* testWithSetup('should have test settings', async ({ trx }) => {
|
|
56
|
+
* const setting = await trx
|
|
57
|
+
* .selectFrom('settings')
|
|
58
|
+
* .where('key', '=', 'test_mode')
|
|
59
|
+
* .selectAll()
|
|
60
|
+
* .executeTakeFirst();
|
|
61
|
+
*
|
|
62
|
+
* expect(setting?.value).toBe('true');
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
function wrapVitestKyselyTransaction(api, connection, setup, level = require_VitestTransactionIsolator.IsolationLevel.REPEATABLE_READ) {
|
|
67
|
+
const wrapper = new require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator(api);
|
|
68
|
+
return wrapper.wrapVitestWithTransaction(connection, setup, level);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
10
72
|
exports.IsolationLevel = require_VitestTransactionIsolator.IsolationLevel;
|
|
11
73
|
exports.KyselyFactory = require_KyselyFactory.KyselyFactory;
|
|
12
74
|
exports.PostgresKyselyMigrator = require_PostgresKyselyMigrator.PostgresKyselyMigrator;
|
|
13
75
|
exports.VitestKyselyTransactionIsolator = require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator;
|
|
14
|
-
exports.wrapVitestKyselyTransaction =
|
|
76
|
+
exports.wrapVitestKyselyTransaction = wrapVitestKyselyTransaction;
|
|
77
|
+
//# sourceMappingURL=kysely.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kysely.cjs","names":["api: TestAPI","connection: DatabaseConnection<Kysely<Database>>","setup?: (trx: Transaction<Database>) => Promise<void>","level: IsolationLevel","IsolationLevel","VitestKyselyTransactionIsolator"],"sources":["../src/kysely.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport type { TestAPI } from 'vitest';\nimport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nimport {\n type DatabaseConnection,\n IsolationLevel,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific exports for test utilities.\n * Provides factories, migrators, and transaction isolators for Kysely ORM.\n */\n\nexport { KyselyFactory } from './KyselyFactory';\nexport { PostgresKyselyMigrator } from './PostgresKyselyMigrator';\nexport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Database - The database schema type\n * @param api - The Vitest test API (usually `test` from vitest)\n * @param db - The Kysely database 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 { wrapVitestKyselyTransaction } from '@geekmidas/testkit/kysely';\n * import { db } from './database';\n *\n * // Create isolated test with automatic rollback\n * const isolatedTest = wrapVitestKyselyTransaction(test, db);\n *\n * // Use in tests - each test gets its own transaction\n * isolatedTest('should create user', async ({ trx }) => {\n * const user = await trx\n * .insertInto('users')\n * .values({ name: 'Test User', email: 'test@example.com' })\n * .returningAll()\n * .executeTakeFirst();\n *\n * expect(user).toBeDefined();\n * // User is automatically rolled back after test\n * });\n *\n * // With setup function for common test data\n * const testWithSetup = wrapVitestKyselyTransaction(\n * test,\n * db,\n * async (trx) => {\n * // Create common test data\n * await trx.insertInto('settings')\n * .values({ key: 'test_mode', value: 'true' })\n * .execute();\n * }\n * );\n *\n * testWithSetup('should have test settings', async ({ trx }) => {\n * const setting = await trx\n * .selectFrom('settings')\n * .where('key', '=', 'test_mode')\n * .selectAll()\n * .executeTakeFirst();\n *\n * expect(setting?.value).toBe('true');\n * });\n * ```\n */\nexport function wrapVitestKyselyTransaction<Database>(\n api: TestAPI,\n connection: DatabaseConnection<Kysely<Database>>,\n setup?: (trx: Transaction<Database>) => Promise<void>,\n level: IsolationLevel = IsolationLevel.REPEATABLE_READ,\n) {\n const wrapper = new VitestKyselyTransactionIsolator<Database>(api);\n\n return wrapper.wrapVitestWithTransaction(connection, setup, level);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,SAAgB,4BACdA,KACAC,YACAC,OACAC,QAAwBC,iDAAe,iBACvC;CACA,MAAM,UAAU,IAAIC,wEAA0C;AAE9D,QAAO,QAAQ,0BAA0B,YAAY,OAAO,MAAM;AACnE"}
|
package/dist/kysely.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./faker-
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-
|
|
1
|
+
import "./faker-Cg76aFNO.cjs";
|
|
2
|
+
import "./Factory-BZ8uMoXl.cjs";
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-DRQ83r0o.cjs";
|
|
4
4
|
import "./PostgresMigrator-D5UkK1_K.cjs";
|
|
5
5
|
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CQ3aUoy_.cjs";
|
|
6
6
|
import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-DdLNODZg.cjs";
|
|
@@ -70,4 +70,5 @@ declare function wrapVitestKyselyTransaction<Database>(api: TestAPI, connection:
|
|
|
70
70
|
trx: Transaction<Database>;
|
|
71
71
|
}>;
|
|
72
72
|
//#endregion
|
|
73
|
-
export { IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, wrapVitestKyselyTransaction };
|
|
73
|
+
export { IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, wrapVitestKyselyTransaction };
|
|
74
|
+
//# sourceMappingURL=kysely.d.cts.map
|
package/dist/kysely.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import "./faker-
|
|
2
|
-
import "./Factory-
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-
|
|
4
|
-
import "./PostgresMigrator-
|
|
5
|
-
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-
|
|
6
|
-
import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-
|
|
7
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-
|
|
1
|
+
import "./faker-DHh7xs4u.mjs";
|
|
2
|
+
import "./Factory-Cmr3s3-s.mjs";
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-Cx3sezwH.mjs";
|
|
4
|
+
import "./PostgresMigrator-DQaRxoaY.mjs";
|
|
5
|
+
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CIx3AFSR.mjs";
|
|
6
|
+
import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-CsfJBxcb.mjs";
|
|
7
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-COCVfvfr.mjs";
|
|
8
8
|
import { Kysely, Transaction } from "kysely";
|
|
9
9
|
import { TestAPI } from "vitest";
|
|
10
10
|
|
|
@@ -70,4 +70,5 @@ declare function wrapVitestKyselyTransaction<Database>(api: TestAPI, connection:
|
|
|
70
70
|
trx: Transaction<Database>;
|
|
71
71
|
}>;
|
|
72
72
|
//#endregion
|
|
73
|
-
export { IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, wrapVitestKyselyTransaction };
|
|
73
|
+
export { IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, wrapVitestKyselyTransaction };
|
|
74
|
+
//# sourceMappingURL=kysely.d.mts.map
|