@geekmidas/testkit 0.0.15 → 0.0.17
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-CRquB4vz.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-72P98y5I.d.mts → KyselyFactory-BDS_QqRT.d.mts} +4 -3
- 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-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-C3tHvX1d.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-BxjlD1YM.mjs +2 -1
- package/dist/VitestKyselyTransactionIsolator-BxjlD1YM.mjs.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-CnxpE9cH.d.mts → VitestKyselyTransactionIsolator-COCVfvfr.d.mts} +3 -2
- package/dist/VitestKyselyTransactionIsolator-Cst3vFjb.cjs +2 -1
- package/dist/VitestKyselyTransactionIsolator-Cst3vFjb.cjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator-DYUYVEh9.d.cts +2 -1
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator-BU-jXEhz.mjs +2 -1
- package/dist/VitestObjectionTransactionIsolator-BU-jXEhz.mjs.map +1 -0
- package/dist/VitestObjectionTransactionIsolator-CJ4ds5Qv.d.cts +2 -1
- package/dist/VitestObjectionTransactionIsolator-DzeF4UAq.cjs +2 -1
- package/dist/VitestObjectionTransactionIsolator-DzeF4UAq.cjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-DIM79dCq.d.mts → VitestObjectionTransactionIsolator-b973r9O1.d.mts} +3 -2
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- 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/better-auth.cjs +245 -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 +244 -0
- package/dist/better-auth.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-C-Iuk_R1.d.mts → faker-Br8MzXil.d.mts} +4 -3
- package/dist/{faker-BSH1EMtg.d.cts → faker-Cg76aFNO.d.cts} +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 +65 -2
- 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 +67 -4
- 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 +80 -2
- 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 +82 -4
- 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 +30 -2
- package/src/__tests__/better-auth.spec.ts +21 -0
- package/src/aws.ts +131 -0
- package/src/better-auth.ts +327 -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-C3h7kitU.mjs +0 -67
- package/dist/kysely-VU3MwvMD.cjs +0 -72
- package/dist/objection-BI7F86qf.mjs +0 -82
- package/dist/objection-BpLv_ZfC.cjs +0 -87
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const better_auth_adapters = require_chunk.__toESM(require("better-auth/adapters"));
|
|
3
|
+
|
|
4
|
+
//#region src/better-auth.ts
|
|
5
|
+
var MemoryStore = class {
|
|
6
|
+
constructor(initialData, data = /* @__PURE__ */ new Map()) {
|
|
7
|
+
this.data = data;
|
|
8
|
+
if (initialData) for (const [model, records] of Object.entries(initialData)) {
|
|
9
|
+
const modelData = /* @__PURE__ */ new Map();
|
|
10
|
+
for (const record of records) modelData.set(record.id, { ...record });
|
|
11
|
+
this.data.set(model, modelData);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
getModel(modelName) {
|
|
15
|
+
if (!this.data.has(modelName)) this.data.set(modelName, /* @__PURE__ */ new Map());
|
|
16
|
+
return this.data.get(modelName);
|
|
17
|
+
}
|
|
18
|
+
clear() {
|
|
19
|
+
this.data.clear();
|
|
20
|
+
}
|
|
21
|
+
getAllData() {
|
|
22
|
+
const result = {};
|
|
23
|
+
for (const [model, records] of this.data.entries()) result[model] = Array.from(records.values());
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function matchesWhere(record, where) {
|
|
28
|
+
if (!where || where.length === 0) return true;
|
|
29
|
+
let result = null;
|
|
30
|
+
for (const condition of where) {
|
|
31
|
+
const { field, value, operator = "eq", connector = "AND" } = condition;
|
|
32
|
+
const recordValue = record[field];
|
|
33
|
+
let matches = false;
|
|
34
|
+
switch (operator) {
|
|
35
|
+
case "eq":
|
|
36
|
+
matches = recordValue === value;
|
|
37
|
+
break;
|
|
38
|
+
case "ne":
|
|
39
|
+
matches = recordValue !== value;
|
|
40
|
+
break;
|
|
41
|
+
case "lt":
|
|
42
|
+
matches = recordValue < value;
|
|
43
|
+
break;
|
|
44
|
+
case "lte":
|
|
45
|
+
matches = recordValue <= value;
|
|
46
|
+
break;
|
|
47
|
+
case "gt":
|
|
48
|
+
matches = recordValue > value;
|
|
49
|
+
break;
|
|
50
|
+
case "gte":
|
|
51
|
+
matches = recordValue >= value;
|
|
52
|
+
break;
|
|
53
|
+
case "in":
|
|
54
|
+
matches = Array.isArray(value) && value.includes(recordValue);
|
|
55
|
+
break;
|
|
56
|
+
case "not_in":
|
|
57
|
+
matches = Array.isArray(value) && !value.includes(recordValue);
|
|
58
|
+
break;
|
|
59
|
+
case "contains":
|
|
60
|
+
matches = typeof recordValue === "string" && typeof value === "string" && recordValue.includes(value);
|
|
61
|
+
break;
|
|
62
|
+
case "starts_with":
|
|
63
|
+
matches = typeof recordValue === "string" && typeof value === "string" && recordValue.startsWith(value);
|
|
64
|
+
break;
|
|
65
|
+
case "ends_with":
|
|
66
|
+
matches = typeof recordValue === "string" && typeof value === "string" && recordValue.endsWith(value);
|
|
67
|
+
break;
|
|
68
|
+
default: matches = recordValue === value;
|
|
69
|
+
}
|
|
70
|
+
if (result === null) result = matches;
|
|
71
|
+
else if (connector === "OR") result = result || matches;
|
|
72
|
+
else result = result && matches;
|
|
73
|
+
}
|
|
74
|
+
return result ?? true;
|
|
75
|
+
}
|
|
76
|
+
function applySorting(records, sortBy) {
|
|
77
|
+
if (!sortBy) return records;
|
|
78
|
+
const { field, direction } = sortBy;
|
|
79
|
+
return records.sort((a, b) => {
|
|
80
|
+
const aVal = a[field];
|
|
81
|
+
const bVal = b[field];
|
|
82
|
+
if (aVal === bVal) return 0;
|
|
83
|
+
if (aVal == null) return direction === "asc" ? -1 : 1;
|
|
84
|
+
if (bVal == null) return direction === "asc" ? 1 : -1;
|
|
85
|
+
const comparison = aVal < bVal ? -1 : 1;
|
|
86
|
+
return direction === "asc" ? comparison : -comparison;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const memoryAdapter = (config = {}, store = /* @__PURE__ */ new Map()) => {
|
|
90
|
+
const storeInstance = new MemoryStore(config.initialData, store);
|
|
91
|
+
const adapterInstance = (0, better_auth_adapters.createAdapterFactory)({
|
|
92
|
+
config: {
|
|
93
|
+
adapterId: "memory-adapter",
|
|
94
|
+
adapterName: "Memory Adapter",
|
|
95
|
+
usePlural: config.usePlural ?? false,
|
|
96
|
+
debugLogs: config.debugLogs ?? false,
|
|
97
|
+
supportsJSON: true,
|
|
98
|
+
supportsDates: true,
|
|
99
|
+
supportsBooleans: true,
|
|
100
|
+
supportsNumericIds: false
|
|
101
|
+
},
|
|
102
|
+
adapter: ({ debugLog, transformInput, transformOutput, getModelName, transformWhereClause }) => ({
|
|
103
|
+
create: async ({ data, model, select }) => {
|
|
104
|
+
debugLog("CREATE", {
|
|
105
|
+
model,
|
|
106
|
+
data
|
|
107
|
+
});
|
|
108
|
+
const modelName = getModelName(model);
|
|
109
|
+
const modelData = storeInstance.getModel(modelName);
|
|
110
|
+
const transformedData = await transformInput(data, model, "create");
|
|
111
|
+
if (!transformedData.id) transformedData.id = crypto.randomUUID();
|
|
112
|
+
modelData.set(transformedData.id, {
|
|
113
|
+
...transformedData,
|
|
114
|
+
...data
|
|
115
|
+
});
|
|
116
|
+
if (data.email_address) modelData.set(transformedData.id, {
|
|
117
|
+
...transformedData,
|
|
118
|
+
email: data.email_address
|
|
119
|
+
});
|
|
120
|
+
const created = modelData.get(transformedData.id);
|
|
121
|
+
const out = await transformOutput(created, model, select);
|
|
122
|
+
return out;
|
|
123
|
+
},
|
|
124
|
+
findOne: async ({ where, model, select }) => {
|
|
125
|
+
debugLog("FIND_ONE", {
|
|
126
|
+
model,
|
|
127
|
+
where
|
|
128
|
+
});
|
|
129
|
+
const modelName = getModelName(model);
|
|
130
|
+
const modelData = storeInstance.getModel(modelName);
|
|
131
|
+
const transformedWhere = transformWhereClause({
|
|
132
|
+
model,
|
|
133
|
+
where
|
|
134
|
+
});
|
|
135
|
+
for (const record of modelData.values()) if (matchesWhere(record, transformedWhere)) {
|
|
136
|
+
const t = await transformOutput(record, model, select);
|
|
137
|
+
return t;
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
},
|
|
141
|
+
findMany: async ({ where, model, limit, offset, sortBy, select }) => {
|
|
142
|
+
debugLog("FIND_MANY", {
|
|
143
|
+
model,
|
|
144
|
+
where
|
|
145
|
+
});
|
|
146
|
+
const modelName = getModelName(model);
|
|
147
|
+
const modelData = storeInstance.getModel(modelName);
|
|
148
|
+
const transformedWhere = transformWhereClause({
|
|
149
|
+
model,
|
|
150
|
+
where
|
|
151
|
+
});
|
|
152
|
+
let results = Array.from(modelData.values()).filter((record) => matchesWhere(record, transformedWhere));
|
|
153
|
+
if (sortBy) results = applySorting(results, sortBy);
|
|
154
|
+
if (offset) results = results.slice(offset);
|
|
155
|
+
if (limit) results = results.slice(0, limit);
|
|
156
|
+
return Promise.all(results.map(async (record) => {
|
|
157
|
+
const transformed = await transformOutput(record, model, select);
|
|
158
|
+
return transformed;
|
|
159
|
+
}));
|
|
160
|
+
},
|
|
161
|
+
update: async ({ where, update, model, select }) => {
|
|
162
|
+
debugLog("UPDATE", {
|
|
163
|
+
model,
|
|
164
|
+
where
|
|
165
|
+
});
|
|
166
|
+
const modelName = getModelName(model);
|
|
167
|
+
const modelData = storeInstance.getModel(modelName);
|
|
168
|
+
const transformedWhere = transformWhereClause({
|
|
169
|
+
model,
|
|
170
|
+
where
|
|
171
|
+
});
|
|
172
|
+
for (const [id, record] of modelData.entries()) if (matchesWhere(record, transformedWhere)) {
|
|
173
|
+
const transformedData = await transformInput(update, model, "update");
|
|
174
|
+
const updated = {
|
|
175
|
+
...record,
|
|
176
|
+
...transformedData
|
|
177
|
+
};
|
|
178
|
+
modelData.set(id, updated);
|
|
179
|
+
return transformOutput(updated, model, select);
|
|
180
|
+
}
|
|
181
|
+
return null;
|
|
182
|
+
},
|
|
183
|
+
updateMany: async ({ where, update, model }) => {
|
|
184
|
+
debugLog("UPDATE_MANY", {
|
|
185
|
+
model,
|
|
186
|
+
where
|
|
187
|
+
});
|
|
188
|
+
const modelName = getModelName(model);
|
|
189
|
+
const modelData = storeInstance.getModel(modelName);
|
|
190
|
+
const transformedWhere = transformWhereClause({
|
|
191
|
+
model,
|
|
192
|
+
where
|
|
193
|
+
});
|
|
194
|
+
let count = 0;
|
|
195
|
+
const transformedData = await transformInput(update, model, "update");
|
|
196
|
+
for (const [id, record] of modelData.entries()) if (matchesWhere(record, transformedWhere)) {
|
|
197
|
+
modelData.set(id, {
|
|
198
|
+
...record,
|
|
199
|
+
...transformedData
|
|
200
|
+
});
|
|
201
|
+
count++;
|
|
202
|
+
}
|
|
203
|
+
return count;
|
|
204
|
+
},
|
|
205
|
+
delete: async ({ where, model }) => {
|
|
206
|
+
debugLog("DELETE", {
|
|
207
|
+
model,
|
|
208
|
+
where
|
|
209
|
+
});
|
|
210
|
+
const modelName = getModelName(model);
|
|
211
|
+
const modelData = storeInstance.getModel(modelName);
|
|
212
|
+
for (const [id, record] of modelData.entries()) if (matchesWhere(record, where)) {
|
|
213
|
+
modelData.delete(id);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
deleteMany: async ({ where, model }) => {
|
|
218
|
+
debugLog("DELETE_MANY", {
|
|
219
|
+
model,
|
|
220
|
+
where
|
|
221
|
+
});
|
|
222
|
+
const modelName = getModelName(model);
|
|
223
|
+
const modelData = storeInstance.getModel(modelName);
|
|
224
|
+
const toDelete = [];
|
|
225
|
+
for (const [id, record] of modelData.entries()) if (matchesWhere(record, where)) toDelete.push(id);
|
|
226
|
+
toDelete.forEach((id) => modelData.delete(id));
|
|
227
|
+
return toDelete.length;
|
|
228
|
+
},
|
|
229
|
+
count: async ({ where, model }) => {
|
|
230
|
+
const modelName = getModelName(model);
|
|
231
|
+
const modelData = storeInstance.getModel(modelName);
|
|
232
|
+
return Array.from(modelData.values()).filter((record) => matchesWhere(record, where)).length;
|
|
233
|
+
}
|
|
234
|
+
})
|
|
235
|
+
});
|
|
236
|
+
return Object.assign(adapterInstance, {
|
|
237
|
+
clear: () => store.clear(),
|
|
238
|
+
getAllData: () => storeInstance.getAllData(),
|
|
239
|
+
getStore: () => store
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
//#endregion
|
|
244
|
+
exports.memoryAdapter = memoryAdapter;
|
|
245
|
+
//# sourceMappingURL=better-auth.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"better-auth.cjs","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 = recordValue < value;\n break;\n case 'lte':\n matches = recordValue <= value;\n break;\n case 'gt':\n matches = recordValue > value;\n break;\n case 'gte':\n matches = recordValue >= value;\n break;\n case 'in':\n matches = Array.isArray(value) && value.includes(recordValue);\n break;\n case 'not_in':\n matches = Array.isArray(value) && !value.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, select }) => {\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(async (record) => {\n const transformed = await transformOutput(record, model, select);\n\n return transformed;\n }),\n );\n },\n\n update: async ({ where, update, model, select }) => {\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, select) 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,QAAK,MAAM,UAAU,QACnB,WAAU,IAAI,OAAO,IAAI,EAAE,GAAG,OAAQ,EAAC;AAEzC,QAAK,KAAK,IAAI,OAAO,UAAU;EAChC;CAEJ;CAED,SAASC,WAAqC;AAC5C,OAAK,KAAK,KAAK,IAAI,UAAU,CAC3B,MAAK,KAAK,IAAI,2BAAW,IAAI,MAAM;AAErC,SAAO,KAAK,KAAK,IAAI,UAAU;CAChC;CAED,QAAQ;AACN,OAAK,KAAK,OAAO;CAClB;CAED,aAAa;EACX,MAAMC,SAAgC,CAAE;AACxC,OAAK,MAAM,CAAC,OAAO,QAAQ,IAAI,KAAK,KAAK,SAAS,CAChD,QAAO,SAAS,MAAM,KAAK,QAAQ,QAAQ,CAAC;AAE9C,SAAO;CACR;AACF;AAED,SAAS,aAAaC,QAAaC,OAA0B;AAC3D,MAAK,SAAS,MAAM,WAAW,EAAG,QAAO;CAEzC,IAAIC,SAAyB;AAE7B,MAAK,MAAM,aAAa,OAAO;EAC7B,MAAM,EAAE,OAAO,OAAO,WAAW,MAAM,YAAY,OAAO,GAAG;EAC7D,MAAM,cAAc,OAAO;EAE3B,IAAI,UAAU;AAEd,UAAQ,UAAR;GACE,KAAK;AACH,cAAU,gBAAgB;AAC1B;GACF,KAAK;AACH,cAAU,gBAAgB;AAC1B;GACF,KAAK;AACH,c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import * as better_auth_adapters2 from "better-auth/adapters";
|
|
2
|
+
import { DBAdapterDebugLogOption } from "better-auth/adapters";
|
|
3
|
+
|
|
4
|
+
//#region src/better-auth.d.ts
|
|
5
|
+
interface MemoryAdapterConfig {
|
|
6
|
+
debugLogs?: DBAdapterDebugLogOption;
|
|
7
|
+
usePlural?: boolean;
|
|
8
|
+
initialData?: Record<string, any[]>;
|
|
9
|
+
}
|
|
10
|
+
declare const memoryAdapter: (config?: MemoryAdapterConfig, store?: Map<any, any>) => better_auth_adapters2.AdapterFactory & {
|
|
11
|
+
clear: () => void;
|
|
12
|
+
getAllData: () => Record<string, any[]>;
|
|
13
|
+
getStore: () => Map<any, any>;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { memoryAdapter };
|
|
17
|
+
//# sourceMappingURL=better-auth.d.cts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as better_auth_adapters1 from "better-auth/adapters";
|
|
2
|
+
import { DBAdapterDebugLogOption } from "better-auth/adapters";
|
|
3
|
+
|
|
4
|
+
//#region src/better-auth.d.ts
|
|
5
|
+
interface MemoryAdapterConfig {
|
|
6
|
+
debugLogs?: DBAdapterDebugLogOption;
|
|
7
|
+
usePlural?: boolean;
|
|
8
|
+
initialData?: Record<string, any[]>;
|
|
9
|
+
}
|
|
10
|
+
declare const memoryAdapter: (config?: MemoryAdapterConfig, store?: Map<any, any>) => better_auth_adapters1.AdapterFactory & {
|
|
11
|
+
clear: () => void;
|
|
12
|
+
getAllData: () => Record<string, any[]>;
|
|
13
|
+
getStore: () => Map<any, any>;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { memoryAdapter };
|
|
17
|
+
//# sourceMappingURL=better-auth.d.mts.map
|
|
@@ -0,0 +1,244 @@
|
|
|
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 = recordValue < value;
|
|
42
|
+
break;
|
|
43
|
+
case "lte":
|
|
44
|
+
matches = recordValue <= value;
|
|
45
|
+
break;
|
|
46
|
+
case "gt":
|
|
47
|
+
matches = recordValue > value;
|
|
48
|
+
break;
|
|
49
|
+
case "gte":
|
|
50
|
+
matches = 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, select }) => {
|
|
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(async (record) => {
|
|
156
|
+
const transformed = await transformOutput(record, model, select);
|
|
157
|
+
return transformed;
|
|
158
|
+
}));
|
|
159
|
+
},
|
|
160
|
+
update: async ({ where, update, model, select }) => {
|
|
161
|
+
debugLog("UPDATE", {
|
|
162
|
+
model,
|
|
163
|
+
where
|
|
164
|
+
});
|
|
165
|
+
const modelName = getModelName(model);
|
|
166
|
+
const modelData = storeInstance.getModel(modelName);
|
|
167
|
+
const transformedWhere = transformWhereClause({
|
|
168
|
+
model,
|
|
169
|
+
where
|
|
170
|
+
});
|
|
171
|
+
for (const [id, record] of modelData.entries()) if (matchesWhere(record, transformedWhere)) {
|
|
172
|
+
const transformedData = await transformInput(update, model, "update");
|
|
173
|
+
const updated = {
|
|
174
|
+
...record,
|
|
175
|
+
...transformedData
|
|
176
|
+
};
|
|
177
|
+
modelData.set(id, updated);
|
|
178
|
+
return transformOutput(updated, model, select);
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
},
|
|
182
|
+
updateMany: async ({ where, update, model }) => {
|
|
183
|
+
debugLog("UPDATE_MANY", {
|
|
184
|
+
model,
|
|
185
|
+
where
|
|
186
|
+
});
|
|
187
|
+
const modelName = getModelName(model);
|
|
188
|
+
const modelData = storeInstance.getModel(modelName);
|
|
189
|
+
const transformedWhere = transformWhereClause({
|
|
190
|
+
model,
|
|
191
|
+
where
|
|
192
|
+
});
|
|
193
|
+
let count = 0;
|
|
194
|
+
const transformedData = await transformInput(update, model, "update");
|
|
195
|
+
for (const [id, record] of modelData.entries()) if (matchesWhere(record, transformedWhere)) {
|
|
196
|
+
modelData.set(id, {
|
|
197
|
+
...record,
|
|
198
|
+
...transformedData
|
|
199
|
+
});
|
|
200
|
+
count++;
|
|
201
|
+
}
|
|
202
|
+
return count;
|
|
203
|
+
},
|
|
204
|
+
delete: async ({ where, model }) => {
|
|
205
|
+
debugLog("DELETE", {
|
|
206
|
+
model,
|
|
207
|
+
where
|
|
208
|
+
});
|
|
209
|
+
const modelName = getModelName(model);
|
|
210
|
+
const modelData = storeInstance.getModel(modelName);
|
|
211
|
+
for (const [id, record] of modelData.entries()) if (matchesWhere(record, where)) {
|
|
212
|
+
modelData.delete(id);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
deleteMany: async ({ where, model }) => {
|
|
217
|
+
debugLog("DELETE_MANY", {
|
|
218
|
+
model,
|
|
219
|
+
where
|
|
220
|
+
});
|
|
221
|
+
const modelName = getModelName(model);
|
|
222
|
+
const modelData = storeInstance.getModel(modelName);
|
|
223
|
+
const toDelete = [];
|
|
224
|
+
for (const [id, record] of modelData.entries()) if (matchesWhere(record, where)) toDelete.push(id);
|
|
225
|
+
toDelete.forEach((id) => modelData.delete(id));
|
|
226
|
+
return toDelete.length;
|
|
227
|
+
},
|
|
228
|
+
count: async ({ where, model }) => {
|
|
229
|
+
const modelName = getModelName(model);
|
|
230
|
+
const modelData = storeInstance.getModel(modelName);
|
|
231
|
+
return Array.from(modelData.values()).filter((record) => matchesWhere(record, where)).length;
|
|
232
|
+
}
|
|
233
|
+
})
|
|
234
|
+
});
|
|
235
|
+
return Object.assign(adapterInstance, {
|
|
236
|
+
clear: () => store.clear(),
|
|
237
|
+
getAllData: () => storeInstance.getAllData(),
|
|
238
|
+
getStore: () => store
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
//#endregion
|
|
243
|
+
export { memoryAdapter };
|
|
244
|
+
//# 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 = recordValue < value;\n break;\n case 'lte':\n matches = recordValue <= value;\n break;\n case 'gt':\n matches = recordValue > value;\n break;\n case 'gte':\n matches = recordValue >= value;\n break;\n case 'in':\n matches = Array.isArray(value) && value.includes(recordValue);\n break;\n case 'not_in':\n matches = Array.isArray(value) && !value.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, select }) => {\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(async (record) => {\n const transformed = await transformOutput(record, model, select);\n\n return transformed;\n }),\n );\n },\n\n update: async ({ where, update, model, select }) => {\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, select) 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,QAAK,MAAM,UAAU,QACnB,WAAU,IAAI,OAAO,IAAI,EAAE,GAAG,OAAQ,EAAC;AAEzC,QAAK,KAAK,IAAI,OAAO,UAAU;EAChC;CAEJ;CAED,SAASC,WAAqC;AAC5C,OAAK,KAAK,KAAK,IAAI,UAAU,CAC3B,MAAK,KAAK,IAAI,2BAAW,IAAI,MAAM;AAErC,SAAO,KAAK,KAAK,IAAI,UAAU;CAChC;CAED,QAAQ;AACN,OAAK,KAAK,OAAO;CAClB;CAED,aAAa;EACX,MAAMC,SAAgC,CAAE;AACxC,OAAK,MAAM,CAAC,OAAO,QAAQ,IAAI,KAAK,KAAK,SAAS,CAChD,QAAO,SAAS,MAAM,KAAK,QAAQ,QAAQ,CAAC;AAE9C,SAAO;CACR;AACF;AAED,SAAS,aAAaC,QAAaC,OAA0B;AAC3D,MAAK,SAAS,MAAM,WAAW,EA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AAM,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"}
|
|
@@ -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
|