@geekmidas/testkit 0.0.16 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +302 -199
- package/dist/{KyselyFactory-DRQ83r0o.d.cts → KyselyFactory-BFygzOlO.d.cts} +21 -8
- package/dist/{KyselyFactory-Cx3sezwH.d.mts → KyselyFactory-BTdygZ-i.d.mts} +21 -8
- package/dist/{KyselyFactory-BcYkC0t2.mjs → KyselyFactory-CXY5gJk2.mjs} +25 -12
- package/dist/KyselyFactory-CXY5gJk2.mjs.map +1 -0
- package/dist/{KyselyFactory-Cf0o2YxO.cjs → KyselyFactory-DaaCykWP.cjs} +25 -12
- package/dist/KyselyFactory-DaaCykWP.cjs.map +1 -0
- package/dist/KyselyFactory.cjs +1 -1
- package/dist/KyselyFactory.d.cts +1 -1
- package/dist/KyselyFactory.d.mts +1 -1
- package/dist/KyselyFactory.mjs +1 -1
- package/dist/{ObjectionFactory-C-59Hjwj.d.mts → ObjectionFactory-BagGjikT.d.mts} +24 -11
- package/dist/{ObjectionFactory-C4X78k0B.d.cts → ObjectionFactory-CeSIN3kZ.d.cts} +24 -11
- package/dist/{ObjectionFactory-CDriunkS.cjs → ObjectionFactory-Eb04AOnv.cjs} +28 -15
- package/dist/ObjectionFactory-Eb04AOnv.cjs.map +1 -0
- package/dist/{ObjectionFactory-8hebmnai.mjs → ObjectionFactory-zf2fLKrL.mjs} +28 -15
- package/dist/ObjectionFactory-zf2fLKrL.mjs.map +1 -0
- package/dist/ObjectionFactory.cjs +1 -1
- package/dist/ObjectionFactory.d.cts +1 -1
- package/dist/ObjectionFactory.d.mts +1 -1
- package/dist/ObjectionFactory.mjs +1 -1
- package/dist/{VitestKyselyTransactionIsolator-COCVfvfr.d.mts → VitestKyselyTransactionIsolator-4HOeLQ0d.d.cts} +2 -2
- package/dist/{VitestKyselyTransactionIsolator-Cst3vFjb.cjs → VitestKyselyTransactionIsolator-DX_VPKS-.cjs} +2 -2
- package/dist/{VitestKyselyTransactionIsolator-Cst3vFjb.cjs.map → VitestKyselyTransactionIsolator-DX_VPKS-.cjs.map} +1 -1
- package/dist/{VitestKyselyTransactionIsolator-DYUYVEh9.d.cts → VitestKyselyTransactionIsolator-DnyZMaA-.d.mts} +2 -2
- package/dist/{VitestKyselyTransactionIsolator-BxjlD1YM.mjs → VitestKyselyTransactionIsolator-XDL3ngs_.mjs} +2 -2
- package/dist/{VitestKyselyTransactionIsolator-BxjlD1YM.mjs.map → VitestKyselyTransactionIsolator-XDL3ngs_.mjs.map} +1 -1
- package/dist/VitestKyselyTransactionIsolator.cjs +2 -2
- package/dist/VitestKyselyTransactionIsolator.d.cts +2 -2
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestKyselyTransactionIsolator.mjs +2 -2
- package/dist/{VitestObjectionTransactionIsolator-b973r9O1.d.mts → VitestObjectionTransactionIsolator-COVDlpEo.d.cts} +2 -2
- package/dist/{VitestObjectionTransactionIsolator-DzeF4UAq.cjs → VitestObjectionTransactionIsolator-D_tlOtq8.cjs} +2 -2
- package/dist/{VitestObjectionTransactionIsolator-DzeF4UAq.cjs.map → VitestObjectionTransactionIsolator-D_tlOtq8.cjs.map} +1 -1
- package/dist/{VitestObjectionTransactionIsolator-BU-jXEhz.mjs → VitestObjectionTransactionIsolator-_EhJKu_O.mjs} +2 -2
- package/dist/{VitestObjectionTransactionIsolator-BU-jXEhz.mjs.map → VitestObjectionTransactionIsolator-_EhJKu_O.mjs.map} +1 -1
- package/dist/{VitestObjectionTransactionIsolator-CJ4ds5Qv.d.cts → VitestObjectionTransactionIsolator-lZUSz1w0.d.mts} +2 -2
- package/dist/VitestObjectionTransactionIsolator.cjs +2 -2
- package/dist/VitestObjectionTransactionIsolator.d.cts +2 -2
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator.mjs +2 -2
- package/dist/{VitestTransactionIsolator-CskiiJbW.mjs → VitestTransactionIsolator-BIaMs4c2.mjs} +40 -2
- package/dist/VitestTransactionIsolator-BIaMs4c2.mjs.map +1 -0
- package/dist/{VitestTransactionIsolator-BQ5FpLtC.cjs → VitestTransactionIsolator-BKIrj3Uy.cjs} +45 -1
- package/dist/VitestTransactionIsolator-BKIrj3Uy.cjs.map +1 -0
- package/dist/{VitestTransactionIsolator-CsfJBxcb.d.mts → VitestTransactionIsolator-CyG_i_Nj.d.cts} +61 -3
- package/dist/{VitestTransactionIsolator-DdLNODZg.d.cts → VitestTransactionIsolator-DWDbnITQ.d.mts} +61 -3
- package/dist/VitestTransactionIsolator.cjs +3 -2
- package/dist/VitestTransactionIsolator.d.cts +2 -2
- package/dist/VitestTransactionIsolator.d.mts +2 -2
- package/dist/VitestTransactionIsolator.mjs +2 -2
- package/dist/better-auth.cjs +242 -0
- package/dist/better-auth.cjs.map +1 -0
- package/dist/better-auth.d.cts +17 -0
- package/dist/better-auth.d.mts +17 -0
- package/dist/better-auth.mjs +241 -0
- package/dist/better-auth.mjs.map +1 -0
- package/dist/{directory-B4oYx02C.d.mts → directory-BXavAeJZ.d.mts} +3 -3
- package/dist/{directory-BUcnztHI.d.cts → directory-DlkPEzL4.d.cts} +3 -3
- package/dist/kysely.cjs +58 -4
- package/dist/kysely.cjs.map +1 -1
- package/dist/kysely.d.cts +58 -5
- package/dist/kysely.d.mts +58 -5
- package/dist/kysely.mjs +57 -5
- package/dist/kysely.mjs.map +1 -1
- package/dist/objection.cjs +54 -4
- package/dist/objection.cjs.map +1 -1
- package/dist/objection.d.cts +54 -5
- package/dist/objection.d.mts +54 -5
- package/dist/objection.mjs +53 -5
- package/dist/objection.mjs.map +1 -1
- package/dist/os/directory.d.cts +1 -1
- package/dist/os/directory.d.mts +1 -1
- package/dist/os/index.d.cts +1 -1
- package/dist/os/index.d.mts +1 -1
- package/package.json +13 -3
- package/src/KyselyFactory.ts +29 -16
- package/src/ObjectionFactory.ts +34 -19
- package/src/VitestTransactionIsolator.ts +110 -2
- package/src/__tests__/KyselyFactory.spec.ts +10 -10
- package/src/__tests__/ObjectionFactory.spec.ts +9 -12
- package/src/__tests__/better-auth.spec.ts +21 -0
- package/src/__tests__/integration.spec.ts +171 -14
- package/src/better-auth.ts +325 -0
- package/src/kysely.ts +66 -0
- package/src/objection.ts +61 -0
- package/dist/KyselyFactory-BcYkC0t2.mjs.map +0 -1
- package/dist/KyselyFactory-Cf0o2YxO.cjs.map +0 -1
- package/dist/ObjectionFactory-8hebmnai.mjs.map +0 -1
- package/dist/ObjectionFactory-CDriunkS.cjs.map +0 -1
- package/dist/VitestTransactionIsolator-BQ5FpLtC.cjs.map +0 -1
- package/dist/VitestTransactionIsolator-CskiiJbW.mjs.map +0 -1
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { createAdapterFactory } from "better-auth/adapters";
|
|
2
|
+
|
|
3
|
+
//#region src/better-auth.ts
|
|
4
|
+
var MemoryStore = class {
|
|
5
|
+
constructor(initialData, data = /* @__PURE__ */ new Map()) {
|
|
6
|
+
this.data = data;
|
|
7
|
+
if (initialData) for (const [model, records] of Object.entries(initialData)) {
|
|
8
|
+
const modelData = /* @__PURE__ */ new Map();
|
|
9
|
+
for (const record of records) modelData.set(record.id, { ...record });
|
|
10
|
+
this.data.set(model, modelData);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
getModel(modelName) {
|
|
14
|
+
if (!this.data.has(modelName)) this.data.set(modelName, /* @__PURE__ */ new Map());
|
|
15
|
+
return this.data.get(modelName);
|
|
16
|
+
}
|
|
17
|
+
clear() {
|
|
18
|
+
this.data.clear();
|
|
19
|
+
}
|
|
20
|
+
getAllData() {
|
|
21
|
+
const result = {};
|
|
22
|
+
for (const [model, records] of this.data.entries()) result[model] = Array.from(records.values());
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
function matchesWhere(record, where) {
|
|
27
|
+
if (!where || where.length === 0) return true;
|
|
28
|
+
let result = null;
|
|
29
|
+
for (const condition of where) {
|
|
30
|
+
const { field, value, operator = "eq", connector = "AND" } = condition;
|
|
31
|
+
const recordValue = record[field];
|
|
32
|
+
let matches = false;
|
|
33
|
+
switch (operator) {
|
|
34
|
+
case "eq":
|
|
35
|
+
matches = recordValue === value;
|
|
36
|
+
break;
|
|
37
|
+
case "ne":
|
|
38
|
+
matches = recordValue !== value;
|
|
39
|
+
break;
|
|
40
|
+
case "lt":
|
|
41
|
+
matches = value != null && recordValue < value;
|
|
42
|
+
break;
|
|
43
|
+
case "lte":
|
|
44
|
+
matches = value != null && recordValue <= value;
|
|
45
|
+
break;
|
|
46
|
+
case "gt":
|
|
47
|
+
matches = value != null && recordValue > value;
|
|
48
|
+
break;
|
|
49
|
+
case "gte":
|
|
50
|
+
matches = value != null && recordValue >= value;
|
|
51
|
+
break;
|
|
52
|
+
case "in":
|
|
53
|
+
matches = Array.isArray(value) && value.includes(recordValue);
|
|
54
|
+
break;
|
|
55
|
+
case "not_in":
|
|
56
|
+
matches = Array.isArray(value) && !value.includes(recordValue);
|
|
57
|
+
break;
|
|
58
|
+
case "contains":
|
|
59
|
+
matches = typeof recordValue === "string" && typeof value === "string" && recordValue.includes(value);
|
|
60
|
+
break;
|
|
61
|
+
case "starts_with":
|
|
62
|
+
matches = typeof recordValue === "string" && typeof value === "string" && recordValue.startsWith(value);
|
|
63
|
+
break;
|
|
64
|
+
case "ends_with":
|
|
65
|
+
matches = typeof recordValue === "string" && typeof value === "string" && recordValue.endsWith(value);
|
|
66
|
+
break;
|
|
67
|
+
default: matches = recordValue === value;
|
|
68
|
+
}
|
|
69
|
+
if (result === null) result = matches;
|
|
70
|
+
else if (connector === "OR") result = result || matches;
|
|
71
|
+
else result = result && matches;
|
|
72
|
+
}
|
|
73
|
+
return result ?? true;
|
|
74
|
+
}
|
|
75
|
+
function applySorting(records, sortBy) {
|
|
76
|
+
if (!sortBy) return records;
|
|
77
|
+
const { field, direction } = sortBy;
|
|
78
|
+
return records.sort((a, b) => {
|
|
79
|
+
const aVal = a[field];
|
|
80
|
+
const bVal = b[field];
|
|
81
|
+
if (aVal === bVal) return 0;
|
|
82
|
+
if (aVal == null) return direction === "asc" ? -1 : 1;
|
|
83
|
+
if (bVal == null) return direction === "asc" ? 1 : -1;
|
|
84
|
+
const comparison = aVal < bVal ? -1 : 1;
|
|
85
|
+
return direction === "asc" ? comparison : -comparison;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const memoryAdapter = (config = {}, store = /* @__PURE__ */ new Map()) => {
|
|
89
|
+
const storeInstance = new MemoryStore(config.initialData, store);
|
|
90
|
+
const adapterInstance = createAdapterFactory({
|
|
91
|
+
config: {
|
|
92
|
+
adapterId: "memory-adapter",
|
|
93
|
+
adapterName: "Memory Adapter",
|
|
94
|
+
usePlural: config.usePlural ?? false,
|
|
95
|
+
debugLogs: config.debugLogs ?? false,
|
|
96
|
+
supportsJSON: true,
|
|
97
|
+
supportsDates: true,
|
|
98
|
+
supportsBooleans: true,
|
|
99
|
+
supportsNumericIds: false
|
|
100
|
+
},
|
|
101
|
+
adapter: ({ debugLog, transformInput, transformOutput, getModelName, transformWhereClause }) => ({
|
|
102
|
+
create: async ({ data, model, select }) => {
|
|
103
|
+
debugLog("CREATE", {
|
|
104
|
+
model,
|
|
105
|
+
data
|
|
106
|
+
});
|
|
107
|
+
const modelName = getModelName(model);
|
|
108
|
+
const modelData = storeInstance.getModel(modelName);
|
|
109
|
+
const transformedData = await transformInput(data, model, "create");
|
|
110
|
+
if (!transformedData.id) transformedData.id = crypto.randomUUID();
|
|
111
|
+
modelData.set(transformedData.id, {
|
|
112
|
+
...transformedData,
|
|
113
|
+
...data
|
|
114
|
+
});
|
|
115
|
+
if (data.email_address) modelData.set(transformedData.id, {
|
|
116
|
+
...transformedData,
|
|
117
|
+
email: data.email_address
|
|
118
|
+
});
|
|
119
|
+
const created = modelData.get(transformedData.id);
|
|
120
|
+
const out = await transformOutput(created, model, select);
|
|
121
|
+
return out;
|
|
122
|
+
},
|
|
123
|
+
findOne: async ({ where, model, select }) => {
|
|
124
|
+
debugLog("FIND_ONE", {
|
|
125
|
+
model,
|
|
126
|
+
where
|
|
127
|
+
});
|
|
128
|
+
const modelName = getModelName(model);
|
|
129
|
+
const modelData = storeInstance.getModel(modelName);
|
|
130
|
+
const transformedWhere = transformWhereClause({
|
|
131
|
+
model,
|
|
132
|
+
where
|
|
133
|
+
});
|
|
134
|
+
for (const record of modelData.values()) if (matchesWhere(record, transformedWhere)) {
|
|
135
|
+
const t = await transformOutput(record, model, select);
|
|
136
|
+
return t;
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
},
|
|
140
|
+
findMany: async ({ where, model, limit, offset, sortBy }) => {
|
|
141
|
+
debugLog("FIND_MANY", {
|
|
142
|
+
model,
|
|
143
|
+
where
|
|
144
|
+
});
|
|
145
|
+
const modelName = getModelName(model);
|
|
146
|
+
const modelData = storeInstance.getModel(modelName);
|
|
147
|
+
const transformedWhere = transformWhereClause({
|
|
148
|
+
model,
|
|
149
|
+
where
|
|
150
|
+
});
|
|
151
|
+
let results = Array.from(modelData.values()).filter((record) => matchesWhere(record, transformedWhere));
|
|
152
|
+
if (sortBy) results = applySorting(results, sortBy);
|
|
153
|
+
if (offset) results = results.slice(offset);
|
|
154
|
+
if (limit) results = results.slice(0, limit);
|
|
155
|
+
return Promise.all(results.map((record) => transformOutput(record, model)));
|
|
156
|
+
},
|
|
157
|
+
update: async ({ where, update, model }) => {
|
|
158
|
+
debugLog("UPDATE", {
|
|
159
|
+
model,
|
|
160
|
+
where
|
|
161
|
+
});
|
|
162
|
+
const modelName = getModelName(model);
|
|
163
|
+
const modelData = storeInstance.getModel(modelName);
|
|
164
|
+
const transformedWhere = transformWhereClause({
|
|
165
|
+
model,
|
|
166
|
+
where
|
|
167
|
+
});
|
|
168
|
+
for (const [id, record] of modelData.entries()) if (matchesWhere(record, transformedWhere)) {
|
|
169
|
+
const transformedData = await transformInput(update, model, "update");
|
|
170
|
+
const updated = {
|
|
171
|
+
...record,
|
|
172
|
+
...transformedData
|
|
173
|
+
};
|
|
174
|
+
modelData.set(id, updated);
|
|
175
|
+
return transformOutput(updated, model);
|
|
176
|
+
}
|
|
177
|
+
return null;
|
|
178
|
+
},
|
|
179
|
+
updateMany: async ({ where, update, model }) => {
|
|
180
|
+
debugLog("UPDATE_MANY", {
|
|
181
|
+
model,
|
|
182
|
+
where
|
|
183
|
+
});
|
|
184
|
+
const modelName = getModelName(model);
|
|
185
|
+
const modelData = storeInstance.getModel(modelName);
|
|
186
|
+
const transformedWhere = transformWhereClause({
|
|
187
|
+
model,
|
|
188
|
+
where
|
|
189
|
+
});
|
|
190
|
+
let count = 0;
|
|
191
|
+
const transformedData = await transformInput(update, model, "update");
|
|
192
|
+
for (const [id, record] of modelData.entries()) if (matchesWhere(record, transformedWhere)) {
|
|
193
|
+
modelData.set(id, {
|
|
194
|
+
...record,
|
|
195
|
+
...transformedData
|
|
196
|
+
});
|
|
197
|
+
count++;
|
|
198
|
+
}
|
|
199
|
+
return count;
|
|
200
|
+
},
|
|
201
|
+
delete: async ({ where, model }) => {
|
|
202
|
+
debugLog("DELETE", {
|
|
203
|
+
model,
|
|
204
|
+
where
|
|
205
|
+
});
|
|
206
|
+
const modelName = getModelName(model);
|
|
207
|
+
const modelData = storeInstance.getModel(modelName);
|
|
208
|
+
for (const [id, record] of modelData.entries()) if (matchesWhere(record, where)) {
|
|
209
|
+
modelData.delete(id);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
deleteMany: async ({ where, model }) => {
|
|
214
|
+
debugLog("DELETE_MANY", {
|
|
215
|
+
model,
|
|
216
|
+
where
|
|
217
|
+
});
|
|
218
|
+
const modelName = getModelName(model);
|
|
219
|
+
const modelData = storeInstance.getModel(modelName);
|
|
220
|
+
const toDelete = [];
|
|
221
|
+
for (const [id, record] of modelData.entries()) if (matchesWhere(record, where)) toDelete.push(id);
|
|
222
|
+
toDelete.forEach((id) => modelData.delete(id));
|
|
223
|
+
return toDelete.length;
|
|
224
|
+
},
|
|
225
|
+
count: async ({ where, model }) => {
|
|
226
|
+
const modelName = getModelName(model);
|
|
227
|
+
const modelData = storeInstance.getModel(modelName);
|
|
228
|
+
return Array.from(modelData.values()).filter((record) => matchesWhere(record, where)).length;
|
|
229
|
+
}
|
|
230
|
+
})
|
|
231
|
+
});
|
|
232
|
+
return Object.assign(adapterInstance, {
|
|
233
|
+
clear: () => store.clear(),
|
|
234
|
+
getAllData: () => storeInstance.getAllData(),
|
|
235
|
+
getStore: () => store
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
//#endregion
|
|
240
|
+
export { memoryAdapter };
|
|
241
|
+
//# sourceMappingURL=better-auth.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"better-auth.mjs","names":["initialData?: Record<string, any[]>","data: Map<string, any>","modelName: string","result: Record<string, any[]>","record: any","where?: Where[]","result: boolean | null","records: any[]","sortBy?: SortBy","config: MemoryAdapterConfig","toDelete: string[]"],"sources":["../src/better-auth.ts"],"sourcesContent":["import {\n type DBAdapterDebugLogOption,\n type Where,\n createAdapterFactory,\n} from 'better-auth/adapters';\n\ninterface MemoryAdapterConfig {\n debugLogs?: DBAdapterDebugLogOption;\n usePlural?: boolean;\n initialData?: Record<string, any[]>;\n}\n\nclass MemoryStore {\n constructor(\n initialData?: Record<string, any[]>,\n private readonly data: Map<string, any> = new Map(),\n ) {\n if (initialData) {\n for (const [model, records] of Object.entries(initialData)) {\n const modelData = new Map();\n for (const record of records) {\n modelData.set(record.id, { ...record });\n }\n this.data.set(model, modelData);\n }\n }\n }\n\n getModel(modelName: string): Map<string, any> {\n if (!this.data.has(modelName)) {\n this.data.set(modelName, new Map());\n }\n return this.data.get(modelName)!;\n }\n\n clear() {\n this.data.clear();\n }\n\n getAllData() {\n const result: Record<string, any[]> = {};\n for (const [model, records] of this.data.entries()) {\n result[model] = Array.from(records.values());\n }\n return result;\n }\n}\n\nfunction matchesWhere(record: any, where?: Where[]): boolean {\n if (!where || where.length === 0) return true;\n\n let result: boolean | null = null;\n\n for (const condition of where) {\n const { field, value, operator = 'eq', connector = 'AND' } = condition;\n const recordValue = record[field];\n\n let matches = false;\n\n switch (operator) {\n case 'eq':\n matches = recordValue === value;\n break;\n case 'ne':\n matches = recordValue !== value;\n break;\n case 'lt':\n matches = value != null && recordValue < value;\n break;\n case 'lte':\n matches = value != null && recordValue <= value;\n break;\n case 'gt':\n matches = value != null && recordValue > value;\n break;\n case 'gte':\n matches = value != null && recordValue >= value;\n break;\n case 'in':\n matches =\n Array.isArray(value) && (value as unknown[]).includes(recordValue);\n break;\n case 'not_in':\n matches =\n Array.isArray(value) && !(value as unknown[]).includes(recordValue);\n break;\n case 'contains':\n matches =\n typeof recordValue === 'string' &&\n typeof value === 'string' &&\n recordValue.includes(value);\n break;\n case 'starts_with':\n matches =\n typeof recordValue === 'string' &&\n typeof value === 'string' &&\n recordValue.startsWith(value);\n break;\n case 'ends_with':\n matches =\n typeof recordValue === 'string' &&\n typeof value === 'string' &&\n recordValue.endsWith(value);\n break;\n default:\n matches = recordValue === value;\n }\n\n // Apply connector logic\n if (result === null) {\n result = matches;\n } else if (connector === 'OR') {\n result = result || matches;\n } else {\n // Default: AND\n result = result && matches;\n }\n }\n\n return result ?? true;\n}\ntype SortBy = {\n field: string;\n direction: 'asc' | 'desc';\n};\n\nfunction applySorting(records: any[], sortBy?: SortBy): any[] {\n if (!sortBy) return records;\n\n const { field, direction } = sortBy;\n\n return records.sort((a, b) => {\n const aVal = a[field];\n const bVal = b[field];\n\n if (aVal === bVal) return 0;\n if (aVal == null) return direction === 'asc' ? -1 : 1;\n if (bVal == null) return direction === 'asc' ? 1 : -1;\n\n const comparison = aVal < bVal ? -1 : 1;\n return direction === 'asc' ? comparison : -comparison;\n });\n}\n\nexport const memoryAdapter = (\n config: MemoryAdapterConfig = {},\n store = new Map(),\n) => {\n const storeInstance = new MemoryStore(config.initialData, store);\n\n const adapterInstance = createAdapterFactory({\n config: {\n adapterId: 'memory-adapter',\n adapterName: 'Memory Adapter',\n usePlural: config.usePlural ?? false,\n debugLogs: config.debugLogs ?? false,\n supportsJSON: true,\n supportsDates: true,\n supportsBooleans: true,\n supportsNumericIds: false,\n },\n\n adapter: ({\n debugLog,\n transformInput,\n transformOutput,\n getModelName,\n transformWhereClause,\n }) => ({\n create: async ({ data, model, select }) => {\n debugLog('CREATE', { model, data });\n const modelName = getModelName(model);\n const modelData = storeInstance.getModel(modelName);\n\n const transformedData = await transformInput(data, model, 'create');\n\n if (!transformedData.id) {\n transformedData.id = crypto.randomUUID();\n }\n\n modelData.set(transformedData.id, { ...transformedData, ...data });\n\n if (data.email_address) {\n modelData.set(transformedData.id, {\n ...transformedData,\n email: data.email_address,\n });\n }\n const created = modelData.get(transformedData.id);\n\n const out = (await transformOutput(created, model, select)) as any;\n\n return out;\n },\n\n findOne: async ({ where, model, select }) => {\n debugLog('FIND_ONE', { model, where });\n const modelName = getModelName(model);\n const modelData = storeInstance.getModel(modelName);\n const transformedWhere = transformWhereClause({ model, where });\n\n for (const record of modelData.values()) {\n if (matchesWhere(record, transformedWhere)) {\n const t = (await transformOutput(record, model, select)) as any;\n\n return t;\n }\n }\n return null;\n },\n\n findMany: async ({ where, model, limit, offset, sortBy }) => {\n debugLog('FIND_MANY', { model, where });\n\n const modelName = getModelName(model);\n const modelData = storeInstance.getModel(modelName);\n const transformedWhere = transformWhereClause({ model, where });\n\n let results = Array.from(modelData.values()).filter((record) =>\n matchesWhere(record, transformedWhere),\n );\n\n if (sortBy) {\n results = applySorting(results, sortBy);\n }\n\n if (offset) {\n results = results.slice(offset);\n }\n if (limit) {\n results = results.slice(0, limit);\n }\n\n return Promise.all(\n results.map((record) => transformOutput(record, model)),\n ) as any;\n },\n\n update: async ({ where, update, model }) => {\n debugLog('UPDATE', { model, where });\n\n const modelName = getModelName(model);\n const modelData = storeInstance.getModel(modelName);\n const transformedWhere = transformWhereClause({ model, where });\n\n for (const [id, record] of modelData.entries()) {\n if (matchesWhere(record, transformedWhere)) {\n const transformedData = await transformInput(\n update as any,\n model,\n 'update',\n );\n const updated = { ...record, ...transformedData };\n modelData.set(id, updated);\n return transformOutput(updated, model) as any;\n }\n }\n return null;\n },\n\n updateMany: async ({ where, update, model }) => {\n debugLog('UPDATE_MANY', { model, where });\n const modelName = getModelName(model);\n const modelData = storeInstance.getModel(modelName);\n const transformedWhere = transformWhereClause({ model, where });\n\n let count = 0;\n const transformedData = await transformInput(update, model, 'update');\n\n for (const [id, record] of modelData.entries()) {\n if (matchesWhere(record, transformedWhere)) {\n modelData.set(id, { ...record, ...transformedData });\n count++;\n }\n }\n return count;\n },\n\n delete: async ({ where, model }) => {\n debugLog('DELETE', { model, where });\n const modelName = getModelName(model);\n const modelData = storeInstance.getModel(modelName);\n\n for (const [id, record] of modelData.entries()) {\n if (matchesWhere(record, where)) {\n modelData.delete(id);\n return;\n }\n }\n },\n\n deleteMany: async ({ where, model }) => {\n debugLog('DELETE_MANY', { model, where });\n const modelName = getModelName(model);\n const modelData = storeInstance.getModel(modelName);\n\n const toDelete: string[] = [];\n for (const [id, record] of modelData.entries()) {\n if (matchesWhere(record, where)) {\n toDelete.push(id);\n }\n }\n\n toDelete.forEach((id) => modelData.delete(id));\n return toDelete.length;\n },\n\n count: async ({ where, model }) => {\n const modelName = getModelName(model);\n const modelData = storeInstance.getModel(modelName);\n\n return Array.from(modelData.values()).filter((record) =>\n matchesWhere(record, where),\n ).length;\n },\n }),\n });\n\n // Add utility methods to the adapter\n return Object.assign(adapterInstance, {\n clear: () => store.clear(),\n getAllData: () => storeInstance.getAllData(),\n getStore: () => store,\n });\n};\n"],"mappings":";;;AAYA,IAAM,cAAN,MAAkB;CAChB,YACEA,aACiBC,uBAAyB,IAAI,OAC9C;EADiB;AAEjB,MAAI,YACF,MAAK,MAAM,CAAC,OAAO,QAAQ,IAAI,OAAO,QAAQ,YAAY,EAAE;GAC1D,MAAM,4BAAY,IAAI;AACtB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EAAE;AAC/B,eAAU,OAAO,GAAG;AACpB;IACD;GAEJ;GAED,YAAY,OAAO,EAAE,OAAO,OAAO,KAAK;AACtC,aAAS,eAAe;KAAE;KAAO;IAAO,EAAC;IACzC,MAAM,YAAY,aAAa,MAAM;IACrC,MAAM,YAAY,cAAc,SAAS,UAAU;IAEnD,MAAMC,WAAqB,CAAE;AAC7B,SAAK,MAAM,CAAC,IAAI,OAAO,IAAI,UAAU,SAAS,CAC5C,KAAI,aAAa,QAAQ,MAAM,CAC7B,UAAS,KAAK,GAAG;AAIrB,aAAS,QAAQ,CAAC,OAAO,UAAU,OAAO,GAAG,CAAC;AAC9C,WAAO,SAAS;GACjB;GAED,OAAO,OAAO,EAAE,OAAO,OAAO,KAAK;IACjC,MAAM,YAAY,aAAa,MAAM;IACrC,MAAM,YAAY,cAAc,SAAS,UAAU;AAEnD,WAAO,MAAM,KAAK,UAAU,QAAQ,CAAC,CAAC,OAAO,CAAC,WAC5C,aAAa,QAAQ,MAAM,CAC5B,CAAC;GACH;EACF;CACF,EAAC;AAGF,QAAO,OAAO,OAAO,iBAAiB;EACpC,OAAO,MAAM,MAAM,OAAO;EAC1B,YAAY,MAAM,cAAc,YAAY;EAC5C,UAAU,MAAM;CACjB,EAAC;AACH"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as vitest6 from "vitest";
|
|
2
2
|
|
|
3
3
|
//#region src/os/directory.d.ts
|
|
4
|
-
declare const itWithDir:
|
|
4
|
+
declare const itWithDir: vitest6.TestAPI<{
|
|
5
5
|
dir: string;
|
|
6
6
|
}>;
|
|
7
7
|
interface DirectoryFixtures {
|
|
@@ -9,4 +9,4 @@ interface DirectoryFixtures {
|
|
|
9
9
|
}
|
|
10
10
|
//#endregion
|
|
11
11
|
export { DirectoryFixtures, itWithDir };
|
|
12
|
-
//# sourceMappingURL=directory-
|
|
12
|
+
//# sourceMappingURL=directory-BXavAeJZ.d.mts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as vitest6 from "vitest";
|
|
2
2
|
|
|
3
3
|
//#region src/os/directory.d.ts
|
|
4
|
-
declare const itWithDir:
|
|
4
|
+
declare const itWithDir: vitest6.TestAPI<{
|
|
5
5
|
dir: string;
|
|
6
6
|
}>;
|
|
7
7
|
interface DirectoryFixtures {
|
|
@@ -9,4 +9,4 @@ interface DirectoryFixtures {
|
|
|
9
9
|
}
|
|
10
10
|
//#endregion
|
|
11
11
|
export { DirectoryFixtures, itWithDir };
|
|
12
|
-
//# sourceMappingURL=directory-
|
|
12
|
+
//# sourceMappingURL=directory-DlkPEzL4.d.cts.map
|
package/dist/kysely.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
require('./Factory-WMhTNZ9S.cjs');
|
|
2
|
-
require('./faker-B14IEMIN.cjs');
|
|
3
|
-
const require_KyselyFactory = require('./KyselyFactory-
|
|
2
|
+
const require_faker = require('./faker-B14IEMIN.cjs');
|
|
3
|
+
const require_KyselyFactory = require('./KyselyFactory-DaaCykWP.cjs');
|
|
4
4
|
require('./PostgresMigrator-DFcNdCvD.cjs');
|
|
5
5
|
const require_PostgresKyselyMigrator = require('./PostgresKyselyMigrator-CfytARcA.cjs');
|
|
6
|
-
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-
|
|
7
|
-
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-
|
|
6
|
+
const require_VitestTransactionIsolator = require('./VitestTransactionIsolator-BKIrj3Uy.cjs');
|
|
7
|
+
const require_VitestKyselyTransactionIsolator = require('./VitestKyselyTransactionIsolator-DX_VPKS-.cjs');
|
|
8
8
|
|
|
9
9
|
//#region src/kysely.ts
|
|
10
10
|
/**
|
|
@@ -67,11 +67,65 @@ function wrapVitestKyselyTransaction(api, connection, setup, level = require_Vit
|
|
|
67
67
|
const wrapper = new require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator(api);
|
|
68
68
|
return wrapper.wrapVitestWithTransaction(connection, setup, level);
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Extends a Kysely transaction-wrapped test with additional fixtures.
|
|
72
|
+
* Each fixture receives the transaction and can create dependencies like factories or repositories.
|
|
73
|
+
*
|
|
74
|
+
* @template Database - The database schema type
|
|
75
|
+
* @template Extended - The type of additional fixtures to provide
|
|
76
|
+
* @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction
|
|
77
|
+
* @param fixtures - Object mapping fixture names to creator functions
|
|
78
|
+
* @returns An extended test API with both trx and the additional fixtures
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* import { test } from 'vitest';
|
|
83
|
+
* import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';
|
|
84
|
+
*
|
|
85
|
+
* // Define your builders
|
|
86
|
+
* const builders = {
|
|
87
|
+
* user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({
|
|
88
|
+
* name: faker.person.fullName(),
|
|
89
|
+
* email: faker.internet.email(),
|
|
90
|
+
* })),
|
|
91
|
+
* };
|
|
92
|
+
*
|
|
93
|
+
* // Create base wrapped test
|
|
94
|
+
* const baseTest = wrapVitestKyselyTransaction<DB>(test, db, createTestTables);
|
|
95
|
+
*
|
|
96
|
+
* // Extend with fixtures - each fixture receives the transaction
|
|
97
|
+
* const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(
|
|
98
|
+
* baseTest,
|
|
99
|
+
* {
|
|
100
|
+
* factory: (trx) => new KyselyFactory(builders, {}, trx),
|
|
101
|
+
* }
|
|
102
|
+
* );
|
|
103
|
+
*
|
|
104
|
+
* // Use in tests - both trx and factory are available
|
|
105
|
+
* it('should create user with factory', async ({ trx, factory }) => {
|
|
106
|
+
* const user = await factory.insert('user', { name: 'Test User' });
|
|
107
|
+
* expect(user.id).toBeDefined();
|
|
108
|
+
*
|
|
109
|
+
* // Verify in database
|
|
110
|
+
* const found = await trx
|
|
111
|
+
* .selectFrom('users')
|
|
112
|
+
* .where('id', '=', user.id)
|
|
113
|
+
* .selectAll()
|
|
114
|
+
* .executeTakeFirst();
|
|
115
|
+
* expect(found?.name).toBe('Test User');
|
|
116
|
+
* });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
function extendWithFixtures$1(wrappedTest, fixtures) {
|
|
120
|
+
return require_VitestTransactionIsolator.extendWithFixtures(wrappedTest, fixtures);
|
|
121
|
+
}
|
|
70
122
|
|
|
71
123
|
//#endregion
|
|
72
124
|
exports.IsolationLevel = require_VitestTransactionIsolator.IsolationLevel;
|
|
73
125
|
exports.KyselyFactory = require_KyselyFactory.KyselyFactory;
|
|
74
126
|
exports.PostgresKyselyMigrator = require_PostgresKyselyMigrator.PostgresKyselyMigrator;
|
|
75
127
|
exports.VitestKyselyTransactionIsolator = require_VitestKyselyTransactionIsolator.VitestKyselyTransactionIsolator;
|
|
128
|
+
exports.extendWithFixtures = extendWithFixtures$1;
|
|
129
|
+
exports.faker = require_faker.faker;
|
|
76
130
|
exports.wrapVitestKyselyTransaction = wrapVitestKyselyTransaction;
|
|
77
131
|
//# sourceMappingURL=kysely.cjs.map
|
package/dist/kysely.cjs.map
CHANGED
|
@@ -1 +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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"kysely.cjs","names":["api: TestAPI","connection: DatabaseConnection<Kysely<Database>>","setup?: (trx: Transaction<Database>) => Promise<void>","level: IsolationLevel","IsolationLevel","VitestKyselyTransactionIsolator","extendWithFixtures","wrappedTest: T","fixtures: FixtureCreators<Transaction<Database>, Extended>"],"sources":["../src/kysely.ts"],"sourcesContent":["import type { Kysely, Transaction } from 'kysely';\nimport type { TestAPI } from 'vitest';\nimport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nimport {\n type DatabaseConnection,\n type FixtureCreators,\n IsolationLevel,\n extendWithFixtures as baseExtendWithFixtures,\n} from './VitestTransactionIsolator';\n\n/**\n * Kysely-specific exports for test utilities.\n * Provides factories, migrators, and transaction isolators for Kysely ORM.\n */\n\nexport { KyselyFactory } from './KyselyFactory';\nexport { PostgresKyselyMigrator } from './PostgresKyselyMigrator';\nexport { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';\nexport { IsolationLevel } from './VitestTransactionIsolator';\nexport type { FixtureCreators } from './VitestTransactionIsolator';\n\n// Re-export faker and FakerFactory for type portability in declaration files\nexport { faker, type FakerFactory } from './faker';\n\n/**\n * Creates a wrapped Vitest test API with automatic transaction rollback for Kysely.\n * Each test runs in an isolated database transaction that is rolled back after completion.\n * This ensures tests don't affect each other's data and run faster than truncating tables.\n *\n * @template Database - The database schema type\n * @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\n/**\n * Extends a Kysely transaction-wrapped test with additional fixtures.\n * Each fixture receives the transaction and can create dependencies like factories or repositories.\n *\n * @template Database - The database schema type\n * @template Extended - The type of additional fixtures to provide\n * @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction\n * @param fixtures - Object mapping fixture names to creator functions\n * @returns An extended test API with both trx and the additional fixtures\n *\n * @example\n * ```typescript\n * import { test } from 'vitest';\n * import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';\n *\n * // Define your builders\n * const builders = {\n * user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({\n * name: faker.person.fullName(),\n * email: faker.internet.email(),\n * })),\n * };\n *\n * // Create base wrapped test\n * const baseTest = wrapVitestKyselyTransaction<DB>(test, db, createTestTables);\n *\n * // Extend with fixtures - each fixture receives the transaction\n * const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(\n * baseTest,\n * {\n * factory: (trx) => new KyselyFactory(builders, {}, trx),\n * }\n * );\n *\n * // Use in tests - both trx and factory are available\n * it('should create user with factory', async ({ trx, factory }) => {\n * const user = await factory.insert('user', { name: 'Test User' });\n * expect(user.id).toBeDefined();\n *\n * // Verify in database\n * const found = await trx\n * .selectFrom('users')\n * .where('id', '=', user.id)\n * .selectAll()\n * .executeTakeFirst();\n * expect(found?.name).toBe('Test User');\n * });\n * ```\n */\nexport function extendWithFixtures<\n Database,\n Extended extends Record<string, unknown>,\n T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>,\n>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>) {\n return baseExtendWithFixtures<Transaction<Database>, Extended, T>(\n wrappedTest,\n fixtures,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFA,SAAgB,4BACdA,KACAC,YACAC,OACAC,QAAwBC,iDAAe,iBACvC;CACA,MAAM,UAAU,IAAIC,wEAA0C;AAE9D,QAAO,QAAQ,0BAA0B,YAAY,OAAO,MAAM;AACnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDD,SAAgBC,qBAIdC,aAAgBC,UAA4D;AAC5E,QAAO,qDACL,aACA,SACD;AACF"}
|
package/dist/kysely.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import "./faker-Cg76aFNO.cjs";
|
|
1
|
+
import { FakerFactory, faker } from "./faker-Cg76aFNO.cjs";
|
|
2
2
|
import "./Factory-BZ8uMoXl.cjs";
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-BFygzOlO.cjs";
|
|
4
4
|
import "./PostgresMigrator-D5UkK1_K.cjs";
|
|
5
5
|
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CQ3aUoy_.cjs";
|
|
6
|
-
import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-
|
|
7
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-
|
|
6
|
+
import { DatabaseConnection, DatabaseFixtures, FixtureCreators, IsolationLevel } from "./VitestTransactionIsolator-CyG_i_Nj.cjs";
|
|
7
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-4HOeLQ0d.cjs";
|
|
8
8
|
import { Kysely, Transaction } from "kysely";
|
|
9
9
|
import { TestAPI } from "vitest";
|
|
10
10
|
|
|
@@ -69,6 +69,59 @@ import { TestAPI } from "vitest";
|
|
|
69
69
|
declare function wrapVitestKyselyTransaction<Database>(api: TestAPI, connection: DatabaseConnection<Kysely<Database>>, setup?: (trx: Transaction<Database>) => Promise<void>, level?: IsolationLevel): TestAPI<{
|
|
70
70
|
trx: Transaction<Database>;
|
|
71
71
|
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Extends a Kysely transaction-wrapped test with additional fixtures.
|
|
74
|
+
* Each fixture receives the transaction and can create dependencies like factories or repositories.
|
|
75
|
+
*
|
|
76
|
+
* @template Database - The database schema type
|
|
77
|
+
* @template Extended - The type of additional fixtures to provide
|
|
78
|
+
* @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction
|
|
79
|
+
* @param fixtures - Object mapping fixture names to creator functions
|
|
80
|
+
* @returns An extended test API with both trx and the additional fixtures
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* import { test } from 'vitest';
|
|
85
|
+
* import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';
|
|
86
|
+
*
|
|
87
|
+
* // Define your builders
|
|
88
|
+
* const builders = {
|
|
89
|
+
* user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({
|
|
90
|
+
* name: faker.person.fullName(),
|
|
91
|
+
* email: faker.internet.email(),
|
|
92
|
+
* })),
|
|
93
|
+
* };
|
|
94
|
+
*
|
|
95
|
+
* // Create base wrapped test
|
|
96
|
+
* const baseTest = wrapVitestKyselyTransaction<DB>(test, db, createTestTables);
|
|
97
|
+
*
|
|
98
|
+
* // Extend with fixtures - each fixture receives the transaction
|
|
99
|
+
* const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(
|
|
100
|
+
* baseTest,
|
|
101
|
+
* {
|
|
102
|
+
* factory: (trx) => new KyselyFactory(builders, {}, trx),
|
|
103
|
+
* }
|
|
104
|
+
* );
|
|
105
|
+
*
|
|
106
|
+
* // Use in tests - both trx and factory are available
|
|
107
|
+
* it('should create user with factory', async ({ trx, factory }) => {
|
|
108
|
+
* const user = await factory.insert('user', { name: 'Test User' });
|
|
109
|
+
* expect(user.id).toBeDefined();
|
|
110
|
+
*
|
|
111
|
+
* // Verify in database
|
|
112
|
+
* const found = await trx
|
|
113
|
+
* .selectFrom('users')
|
|
114
|
+
* .where('id', '=', user.id)
|
|
115
|
+
* .selectAll()
|
|
116
|
+
* .executeTakeFirst();
|
|
117
|
+
* expect(found?.name).toBe('Test User');
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
declare function extendWithFixtures<Database, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>): T & {
|
|
122
|
+
<C extends object>(name: string, fn: (context: DatabaseFixtures<Transaction<Database>, object> & Extended & C) => Promise<void>): void;
|
|
123
|
+
<C extends object>(name: string, options: object, fn: (context: DatabaseFixtures<Transaction<Database>, object> & Extended & C) => Promise<void>): void;
|
|
124
|
+
};
|
|
72
125
|
//#endregion
|
|
73
|
-
export { IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, wrapVitestKyselyTransaction };
|
|
126
|
+
export { FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
|
|
74
127
|
//# sourceMappingURL=kysely.d.cts.map
|
package/dist/kysely.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import "./faker-DHh7xs4u.mjs";
|
|
1
|
+
import { FakerFactory, faker } from "./faker-DHh7xs4u.mjs";
|
|
2
2
|
import "./Factory-Cmr3s3-s.mjs";
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-BTdygZ-i.mjs";
|
|
4
4
|
import "./PostgresMigrator-DQaRxoaY.mjs";
|
|
5
5
|
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-CIx3AFSR.mjs";
|
|
6
|
-
import { DatabaseConnection, IsolationLevel } from "./VitestTransactionIsolator-
|
|
7
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-
|
|
6
|
+
import { DatabaseConnection, DatabaseFixtures, FixtureCreators, IsolationLevel } from "./VitestTransactionIsolator-DWDbnITQ.mjs";
|
|
7
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-DnyZMaA-.mjs";
|
|
8
8
|
import { Kysely, Transaction } from "kysely";
|
|
9
9
|
import { TestAPI } from "vitest";
|
|
10
10
|
|
|
@@ -69,6 +69,59 @@ import { TestAPI } from "vitest";
|
|
|
69
69
|
declare function wrapVitestKyselyTransaction<Database>(api: TestAPI, connection: DatabaseConnection<Kysely<Database>>, setup?: (trx: Transaction<Database>) => Promise<void>, level?: IsolationLevel): TestAPI<{
|
|
70
70
|
trx: Transaction<Database>;
|
|
71
71
|
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Extends a Kysely transaction-wrapped test with additional fixtures.
|
|
74
|
+
* Each fixture receives the transaction and can create dependencies like factories or repositories.
|
|
75
|
+
*
|
|
76
|
+
* @template Database - The database schema type
|
|
77
|
+
* @template Extended - The type of additional fixtures to provide
|
|
78
|
+
* @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction
|
|
79
|
+
* @param fixtures - Object mapping fixture names to creator functions
|
|
80
|
+
* @returns An extended test API with both trx and the additional fixtures
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* import { test } from 'vitest';
|
|
85
|
+
* import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';
|
|
86
|
+
*
|
|
87
|
+
* // Define your builders
|
|
88
|
+
* const builders = {
|
|
89
|
+
* user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({
|
|
90
|
+
* name: faker.person.fullName(),
|
|
91
|
+
* email: faker.internet.email(),
|
|
92
|
+
* })),
|
|
93
|
+
* };
|
|
94
|
+
*
|
|
95
|
+
* // Create base wrapped test
|
|
96
|
+
* const baseTest = wrapVitestKyselyTransaction<DB>(test, db, createTestTables);
|
|
97
|
+
*
|
|
98
|
+
* // Extend with fixtures - each fixture receives the transaction
|
|
99
|
+
* const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(
|
|
100
|
+
* baseTest,
|
|
101
|
+
* {
|
|
102
|
+
* factory: (trx) => new KyselyFactory(builders, {}, trx),
|
|
103
|
+
* }
|
|
104
|
+
* );
|
|
105
|
+
*
|
|
106
|
+
* // Use in tests - both trx and factory are available
|
|
107
|
+
* it('should create user with factory', async ({ trx, factory }) => {
|
|
108
|
+
* const user = await factory.insert('user', { name: 'Test User' });
|
|
109
|
+
* expect(user.id).toBeDefined();
|
|
110
|
+
*
|
|
111
|
+
* // Verify in database
|
|
112
|
+
* const found = await trx
|
|
113
|
+
* .selectFrom('users')
|
|
114
|
+
* .where('id', '=', user.id)
|
|
115
|
+
* .selectAll()
|
|
116
|
+
* .executeTakeFirst();
|
|
117
|
+
* expect(found?.name).toBe('Test User');
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
declare function extendWithFixtures<Database, Extended extends Record<string, unknown>, T extends ReturnType<TestAPI['extend']> = ReturnType<TestAPI['extend']>>(wrappedTest: T, fixtures: FixtureCreators<Transaction<Database>, Extended>): T & {
|
|
122
|
+
<C extends object>(name: string, fn: (context: DatabaseFixtures<Transaction<Database>, object> & Extended & C) => Promise<void>): void;
|
|
123
|
+
<C extends object>(name: string, options: object, fn: (context: DatabaseFixtures<Transaction<Database>, object> & Extended & C) => Promise<void>): void;
|
|
124
|
+
};
|
|
72
125
|
//#endregion
|
|
73
|
-
export { IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, wrapVitestKyselyTransaction };
|
|
126
|
+
export { FakerFactory, FixtureCreators, IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, extendWithFixtures, faker, wrapVitestKyselyTransaction };
|
|
74
127
|
//# sourceMappingURL=kysely.d.mts.map
|
package/dist/kysely.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "./Factory-z2m01hMj.mjs";
|
|
2
|
-
import "./faker-BGKYFoCT.mjs";
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-
|
|
2
|
+
import { faker } from "./faker-BGKYFoCT.mjs";
|
|
3
|
+
import { KyselyFactory } from "./KyselyFactory-CXY5gJk2.mjs";
|
|
4
4
|
import "./PostgresMigrator-DbuJGAVy.mjs";
|
|
5
5
|
import { PostgresKyselyMigrator } from "./PostgresKyselyMigrator-upT-hmrz.mjs";
|
|
6
|
-
import { IsolationLevel } from "./VitestTransactionIsolator-
|
|
7
|
-
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-
|
|
6
|
+
import { IsolationLevel, extendWithFixtures } from "./VitestTransactionIsolator-BIaMs4c2.mjs";
|
|
7
|
+
import { VitestKyselyTransactionIsolator } from "./VitestKyselyTransactionIsolator-XDL3ngs_.mjs";
|
|
8
8
|
|
|
9
9
|
//#region src/kysely.ts
|
|
10
10
|
/**
|
|
@@ -67,7 +67,59 @@ function wrapVitestKyselyTransaction(api, connection, setup, level = IsolationLe
|
|
|
67
67
|
const wrapper = new VitestKyselyTransactionIsolator(api);
|
|
68
68
|
return wrapper.wrapVitestWithTransaction(connection, setup, level);
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Extends a Kysely transaction-wrapped test with additional fixtures.
|
|
72
|
+
* Each fixture receives the transaction and can create dependencies like factories or repositories.
|
|
73
|
+
*
|
|
74
|
+
* @template Database - The database schema type
|
|
75
|
+
* @template Extended - The type of additional fixtures to provide
|
|
76
|
+
* @param wrappedTest - The base wrapped test from wrapVitestKyselyTransaction
|
|
77
|
+
* @param fixtures - Object mapping fixture names to creator functions
|
|
78
|
+
* @returns An extended test API with both trx and the additional fixtures
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* import { test } from 'vitest';
|
|
83
|
+
* import { wrapVitestKyselyTransaction, extendWithFixtures, KyselyFactory } from '@geekmidas/testkit/kysely';
|
|
84
|
+
*
|
|
85
|
+
* // Define your builders
|
|
86
|
+
* const builders = {
|
|
87
|
+
* user: KyselyFactory.createBuilder<DB, 'users'>('users', ({ faker }) => ({
|
|
88
|
+
* name: faker.person.fullName(),
|
|
89
|
+
* email: faker.internet.email(),
|
|
90
|
+
* })),
|
|
91
|
+
* };
|
|
92
|
+
*
|
|
93
|
+
* // Create base wrapped test
|
|
94
|
+
* const baseTest = wrapVitestKyselyTransaction<DB>(test, db, createTestTables);
|
|
95
|
+
*
|
|
96
|
+
* // Extend with fixtures - each fixture receives the transaction
|
|
97
|
+
* const it = extendWithFixtures<DB, { factory: KyselyFactory<DB, typeof builders, {}> }>(
|
|
98
|
+
* baseTest,
|
|
99
|
+
* {
|
|
100
|
+
* factory: (trx) => new KyselyFactory(builders, {}, trx),
|
|
101
|
+
* }
|
|
102
|
+
* );
|
|
103
|
+
*
|
|
104
|
+
* // Use in tests - both trx and factory are available
|
|
105
|
+
* it('should create user with factory', async ({ trx, factory }) => {
|
|
106
|
+
* const user = await factory.insert('user', { name: 'Test User' });
|
|
107
|
+
* expect(user.id).toBeDefined();
|
|
108
|
+
*
|
|
109
|
+
* // Verify in database
|
|
110
|
+
* const found = await trx
|
|
111
|
+
* .selectFrom('users')
|
|
112
|
+
* .where('id', '=', user.id)
|
|
113
|
+
* .selectAll()
|
|
114
|
+
* .executeTakeFirst();
|
|
115
|
+
* expect(found?.name).toBe('Test User');
|
|
116
|
+
* });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
function extendWithFixtures$1(wrappedTest, fixtures) {
|
|
120
|
+
return extendWithFixtures(wrappedTest, fixtures);
|
|
121
|
+
}
|
|
70
122
|
|
|
71
123
|
//#endregion
|
|
72
|
-
export { IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, wrapVitestKyselyTransaction };
|
|
124
|
+
export { IsolationLevel, KyselyFactory, PostgresKyselyMigrator, VitestKyselyTransactionIsolator, extendWithFixtures$1 as extendWithFixtures, faker, wrapVitestKyselyTransaction };
|
|
73
125
|
//# sourceMappingURL=kysely.mjs.map
|