prisma-mock 0.0.31 → 0.0.34

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 De Monsters
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -104,8 +104,8 @@ Alot of the functionality is implemented, but parts are missing. Here is a list
104
104
  - distinct
105
105
  - include
106
106
  - where
107
- - TODO: select
108
- - TODO: orderBy
107
+ - select
108
+ - orderBy
109
109
  - TODO: select: _count
110
110
 
111
111
  ## Nested queries
package/lib/index.js CHANGED
@@ -179,7 +179,20 @@ const createPrismaMock = async (data = {}, pathToSchema, client = (0, jest_mock_
179
179
  }
180
180
  }
181
181
  if (c.disconnect) {
182
- d = Object.assign(Object.assign({}, d), { [field.relationFromFields[0]]: null });
182
+ if (field.relationFromFields.length > 0) {
183
+ d = Object.assign(Object.assign({}, d), { [field.relationFromFields[0]]: null });
184
+ }
185
+ else {
186
+ const joinfield = getJoinField(field);
187
+ delegate.update({
188
+ data: {
189
+ [joinfield.relationFromFields[0]]: null
190
+ },
191
+ where: {
192
+ [joinfield.relationFromFields[0]]: item[joinfield.relationToFields[0]]
193
+ }
194
+ });
195
+ }
183
196
  }
184
197
  const _e = d, _f = field.name, _update = _e[_f], rest = __rest(_e, [typeof _f === "symbol" ? _f : _f + ""]);
185
198
  d = rest;
@@ -401,6 +414,21 @@ const createPrismaMock = async (data = {}, pathToSchema, client = (0, jest_mock_
401
414
  return shouldInclude;
402
415
  });
403
416
  }
417
+ if (args === null || args === void 0 ? void 0 : args.orderBy) {
418
+ const keys = Object.keys(args.orderBy);
419
+ res.sort((a, b) => {
420
+ for (const key of keys) {
421
+ const dir = args.orderBy[key];
422
+ if (a[key] > b[key]) {
423
+ return dir === "asc" ? 1 : -1;
424
+ }
425
+ else if (a[key] < b[key]) {
426
+ return dir === "asc" ? -1 : 1;
427
+ }
428
+ }
429
+ return 0;
430
+ });
431
+ }
404
432
  if (args === null || args === void 0 ? void 0 : args.select) {
405
433
  return res.map(item => {
406
434
  const newItem = {};
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "prisma-mock",
3
- "version": "0.0.31",
3
+ "version": "0.0.34",
4
4
  "description": "Mock prisma for unit testing database",
5
5
  "main": "lib/index.js",
6
+ "repository": "https://github.com/demonsters/prisma-mock",
6
7
  "license": "MIT",
7
8
  "types": "lib/",
8
9
  "files": [