vsrepo 2.5.0 → 2.6.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/CHANGELOG.md +587 -531
- package/LICENSE +20 -20
- package/README.md +220 -1243
- package/README.pt-BR.md +220 -1246
- package/dist/VSRepoAdapter.js.map +1 -1
- package/dist/VSRepository.d.ts +43 -1
- package/dist/VSRepository.js +61 -9
- package/dist/VSRepository.js.map +1 -1
- package/dist/decorators/dynamic-method.decorator.d.ts +1 -1
- package/dist/decorators/dynamic-method.decorator.js +2 -4
- package/dist/decorators/dynamic-method.decorator.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/enums/vsrepo-error-type.enum.d.ts +3 -1
- package/dist/internal/enums/vsrepo-error-type.enum.js +2 -0
- package/dist/internal/enums/vsrepo-error-type.enum.js.map +1 -1
- package/dist/internal/resolvers/dynamic-methods.resolver.d.ts +5 -0
- package/dist/internal/resolvers/dynamic-methods.resolver.js +163 -98
- package/dist/internal/resolvers/dynamic-methods.resolver.js.map +1 -1
- package/dist/internal/utils/vs-logger.util.js.map +1 -1
- package/dist/internal/utils/vs-query-builder.util.d.ts +235 -0
- package/dist/internal/utils/vs-query-builder.util.js +413 -0
- package/dist/internal/utils/vs-query-builder.util.js.map +1 -0
- package/dist/internal/utils/with-db.util.js.map +1 -1
- package/dist/internal/validators/decorators.validator.js +2 -6
- package/dist/internal/validators/decorators.validator.js.map +1 -1
- package/dist/internal/validators/schemas/pagination.schema.d.ts +2 -2
- package/dist/internal/validators/schemas/pagination.schema.js +2 -2
- package/dist/internal/validators/schemas/pagination.schema.js.map +1 -1
- package/dist/internal/validators/schemas/relations.schema.d.ts +4 -0
- package/dist/internal/validators/schemas/relations.schema.js +39 -0
- package/dist/internal/validators/schemas/relations.schema.js.map +1 -0
- package/dist/internal/validators/schemas/see-mode.schema.d.ts +3 -0
- package/dist/internal/validators/schemas/see-mode.schema.js +38 -0
- package/dist/internal/validators/schemas/see-mode.schema.js.map +1 -0
- package/dist/internal/validators/schemas/select.schema.d.ts +4 -0
- package/dist/internal/validators/schemas/select.schema.js +39 -0
- package/dist/internal/validators/schemas/select.schema.js.map +1 -0
- package/dist/internal/validators/vsrepo.validator.js +6 -5
- package/dist/internal/validators/vsrepo.validator.js.map +1 -1
- package/dist/types/dynamic-methods/dynamic-method-info.type.d.ts +1 -0
- package/dist/types/utils/query-args.type.d.ts +1 -4
- package/dist/types/vsrepo/vsrepo-options.type.d.ts +9 -0
- package/package.json +87 -80
|
@@ -26,6 +26,55 @@ class DynamicMethodsResolver {
|
|
|
26
26
|
this.validator = validator;
|
|
27
27
|
this.defaultOrdering = defaultOrdering;
|
|
28
28
|
}
|
|
29
|
+
keywordTemplate = (keyword, allowAtTheEnd = false) => new RegExp(`${keyword}(?=[\\p{Lu}]|[^\\p{ASCII}]${allowAtTheEnd ? "|$" : ""})`, "u");
|
|
30
|
+
fieldModifiers = {
|
|
31
|
+
IsNull: this.keywordTemplate("IsNull", true),
|
|
32
|
+
IsNotNull: this.keywordTemplate("IsNotNull", true),
|
|
33
|
+
IsTrue: this.keywordTemplate("IsTrue", true),
|
|
34
|
+
IsFalse: this.keywordTemplate("IsFalse", true),
|
|
35
|
+
IgnoreCase: this.keywordTemplate("IgnoreCase", true),
|
|
36
|
+
Optional: this.keywordTemplate("Optional", true),
|
|
37
|
+
NotBetween: this.keywordTemplate("NotBetween", true),
|
|
38
|
+
Between: this.keywordTemplate("Between", true),
|
|
39
|
+
NotStartsWith: this.keywordTemplate("NotStartsWith", true),
|
|
40
|
+
StartsWith: this.keywordTemplate("StartsWith", true),
|
|
41
|
+
NotEndsWith: this.keywordTemplate("NotEndsWith", true),
|
|
42
|
+
EndsWith: this.keywordTemplate("EndsWith", true),
|
|
43
|
+
NotContains: this.keywordTemplate("NotContains", true),
|
|
44
|
+
Contains: this.keywordTemplate("Contains", true),
|
|
45
|
+
LessThanEqual: this.keywordTemplate("LessThanEqual", true),
|
|
46
|
+
LessThan: this.keywordTemplate("LessThan", true),
|
|
47
|
+
GreaterThanEqual: this.keywordTemplate("GreaterThanEqual", true),
|
|
48
|
+
GreaterThan: this.keywordTemplate("GreaterThan", true),
|
|
49
|
+
NotIn: this.keywordTemplate("NotIn", true),
|
|
50
|
+
In: this.keywordTemplate("In", true),
|
|
51
|
+
Not: this.keywordTemplate("Not", true),
|
|
52
|
+
Equals: this.keywordTemplate("Equals", true),
|
|
53
|
+
NotEquals: this.keywordTemplate("NotEquals", true),
|
|
54
|
+
Without: this.keywordTemplate("Without", true),
|
|
55
|
+
With: this.keywordTemplate("With", true),
|
|
56
|
+
Some: this.keywordTemplate("Some", true),
|
|
57
|
+
Every: this.keywordTemplate("Every", true),
|
|
58
|
+
None: this.keywordTemplate("None", true),
|
|
59
|
+
};
|
|
60
|
+
operators = {
|
|
61
|
+
And: this.keywordTemplate("And"),
|
|
62
|
+
Or: this.keywordTemplate("Or"),
|
|
63
|
+
AND: this.keywordTemplate("AND"),
|
|
64
|
+
};
|
|
65
|
+
customizationModifiers = {
|
|
66
|
+
Distinct: this.keywordTemplate("Distinct"),
|
|
67
|
+
OrderBy: this.keywordTemplate("OrderBy"),
|
|
68
|
+
PaginatedAndOrdered: /PaginatedAndOrdered$/,
|
|
69
|
+
OrderedAndPaginated: /OrderedAndPaginated$/,
|
|
70
|
+
Paginated: /Paginated$/,
|
|
71
|
+
Ordered: /Ordered$/,
|
|
72
|
+
IgnoreConflicts: /IgnoreConflicts$/,
|
|
73
|
+
};
|
|
74
|
+
logAndThrowError(errorMessage) {
|
|
75
|
+
this.logger.logError(errorMessage);
|
|
76
|
+
throw new VSRepoError_1.VSRepoError(errorMessage, vsrepo_error_type_enum_1.VSRepoErrorType.RESOLVER);
|
|
77
|
+
}
|
|
29
78
|
validateIndexedArg(args, positionIndex, validate, parseDebugToString = true) {
|
|
30
79
|
const value = args.at(positionIndex);
|
|
31
80
|
if (value === debug_arg_symbol_constant_1.DEBUG_ARG_SYMBOL) {
|
|
@@ -49,6 +98,7 @@ class DynamicMethodsResolver {
|
|
|
49
98
|
ignoreDistinct: true,
|
|
50
99
|
whereParams: [],
|
|
51
100
|
otherParams: [],
|
|
101
|
+
originalDynamicMethodName: dynamicMethod,
|
|
52
102
|
};
|
|
53
103
|
if (dynamicMethod.startsWith("findOneBy")) {
|
|
54
104
|
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("findOneBy", "");
|
|
@@ -61,14 +111,6 @@ class DynamicMethodsResolver {
|
|
|
61
111
|
dynamicMethodInfo.ignoreDistinct = false;
|
|
62
112
|
dynamicMethodInfo.method = "findMany";
|
|
63
113
|
}
|
|
64
|
-
// else if (dynamicMethod === "groupBy") {
|
|
65
|
-
// dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("groupBy", "");
|
|
66
|
-
// dynamicMethodInfo.ignoreSelect = true;
|
|
67
|
-
// dynamicMethodInfo.ignoreWhere = true;
|
|
68
|
-
// dynamicMethodInfo.method = "groupBy";
|
|
69
|
-
// dynamicMethodInfo.otherParams.push("prismaArgs"); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
70
|
-
// dynamicMethodInfo.argsCount++;
|
|
71
|
-
// }
|
|
72
114
|
else if (dynamicMethod.startsWith("findOneOrThrowBy")) {
|
|
73
115
|
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("findOneOrThrowBy", "");
|
|
74
116
|
dynamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
@@ -302,59 +344,63 @@ class DynamicMethodsResolver {
|
|
|
302
344
|
dynamicMethodInfo.method = "findOne";
|
|
303
345
|
}
|
|
304
346
|
else {
|
|
305
|
-
|
|
306
|
-
this.logger.logError(errorMessage);
|
|
307
|
-
throw new VSRepoError_1.VSRepoError(errorMessage, vsrepo_error_type_enum_1.VSRepoErrorType.RESOLVER);
|
|
347
|
+
this.logAndThrowError(`Unknown dynamic method: ${dynamicMethod}.`);
|
|
308
348
|
}
|
|
309
349
|
return dynamicMethodInfo;
|
|
310
350
|
}
|
|
311
351
|
resolveDynamicMethodCustomization(dynamicMethodInfo, methodData) {
|
|
312
352
|
const dynamicMethodCustomization = {};
|
|
313
353
|
if (!dynamicMethodInfo.ignoreIgnoreConflicts) {
|
|
314
|
-
if (dynamicMethodInfo.keyToMapReplaced
|
|
315
|
-
dynamicMethodInfo.keyToMapReplaced = dynamicMethodInfo.keyToMapReplaced.replace(
|
|
354
|
+
if (this.customizationModifiers.IgnoreConflicts.test(dynamicMethodInfo.keyToMapReplaced)) {
|
|
355
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethodInfo.keyToMapReplaced.replace(this.customizationModifiers.IgnoreConflicts, "");
|
|
316
356
|
dynamicMethodCustomization.ignoreConflicts = true;
|
|
317
357
|
}
|
|
318
358
|
}
|
|
359
|
+
else if (this.customizationModifiers.IgnoreConflicts.test(dynamicMethodInfo.keyToMapReplaced)) {
|
|
360
|
+
this.logAndThrowError(`This dynamic method prefix doesn't support the "IgnoreConflicts" modifier: ${dynamicMethodInfo.originalDynamicMethodName}.`);
|
|
361
|
+
}
|
|
319
362
|
if (!dynamicMethodInfo.ignoreOrderByAndPagination) {
|
|
320
|
-
if (dynamicMethodInfo.keyToMapReplaced
|
|
363
|
+
if (this.customizationModifiers.PaginatedAndOrdered.test(dynamicMethodInfo.keyToMapReplaced)) {
|
|
321
364
|
dynamicMethodCustomization.orderPosition = -2;
|
|
322
365
|
dynamicMethodCustomization.paginationPosition = -3;
|
|
323
366
|
dynamicMethodInfo.otherParams.push("pagination");
|
|
324
367
|
dynamicMethodInfo.otherParams.push("order");
|
|
325
|
-
dynamicMethodInfo.keyToMapReplaced = dynamicMethodInfo.keyToMapReplaced.replace(
|
|
368
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethodInfo.keyToMapReplaced.replace(this.customizationModifiers.PaginatedAndOrdered, "");
|
|
326
369
|
dynamicMethodInfo.argsCount += 2;
|
|
327
370
|
}
|
|
328
|
-
else if (dynamicMethodInfo.keyToMapReplaced
|
|
371
|
+
else if (this.customizationModifiers.OrderedAndPaginated.test(dynamicMethodInfo.keyToMapReplaced)) {
|
|
329
372
|
dynamicMethodCustomization.orderPosition = -3;
|
|
330
373
|
dynamicMethodCustomization.paginationPosition = -2;
|
|
331
374
|
dynamicMethodInfo.otherParams.push("order");
|
|
332
375
|
dynamicMethodInfo.otherParams.push("pagination");
|
|
333
|
-
dynamicMethodInfo.keyToMapReplaced = dynamicMethodInfo.keyToMapReplaced.replace(
|
|
376
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethodInfo.keyToMapReplaced.replace(this.customizationModifiers.OrderedAndPaginated, "");
|
|
334
377
|
dynamicMethodInfo.argsCount += 2;
|
|
335
378
|
}
|
|
336
|
-
else if (dynamicMethodInfo.keyToMapReplaced
|
|
379
|
+
else if (this.customizationModifiers.Paginated.test(dynamicMethodInfo.keyToMapReplaced)) {
|
|
337
380
|
dynamicMethodCustomization.paginationPosition = -2;
|
|
338
381
|
dynamicMethodInfo.otherParams.push("pagination");
|
|
339
|
-
dynamicMethodInfo.keyToMapReplaced = dynamicMethodInfo.keyToMapReplaced.replace(
|
|
382
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethodInfo.keyToMapReplaced.replace(this.customizationModifiers.Paginated, "");
|
|
340
383
|
dynamicMethodInfo.argsCount++;
|
|
341
384
|
}
|
|
342
|
-
else if (dynamicMethodInfo.keyToMapReplaced
|
|
385
|
+
else if (this.customizationModifiers.Ordered.test(dynamicMethodInfo.keyToMapReplaced)) {
|
|
343
386
|
dynamicMethodCustomization.orderPosition = -2;
|
|
344
387
|
dynamicMethodInfo.otherParams.push("order");
|
|
345
|
-
dynamicMethodInfo.keyToMapReplaced = dynamicMethodInfo.keyToMapReplaced.replace(
|
|
388
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethodInfo.keyToMapReplaced.replace(this.customizationModifiers.Ordered, "");
|
|
346
389
|
dynamicMethodInfo.argsCount++;
|
|
347
390
|
}
|
|
348
|
-
const keySplitedOrderBy = dynamicMethodInfo.keyToMapReplaced.split(
|
|
391
|
+
const keySplitedOrderBy = dynamicMethodInfo.keyToMapReplaced.split(this.customizationModifiers.OrderBy);
|
|
349
392
|
if (keySplitedOrderBy[1]) {
|
|
350
|
-
|
|
393
|
+
if (this.customizationModifiers.Distinct.test(keySplitedOrderBy[1])) {
|
|
394
|
+
this.logAndThrowError(`The "Distinct" modifier cannot appear after the "OrderBy" modifier: ${dynamicMethodInfo.originalDynamicMethodName}.`);
|
|
395
|
+
}
|
|
396
|
+
const orderByFields = keySplitedOrderBy[1].split(this.operators.And).map(uncapitalize_util_1.uncapitalize);
|
|
351
397
|
dynamicMethodCustomization.injectOrdering = orderByFields.map(field => {
|
|
352
398
|
if (field.endsWith("Asc")) {
|
|
353
|
-
field = field.replace(
|
|
399
|
+
field = field.replace(/Asc$/, "");
|
|
354
400
|
return { [field]: "ASC" };
|
|
355
401
|
}
|
|
356
402
|
else if (field.endsWith("Desc")) {
|
|
357
|
-
field = field.replace(
|
|
403
|
+
field = field.replace(/Desc$/, "");
|
|
358
404
|
return { [field]: "DESC" };
|
|
359
405
|
}
|
|
360
406
|
return { [field]: "ASC" };
|
|
@@ -363,119 +409,135 @@ class DynamicMethodsResolver {
|
|
|
363
409
|
dynamicMethodInfo.keyToMapReplaced = keySplitedOrderBy[0];
|
|
364
410
|
dynamicMethodCustomization.injectOrdering ??= methodData.injectOrdering;
|
|
365
411
|
}
|
|
412
|
+
else if (this.customizationModifiers.Paginated.test(dynamicMethodInfo.keyToMapReplaced) ||
|
|
413
|
+
this.customizationModifiers.Ordered.test(dynamicMethodInfo.keyToMapReplaced) ||
|
|
414
|
+
this.customizationModifiers.OrderBy.test(dynamicMethodInfo.keyToMapReplaced)) {
|
|
415
|
+
this.logAndThrowError(`This dynamic method prefix doesn't support the ordering or pagination modifiers: ${dynamicMethodInfo.originalDynamicMethodName}.`);
|
|
416
|
+
}
|
|
366
417
|
if (!dynamicMethodInfo.ignoreDistinct) {
|
|
367
|
-
const keySplitedDistinct = dynamicMethodInfo.keyToMapReplaced.split(
|
|
418
|
+
const keySplitedDistinct = dynamicMethodInfo.keyToMapReplaced.split(this.customizationModifiers.Distinct);
|
|
368
419
|
if (keySplitedDistinct[1]) {
|
|
369
420
|
dynamicMethodCustomization.distinctKeys = keySplitedDistinct[1]
|
|
370
|
-
.split(
|
|
421
|
+
.split(this.operators.And)
|
|
371
422
|
.map(uncapitalize_util_1.uncapitalize);
|
|
372
423
|
}
|
|
373
424
|
dynamicMethodInfo.keyToMapReplaced = keySplitedDistinct[0];
|
|
374
425
|
}
|
|
426
|
+
else if (this.customizationModifiers.Distinct.test(dynamicMethodInfo.keyToMapReplaced)) {
|
|
427
|
+
this.logAndThrowError(`This dynamic method prefix doesn't support the "Distinct" modifier: ${dynamicMethodInfo.originalDynamicMethodName}.`);
|
|
428
|
+
}
|
|
375
429
|
return dynamicMethodCustomization;
|
|
376
430
|
}
|
|
377
431
|
resolveUglyWhere(keySplitedAnd) {
|
|
378
432
|
const uglyWhere = { name: "", pushProperty: "$$$" };
|
|
379
433
|
let nullMode = undefined;
|
|
380
|
-
if (
|
|
434
|
+
if (this.fieldModifiers.IsNull.test(keySplitedAnd)) {
|
|
381
435
|
uglyWhere.pushProperty = "$$$";
|
|
382
436
|
uglyWhere.autoInjectVal = null;
|
|
383
437
|
nullMode = "is";
|
|
384
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
438
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.IsNull, "");
|
|
385
439
|
}
|
|
386
|
-
else if (
|
|
440
|
+
else if (this.fieldModifiers.IsNotNull.test(keySplitedAnd)) {
|
|
387
441
|
uglyWhere.pushProperty = "not";
|
|
388
442
|
uglyWhere.autoInjectVal = null;
|
|
389
443
|
nullMode = "not";
|
|
390
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
444
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.IsNotNull, "");
|
|
391
445
|
}
|
|
392
|
-
else if (
|
|
446
|
+
else if (this.fieldModifiers.IsTrue.test(keySplitedAnd)) {
|
|
393
447
|
uglyWhere.pushProperty = "$$$";
|
|
394
448
|
uglyWhere.autoInjectVal = true;
|
|
395
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
449
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.IsTrue, "");
|
|
396
450
|
}
|
|
397
|
-
else if (
|
|
451
|
+
else if (this.fieldModifiers.IsFalse.test(keySplitedAnd)) {
|
|
398
452
|
uglyWhere.pushProperty = "$$$";
|
|
399
453
|
uglyWhere.autoInjectVal = false;
|
|
400
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
454
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.IsFalse, "");
|
|
401
455
|
}
|
|
402
456
|
else {
|
|
403
|
-
if (
|
|
457
|
+
if (this.fieldModifiers.IgnoreCase.test(keySplitedAnd)) {
|
|
404
458
|
uglyWhere.properties = {};
|
|
405
459
|
uglyWhere.properties.ignoreCase = true;
|
|
406
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
460
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.IgnoreCase, "");
|
|
407
461
|
}
|
|
408
|
-
if (
|
|
409
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
462
|
+
if (this.fieldModifiers.Optional.test(keySplitedAnd)) {
|
|
463
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.Optional, "");
|
|
410
464
|
}
|
|
411
|
-
if (
|
|
465
|
+
if (this.fieldModifiers.NotBetween.test(keySplitedAnd)) {
|
|
412
466
|
uglyWhere.pushProperty = "not";
|
|
413
467
|
uglyWhere.betweenMode = true;
|
|
414
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
468
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.NotBetween, "");
|
|
415
469
|
}
|
|
416
|
-
else if (
|
|
470
|
+
else if (this.fieldModifiers.Between.test(keySplitedAnd)) {
|
|
417
471
|
uglyWhere.pushProperty = "$$$";
|
|
418
472
|
uglyWhere.betweenMode = true;
|
|
419
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
473
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.Between, "");
|
|
420
474
|
}
|
|
421
|
-
else if (
|
|
475
|
+
else if (this.fieldModifiers.NotStartsWith.test(keySplitedAnd)) {
|
|
422
476
|
uglyWhere.pushProperty = "not.startsWith";
|
|
423
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
477
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.NotStartsWith, "");
|
|
424
478
|
}
|
|
425
|
-
else if (
|
|
479
|
+
else if (this.fieldModifiers.StartsWith.test(keySplitedAnd)) {
|
|
426
480
|
uglyWhere.pushProperty = "startsWith";
|
|
427
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
481
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.StartsWith, "");
|
|
428
482
|
}
|
|
429
|
-
else if (
|
|
483
|
+
else if (this.fieldModifiers.NotEndsWith.test(keySplitedAnd)) {
|
|
430
484
|
uglyWhere.pushProperty = "not.endsWith";
|
|
431
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
485
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.NotEndsWith, "");
|
|
432
486
|
}
|
|
433
|
-
else if (
|
|
487
|
+
else if (this.fieldModifiers.EndsWith.test(keySplitedAnd)) {
|
|
434
488
|
uglyWhere.pushProperty = "endsWith";
|
|
435
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
489
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.EndsWith, "");
|
|
436
490
|
}
|
|
437
|
-
else if (
|
|
491
|
+
else if (this.fieldModifiers.NotContains.test(keySplitedAnd)) {
|
|
438
492
|
uglyWhere.pushProperty = "not.contains";
|
|
439
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
493
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.NotContains, "");
|
|
440
494
|
}
|
|
441
|
-
else if (
|
|
495
|
+
else if (this.fieldModifiers.Contains.test(keySplitedAnd)) {
|
|
442
496
|
uglyWhere.pushProperty = "contains";
|
|
443
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
497
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.Contains, "");
|
|
498
|
+
}
|
|
499
|
+
else if (this.fieldModifiers.NotEquals.test(keySplitedAnd)) {
|
|
500
|
+
uglyWhere.pushProperty = "not";
|
|
501
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.NotEquals, "");
|
|
444
502
|
}
|
|
445
|
-
else if (
|
|
503
|
+
else if (this.fieldModifiers.Equals.test(keySplitedAnd)) {
|
|
504
|
+
uglyWhere.pushProperty = "$$$";
|
|
505
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.Equals, "");
|
|
506
|
+
}
|
|
507
|
+
else if (this.fieldModifiers.LessThanEqual.test(keySplitedAnd)) {
|
|
446
508
|
uglyWhere.pushProperty = "lte";
|
|
447
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
509
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.LessThanEqual, "");
|
|
448
510
|
}
|
|
449
|
-
else if (
|
|
511
|
+
else if (this.fieldModifiers.LessThan.test(keySplitedAnd)) {
|
|
450
512
|
uglyWhere.pushProperty = "lt";
|
|
451
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
513
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.LessThan, "");
|
|
452
514
|
}
|
|
453
|
-
else if (
|
|
515
|
+
else if (this.fieldModifiers.GreaterThanEqual.test(keySplitedAnd)) {
|
|
454
516
|
uglyWhere.pushProperty = "gte";
|
|
455
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
517
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.GreaterThanEqual, "");
|
|
456
518
|
}
|
|
457
|
-
else if (
|
|
519
|
+
else if (this.fieldModifiers.GreaterThan.test(keySplitedAnd)) {
|
|
458
520
|
uglyWhere.pushProperty = "gt";
|
|
459
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
521
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.GreaterThan, "");
|
|
460
522
|
}
|
|
461
|
-
else if (
|
|
523
|
+
else if (this.fieldModifiers.NotIn.test(keySplitedAnd)) {
|
|
462
524
|
uglyWhere.pushProperty = "notIn";
|
|
463
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
525
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.NotIn, "");
|
|
464
526
|
}
|
|
465
|
-
else if (
|
|
527
|
+
else if (this.fieldModifiers.In.test(keySplitedAnd)) {
|
|
466
528
|
uglyWhere.pushProperty = "in";
|
|
467
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
529
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.In, "");
|
|
468
530
|
}
|
|
469
|
-
else if (
|
|
531
|
+
else if (this.fieldModifiers.Not.test(keySplitedAnd)) {
|
|
470
532
|
uglyWhere.pushProperty = "not";
|
|
471
|
-
keySplitedAnd = keySplitedAnd.replace(
|
|
533
|
+
keySplitedAnd = keySplitedAnd.replace(this.fieldModifiers.Not, "");
|
|
472
534
|
}
|
|
473
535
|
else {
|
|
474
536
|
uglyWhere.pushProperty = "$$$";
|
|
475
537
|
}
|
|
476
538
|
}
|
|
477
|
-
if (
|
|
478
|
-
const keySplitedConector = keySplitedAnd.split(
|
|
539
|
+
if (this.fieldModifiers.Without.test(keySplitedAnd)) {
|
|
540
|
+
const keySplitedConector = keySplitedAnd.split(this.fieldModifiers.Without);
|
|
479
541
|
const specificField = keySplitedConector[1];
|
|
480
542
|
if (!specificField) {
|
|
481
543
|
if (nullMode) {
|
|
@@ -487,12 +549,12 @@ class DynamicMethodsResolver {
|
|
|
487
549
|
}
|
|
488
550
|
}
|
|
489
551
|
else {
|
|
490
|
-
uglyWhere.pushProperty = `_without.${(0, uncapitalize_util_1.uncapitalize)(specificField)}${uglyWhere.pushProperty === "$$$" ? "" : `.${uglyWhere.pushProperty}`}`;
|
|
552
|
+
uglyWhere.pushProperty = `_without.${(0, uncapitalize_util_1.uncapitalize)(specificField)}${uglyWhere.pushProperty === "$$$" ? (uglyWhere.properties ? ".equals" : "") : `.${uglyWhere.pushProperty}`}`;
|
|
491
553
|
}
|
|
492
554
|
keySplitedAnd = keySplitedConector[0];
|
|
493
555
|
}
|
|
494
|
-
else if (
|
|
495
|
-
const keySplitedConector = keySplitedAnd.split(
|
|
556
|
+
else if (this.fieldModifiers.With.test(keySplitedAnd)) {
|
|
557
|
+
const keySplitedConector = keySplitedAnd.split(this.fieldModifiers.With);
|
|
496
558
|
const specificField = keySplitedConector[1];
|
|
497
559
|
if (!specificField) {
|
|
498
560
|
if (nullMode) {
|
|
@@ -504,43 +566,43 @@ class DynamicMethodsResolver {
|
|
|
504
566
|
}
|
|
505
567
|
}
|
|
506
568
|
else {
|
|
507
|
-
uglyWhere.pushProperty = `_with.${(0, uncapitalize_util_1.uncapitalize)(specificField)}${uglyWhere.pushProperty === "$$$" ? "" : `.${uglyWhere.pushProperty}`}`;
|
|
569
|
+
uglyWhere.pushProperty = `_with.${(0, uncapitalize_util_1.uncapitalize)(specificField)}${uglyWhere.pushProperty === "$$$" ? (uglyWhere.properties ? ".equals" : "") : `.${uglyWhere.pushProperty}`}`;
|
|
508
570
|
}
|
|
509
571
|
keySplitedAnd = keySplitedConector[0];
|
|
510
572
|
}
|
|
511
|
-
else if (
|
|
512
|
-
const keySplitedConector = keySplitedAnd.split(
|
|
573
|
+
else if (this.fieldModifiers.Some.test(keySplitedAnd)) {
|
|
574
|
+
const keySplitedConector = keySplitedAnd.split(this.fieldModifiers.Some);
|
|
513
575
|
const specificField = keySplitedConector[1];
|
|
514
576
|
if (!specificField) {
|
|
515
577
|
uglyWhere.pushProperty = "_some";
|
|
516
578
|
uglyWhere.autoInjectVal = {};
|
|
517
579
|
}
|
|
518
580
|
else {
|
|
519
|
-
uglyWhere.pushProperty = `_some.${(0, uncapitalize_util_1.uncapitalize)(specificField)}${uglyWhere.pushProperty === "$$$" ? "" : `.${uglyWhere.pushProperty}`}`;
|
|
581
|
+
uglyWhere.pushProperty = `_some.${(0, uncapitalize_util_1.uncapitalize)(specificField)}${uglyWhere.pushProperty === "$$$" ? (uglyWhere.properties ? ".equals" : "") : `.${uglyWhere.pushProperty}`}`;
|
|
520
582
|
}
|
|
521
583
|
keySplitedAnd = keySplitedConector[0];
|
|
522
584
|
}
|
|
523
|
-
else if (
|
|
524
|
-
const keySplitedConector = keySplitedAnd.split(
|
|
585
|
+
else if (this.fieldModifiers.Every.test(keySplitedAnd)) {
|
|
586
|
+
const keySplitedConector = keySplitedAnd.split(this.fieldModifiers.Every);
|
|
525
587
|
const specificField = keySplitedConector[1];
|
|
526
588
|
if (!specificField) {
|
|
527
589
|
uglyWhere.pushProperty = "_every";
|
|
528
590
|
uglyWhere.autoInjectVal = {};
|
|
529
591
|
}
|
|
530
592
|
else {
|
|
531
|
-
uglyWhere.pushProperty = `_every.${(0, uncapitalize_util_1.uncapitalize)(specificField)}${uglyWhere.pushProperty === "$$$" ? "" : `.${uglyWhere.pushProperty}`}`;
|
|
593
|
+
uglyWhere.pushProperty = `_every.${(0, uncapitalize_util_1.uncapitalize)(specificField)}${uglyWhere.pushProperty === "$$$" ? (uglyWhere.properties ? ".equals" : "") : `.${uglyWhere.pushProperty}`}`;
|
|
532
594
|
}
|
|
533
595
|
keySplitedAnd = keySplitedConector[0];
|
|
534
596
|
}
|
|
535
|
-
else if (
|
|
536
|
-
const keySplitedConector = keySplitedAnd.split(
|
|
597
|
+
else if (this.fieldModifiers.None.test(keySplitedAnd)) {
|
|
598
|
+
const keySplitedConector = keySplitedAnd.split(this.fieldModifiers.None);
|
|
537
599
|
const specificField = keySplitedConector[1];
|
|
538
600
|
if (!specificField) {
|
|
539
601
|
uglyWhere.pushProperty = "_none";
|
|
540
602
|
uglyWhere.autoInjectVal = {};
|
|
541
603
|
}
|
|
542
604
|
else {
|
|
543
|
-
uglyWhere.pushProperty = `_none.${(0, uncapitalize_util_1.uncapitalize)(specificField)}${uglyWhere.pushProperty === "$$$" ? "" : `.${uglyWhere.pushProperty}`}`;
|
|
605
|
+
uglyWhere.pushProperty = `_none.${(0, uncapitalize_util_1.uncapitalize)(specificField)}${uglyWhere.pushProperty === "$$$" ? (uglyWhere.properties ? ".equals" : "") : `.${uglyWhere.pushProperty}`}`;
|
|
544
606
|
}
|
|
545
607
|
keySplitedAnd = keySplitedConector[0];
|
|
546
608
|
}
|
|
@@ -554,20 +616,29 @@ class DynamicMethodsResolver {
|
|
|
554
616
|
prettyWheres: [],
|
|
555
617
|
};
|
|
556
618
|
let ANDMode = false;
|
|
557
|
-
let keysSplitedAND = dynamicMethodInfo.keyToMapReplaced.split(
|
|
619
|
+
let keysSplitedAND = dynamicMethodInfo.keyToMapReplaced.split(this.operators.AND);
|
|
558
620
|
if (keysSplitedAND.length > 1) {
|
|
559
621
|
ANDMode = true;
|
|
560
622
|
}
|
|
561
623
|
keysSplitedAND.forEach((keySplitedAND, idx) => {
|
|
562
624
|
let orMode = false;
|
|
563
|
-
let keysSplitedOr
|
|
625
|
+
let keysSplitedOr;
|
|
626
|
+
if (idx === 0) {
|
|
627
|
+
keysSplitedOr = keySplitedAND.split(this.operators.Or);
|
|
628
|
+
}
|
|
629
|
+
else {
|
|
630
|
+
if (this.operators.Or.test(keySplitedAND)) {
|
|
631
|
+
this.logAndThrowError(`The logical operator "Or" cannot appear after an "AND" (all caps): ${dynamicMethodInfo.originalDynamicMethodName}.`);
|
|
632
|
+
}
|
|
633
|
+
keysSplitedOr = [keySplitedAND];
|
|
634
|
+
}
|
|
564
635
|
if (keysSplitedOr.length > 1) {
|
|
565
636
|
orMode = true;
|
|
566
637
|
}
|
|
567
638
|
for (let i = 0; i < keysSplitedOr.length; i++) {
|
|
568
639
|
if (keysSplitedOr[i] === "")
|
|
569
640
|
continue;
|
|
570
|
-
const keysSplitedAnd = keysSplitedOr[i].split(
|
|
641
|
+
const keysSplitedAnd = keysSplitedOr[i].split(this.operators.And);
|
|
571
642
|
for (const keySplitedAnd of keysSplitedAnd) {
|
|
572
643
|
if (keySplitedAnd === "")
|
|
573
644
|
continue;
|
|
@@ -718,9 +789,7 @@ class DynamicMethodsResolver {
|
|
|
718
789
|
adjust++;
|
|
719
790
|
continue;
|
|
720
791
|
}
|
|
721
|
-
const arg = args[j - adjust] === debug_arg_symbol_constant_1.DEBUG_ARG_SYMBOL
|
|
722
|
-
? `<args>[${j - adjust}]`
|
|
723
|
-
: args[j - adjust];
|
|
792
|
+
const arg = args[j - adjust] === debug_arg_symbol_constant_1.DEBUG_ARG_SYMBOL ? `<args>[${j - adjust}]` : args[j - adjust];
|
|
724
793
|
// ? Avaliar necessidade dessa validação; era usada por compatibilidade direta com o prisma
|
|
725
794
|
if (currentWhereRslvd.betweenMode && arg !== undefined) {
|
|
726
795
|
current[context[i]] = { between: arg };
|
|
@@ -782,7 +851,7 @@ class DynamicMethodsResolver {
|
|
|
782
851
|
if (!dynamicMethodInfo.ignoreWhere) {
|
|
783
852
|
dynamicMethodWhereOps = this.resolvePrettyWheres(dynamicMethodInfo);
|
|
784
853
|
}
|
|
785
|
-
instance
|
|
854
|
+
instance._vsrepocache.set(originalKey, (args, methodOptions) => {
|
|
786
855
|
const vsrepoResolveArgsData = {
|
|
787
856
|
instance,
|
|
788
857
|
options: methodOptions ?? {},
|
|
@@ -796,9 +865,7 @@ class DynamicMethodsResolver {
|
|
|
796
865
|
pagination: dynamicMethodCustomization.paginationPosition !== undefined
|
|
797
866
|
? this.validateIndexedArg(args, dynamicMethodCustomization.paginationPosition, value => this.validator.validatePagination(value))
|
|
798
867
|
: undefined,
|
|
799
|
-
dataPayload: dynamicMethodInfo.dataIndex !== undefined
|
|
800
|
-
? args.at(dynamicMethodInfo.dataIndex)
|
|
801
|
-
: undefined,
|
|
868
|
+
dataPayload: dynamicMethodInfo.dataIndex !== undefined ? args.at(dynamicMethodInfo.dataIndex) : undefined,
|
|
802
869
|
createPayload: dynamicMethodInfo.createIndex !== undefined
|
|
803
870
|
? args.at(dynamicMethodInfo.createIndex)
|
|
804
871
|
: undefined,
|
|
@@ -825,7 +892,7 @@ class DynamicMethodsResolver {
|
|
|
825
892
|
for (let i = 0; i <= dynamicMethodInfo.argsCount; i++) {
|
|
826
893
|
argsSimulation.push(debug_arg_symbol_constant_1.DEBUG_ARG_SYMBOL);
|
|
827
894
|
}
|
|
828
|
-
const vsrepoArgs = instance
|
|
895
|
+
const vsrepoArgs = instance._vsrepocache.get(originalKey)(argsSimulation);
|
|
829
896
|
const { db: _, ...options } = vsrepoArgs.options ?? {};
|
|
830
897
|
this.logger.logDebug(`Args preview for ${originalKey}:`, {
|
|
831
898
|
...vsrepoArgs,
|
|
@@ -833,7 +900,6 @@ class DynamicMethodsResolver {
|
|
|
833
900
|
});
|
|
834
901
|
}
|
|
835
902
|
instance[originalKey] = async (...args) => {
|
|
836
|
-
let db = this.adapter.getDbClient();
|
|
837
903
|
let methodOptions;
|
|
838
904
|
if (args.length < dynamicMethodInfo.argsCount) {
|
|
839
905
|
const missingParams = dynamicMethodInfo.whereParams
|
|
@@ -846,12 +912,11 @@ class DynamicMethodsResolver {
|
|
|
846
912
|
else if (args.length > dynamicMethodInfo.argsCount) {
|
|
847
913
|
const optionsArg = args[args.length - 1];
|
|
848
914
|
methodOptions = this.validator.validateMethodOptions(optionsArg);
|
|
849
|
-
db = methodOptions.db ?? db;
|
|
850
915
|
}
|
|
851
916
|
else {
|
|
852
917
|
args.push("1");
|
|
853
918
|
}
|
|
854
|
-
const vsrepoArgs = instance
|
|
919
|
+
const vsrepoArgs = instance._vsrepocache.get(originalKey)(args, methodOptions);
|
|
855
920
|
const start = this.logger.startPerformLog(`run ${String(originalKey)} (-> ${dynamicMethodInfo.method})`);
|
|
856
921
|
try {
|
|
857
922
|
// * Todos os métodos do adapter seguem essa precedencia de parametros
|