prisma-mock 1.0.1 → 1.1.0-alpha.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/lib/client.js +5 -2
- package/lib/indexes.d.ts +1 -1
- package/lib/indexes.js +1 -1
- package/lib/utils/shallowCompare.js +10 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -24,7 +24,7 @@ function createPrismaMock(prisma, options = {
|
|
|
24
24
|
}) {
|
|
25
25
|
// Reference object to hold the mock data state
|
|
26
26
|
let ref = {
|
|
27
|
-
data: options.data
|
|
27
|
+
data: options.data ? (0, deepCopy_1.deepCopy)(options.data) : {},
|
|
28
28
|
};
|
|
29
29
|
// Initialize the mock client (either use provided one or create new)
|
|
30
30
|
let client = options.mockClient ? options.mockClient : {};
|
|
@@ -42,7 +42,7 @@ function createPrismaMock(prisma, options = {
|
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
// Create indexes if enabled in options
|
|
45
|
-
const indexes = (0, indexes_1.default)(!!options.enableIndexes
|
|
45
|
+
const indexes = (0, indexes_1.default)(!!options.enableIndexes);
|
|
46
46
|
// Determine if case-insensitive matching should be used
|
|
47
47
|
const caseInsensitive = options.caseInsensitive || false;
|
|
48
48
|
// Mock $transaction method for handling database transactions
|
|
@@ -126,6 +126,9 @@ function createPrismaMock(prisma, options = {
|
|
|
126
126
|
});
|
|
127
127
|
// Add method to access internal state for testing/debugging
|
|
128
128
|
client['$getInternalState'] = () => ref.data;
|
|
129
|
+
client['$clear'] = () => {
|
|
130
|
+
ref.data = options.data ? (0, deepCopy_1.deepCopy)(options.data) : {};
|
|
131
|
+
};
|
|
129
132
|
// @ts-ignore
|
|
130
133
|
return client;
|
|
131
134
|
}
|
package/lib/indexes.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { Prisma } from "@prisma/client";
|
|
|
7
7
|
* @param isEnabled - Whether indexing is enabled. When false, all operations are no-ops.
|
|
8
8
|
* @returns Object containing methods for managing indexes and performing indexed lookups
|
|
9
9
|
*/
|
|
10
|
-
export default function createIndexes(isEnabled
|
|
10
|
+
export default function createIndexes(isEnabled?: boolean): {
|
|
11
11
|
addIndexFieldIfNeeded: (tableName: string, field: Prisma.DMMF.Field, isPrimary: boolean) => void;
|
|
12
12
|
getIndexedItems: (tableName: string, where: any) => any;
|
|
13
13
|
updateItem: (tableName: string, item: any, oldItem: any | null) => void;
|
package/lib/indexes.js
CHANGED
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
8
8
|
* @param isEnabled - Whether indexing is enabled. When false, all operations are no-ops.
|
|
9
9
|
* @returns Object containing methods for managing indexes and performing indexed lookups
|
|
10
10
|
*/
|
|
11
|
-
function createIndexes(isEnabled = true
|
|
11
|
+
function createIndexes(isEnabled = true) {
|
|
12
12
|
// Main data structures for storing indexed data
|
|
13
13
|
// items: tableName -> fieldName -> fieldValue -> array of items with that value
|
|
14
14
|
let items = {};
|
|
@@ -2,7 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.shallowCompare = void 0;
|
|
4
4
|
const shallowCompare = (a, b) => {
|
|
5
|
+
// if (Object.keys(a).length !== Object.keys(b).length) return false
|
|
5
6
|
for (let key in b) {
|
|
7
|
+
if (a[key] instanceof Date) {
|
|
8
|
+
if (b[key] === undefined) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (!(b[key] instanceof Date) || b[key].getTime() !== a[key].getTime()) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
6
16
|
if (a[key] !== b[key])
|
|
7
17
|
return false;
|
|
8
18
|
}
|