vsrepo 1.4.2 → 2.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 +827 -1322
- package/README.pt-BR.md +833 -1325
- package/dist/VSRepoAdapter.d.ts +109 -0
- package/dist/VSRepoAdapter.js +18 -0
- package/dist/VSRepository.d.ts +166 -1201
- package/dist/VSRepository.js +327 -237
- package/dist/decorators/dynamic-method.decorator.d.ts +25 -0
- package/dist/decorators/dynamic-method.decorator.js +38 -0
- package/dist/decorators/query-method.decorator.d.ts +27 -0
- package/dist/decorators/query-method.decorator.js +45 -0
- package/dist/errors/VSRepoAdapterError.d.ts +22 -0
- package/dist/errors/VSRepoAdapterError.js +31 -0
- package/dist/errors/VSRepoError.d.ts +15 -0
- package/dist/errors/VSRepoError.js +21 -0
- package/dist/index.d.ts +38 -1
- package/dist/index.js +28 -15
- package/dist/internal/constants/debug-arg-symbol.constant.d.ts +1 -0
- package/dist/internal/constants/debug-arg-symbol.constant.js +4 -0
- package/dist/internal/constants/dynamic-methods-key.constant.d.ts +1 -0
- package/dist/internal/constants/query-methods-key.constant.d.ts +1 -0
- package/dist/internal/constants/query-methods-key.constant.js +4 -0
- package/dist/internal/enums/adapter-error-code.enum.d.ts +125 -0
- package/dist/internal/enums/adapter-error-code.enum.js +129 -0
- package/dist/internal/enums/transaction-isolation-level.enum.d.ts +16 -0
- package/dist/internal/enums/transaction-isolation-level.enum.js +20 -0
- package/dist/internal/enums/vs-log-level.enum.d.ts +18 -0
- package/dist/internal/enums/vs-log-level.enum.js +22 -0
- package/dist/internal/enums/vsrepo-error-type.enum.d.ts +19 -0
- package/dist/internal/enums/vsrepo-error-type.enum.js +23 -0
- package/dist/internal/resolvers/dynamic-methods.resolver.d.ts +23 -0
- package/dist/internal/resolvers/dynamic-methods.resolver.js +910 -0
- package/dist/internal/resolvers/merge-wheres.resolver.d.ts +7 -0
- package/dist/internal/resolvers/merge-wheres.resolver.js +26 -0
- package/dist/internal/utils/uncapitalize.util.d.ts +1 -0
- package/dist/internal/utils/vs-logger.util.d.ts +25 -0
- package/dist/internal/utils/vs-logger.util.js +139 -0
- package/dist/internal/validators/decorators.validator.d.ts +8 -0
- package/dist/internal/validators/decorators.validator.js +75 -0
- package/dist/internal/validators/schemas/ordering.schema.d.ts +3 -0
- package/dist/internal/validators/schemas/ordering.schema.js +38 -0
- package/dist/internal/validators/schemas/pagination.schema.d.ts +6 -0
- package/dist/internal/validators/schemas/pagination.schema.js +40 -0
- package/dist/internal/validators/schemas/where.schema.d.ts +7 -0
- package/dist/internal/validators/schemas/where.schema.js +42 -0
- package/dist/internal/validators/vsrepo.validator.d.ts +40 -0
- package/dist/internal/validators/vsrepo.validator.js +182 -0
- package/dist/types/adapter/adapter-method-options.type.d.ts +24 -0
- package/dist/types/adapter/adapter-query-options.type.d.ts +5 -0
- package/dist/types/decorators/dynamic-method-options.type.d.ts +14 -0
- package/dist/types/decorators/query-method-options.type.d.ts +15 -0
- package/dist/types/dynamic-methods/dynamic-method-customization.type.d.ts +7 -0
- package/dist/types/dynamic-methods/dynamic-method-info.type.d.ts +18 -0
- package/dist/types/dynamic-methods/dynamic-method-where-ops.type.d.ts +6 -0
- package/dist/types/utils/count-result.type.d.ts +9 -0
- package/dist/types/utils/decimal-like.type.d.ts +23 -0
- package/dist/types/utils/deep-partial.type.d.ts +14 -0
- package/dist/types/utils/keys-of-type.type.d.ts +20 -0
- package/dist/types/utils/methods-options.type.d.ts +23 -0
- package/dist/types/utils/numeric-keys.type.d.ts +24 -0
- package/dist/types/utils/numeric-like.type.d.ts +10 -0
- package/dist/types/utils/ordering.type.d.ts +39 -0
- package/dist/types/utils/pagination.type.d.ts +11 -0
- package/dist/types/utils/perform-data.type.d.ts +4 -0
- package/dist/types/utils/primitive.type.d.ts +7 -0
- package/dist/types/utils/query-method-arg.type.d.ts +27 -0
- package/dist/types/utils/restrict-method-options.type.d.ts +14 -0
- package/dist/types/utils/see-mode.type.d.ts +12 -0
- package/dist/types/vsrepo/vsrepo-args.type.d.ts +9 -0
- package/dist/types/vsrepo/vsrepo-method.type.d.ts +4 -0
- package/dist/types/vsrepo/vsrepo-method.type.js +2 -0
- package/dist/types/vsrepo/vsrepo-options.type.d.ts +34 -0
- package/dist/types/vsrepo/vsrepo-options.type.js +2 -0
- package/dist/types/vsrepo/vsrepo-orm-types.type.d.ts +17 -0
- package/dist/types/vsrepo/vsrepo-orm-types.type.js +2 -0
- package/dist/types/vsrepo/vsrepo-pretty-where.type.d.ts +7 -0
- package/dist/types/vsrepo/vsrepo-pretty-where.type.js +2 -0
- package/dist/types/vsrepo/vsrepo-query-options.type.d.ts +17 -0
- package/dist/types/vsrepo/vsrepo-query-options.type.js +2 -0
- package/dist/types/vsrepo/vsrepo-query.type.d.ts +5 -0
- package/dist/types/vsrepo/vsrepo-query.type.js +2 -0
- package/dist/types/vsrepo/vsrepo-relations.type.d.ts +26 -0
- package/dist/types/vsrepo/vsrepo-relations.type.js +2 -0
- package/dist/types/vsrepo/vsrepo-resolve-args-data.type.d.ts +19 -0
- package/dist/types/vsrepo/vsrepo-resolve-args-data.type.js +2 -0
- package/dist/types/vsrepo/vsrepo-select.type.d.ts +15 -0
- package/dist/types/vsrepo/vsrepo-select.type.js +2 -0
- package/dist/types/vsrepo/vsrepo-transaction-options.type.d.ts +12 -0
- package/dist/types/vsrepo/vsrepo-transaction-options.type.js +2 -0
- package/dist/types/vsrepo/vsrepo-ugly-where.type.d.ts +9 -0
- package/dist/types/vsrepo/vsrepo-ugly-where.type.js +2 -0
- package/dist/types/vsrepo/vsrepo-where.type.d.ts +99 -0
- package/dist/types/vsrepo/vsrepo-where.type.js +2 -0
- package/package.json +16 -37
- package/README-DynamicRepo.md +0 -625
- package/README-DynamicRepo.pt-BR.md +0 -625
- package/dist/DynamicRepository.d.ts +0 -497
- package/dist/DynamicRepository.js +0 -26
- package/dist/VSRepoError.d.ts +0 -83
- package/dist/VSRepoError.js +0 -17
- package/dist/internal/decorators/dynamic-method.decorator.js +0 -14
- package/dist/internal/decorators/query-method.decorator.js +0 -20
- package/dist/internal/entities/dynamic-method-metadata.entity.js +0 -26
- package/dist/internal/errors/vs-repo.error.js +0 -31
- package/dist/internal/resolvers/base-methods.resolve.js +0 -541
- package/dist/internal/resolvers/create-update-payloads-with-relations.resolve.js +0 -143
- package/dist/internal/resolvers/data-payload-with-relations.resolve.js +0 -60
- package/dist/internal/resolvers/dbAndPrismaArgs.resolve.js +0 -63
- package/dist/internal/resolvers/dynamic-method-customization.resolve.js +0 -57
- package/dist/internal/resolvers/dynamic-method-info.resolve.js +0 -279
- package/dist/internal/resolvers/dynamic-methods-metadata.resolve.js +0 -15
- package/dist/internal/resolvers/merge-wheres.resolve.js +0 -22
- package/dist/internal/resolvers/pretty-wheres.resolve.js +0 -87
- package/dist/internal/resolvers/select.resolve.js +0 -7
- package/dist/internal/resolvers/specific-where.resolve.js +0 -84
- package/dist/internal/resolvers/ugly-where.resolve.js +0 -178
- package/dist/internal/utils/logger.util.js +0 -21
- package/dist/internal/utils/schemas.util.js +0 -31
- package/dist/internal/validation/build-config.validate.js +0 -84
- package/dist/internal/validation/constructor-config.validate.js +0 -64
- package/dist/internal/validation/dynamic-method-config.validate.js +0 -19
- package/dist/internal/validation/extension.validate.js +0 -15
- package/dist/internal/validation/is-object.validate.js +0 -6
- package/dist/internal/validation/method-options.validate.js +0 -42
- package/dist/internal/validation/obj-with-relations.validate.js +0 -37
- package/dist/internal/validation/prisma-client.validate.js +0 -10
- package/dist/internal/validation/query-method-arg.validate.js +0 -22
- package/dist/internal/validation/query-method-options.validate.js +0 -24
- package/scripts/configure-prisma-import.mjs +0 -283
- package/scripts/copy-types.mjs +0 -24
- /package/dist/{internal/decorators/types/dynamic-method-config.type.js → types/adapter/adapter-method-options.type.js} +0 -0
- /package/dist/{internal/errors/types/vs-repo-error-type.type.js → types/adapter/adapter-query-options.type.js} +0 -0
- /package/dist/{internal/errors/types/vs-repo-runtime-error-code.type.js → types/decorators/dynamic-method-options.type.js} +0 -0
- /package/dist/{internal/validation/types → types/decorators}/query-method-options.type.js +0 -0
- /package/dist/{internal/resolvers/types → types/dynamic-methods}/dynamic-method-customization.type.js +0 -0
- /package/dist/{internal/resolvers/types → types/dynamic-methods}/dynamic-method-info.type.js +0 -0
- /package/dist/{internal/resolvers/types → types/dynamic-methods}/dynamic-method-where-ops.type.js +0 -0
- /package/dist/{internal/resolvers/types/base-method-function.type.js → types/utils/count-result.type.js} +0 -0
- /package/dist/{internal/resolvers/types/pretty-where.type.js → types/utils/decimal-like.type.js} +0 -0
- /package/dist/{internal/resolvers/types/prisma-args.type.js → types/utils/deep-partial.type.js} +0 -0
- /package/dist/{internal/resolvers/types/repository-build-instance.type.js → types/utils/keys-of-type.type.js} +0 -0
- /package/dist/{internal/resolvers/types/resolve-db-and-prisma-args-data.type.js → types/utils/methods-options.type.js} +0 -0
- /package/dist/{internal/resolvers/types/ugly-where.type.js → types/utils/numeric-keys.type.js} +0 -0
- /package/dist/{internal/validation/types/base-methods.type.js → types/utils/numeric-like.type.js} +0 -0
- /package/dist/{internal/validation/types/build-config.type.js → types/utils/ordering.type.js} +0 -0
- /package/dist/{internal/validation/types → types/utils}/pagination.type.js +0 -0
- /package/dist/{internal/validation/types/constructor-config.type.js → types/utils/perform-data.type.js} +0 -0
- /package/dist/{internal/validation/types/method-options.type.js → types/utils/primitive.type.js} +0 -0
- /package/dist/{internal/validation/types → types/utils}/query-method-arg.type.js +0 -0
- /package/dist/{internal/validation/types/method.type.js → types/utils/restrict-method-options.type.js} +0 -0
- /package/dist/{internal/validation/types → types/utils}/see-mode.type.js +0 -0
- /package/dist/{internal/validation/types/relation.type.js → types/vsrepo/vsrepo-args.type.js} +0 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SeeMode } from "../../types/utils/see-mode.type";
|
|
2
|
+
import { VSRepoWhere } from "../../types/vsrepo/vsrepo-where.type";
|
|
3
|
+
export declare class MergeWheresResolver<T> {
|
|
4
|
+
private readonly softRemoveKey?;
|
|
5
|
+
constructor(softRemoveKey?: keyof T | undefined);
|
|
6
|
+
resolve(see?: SeeMode, provided?: VSRepoWhere<T>): VSRepoWhere<T>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MergeWheresResolver = void 0;
|
|
7
|
+
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
8
|
+
class MergeWheresResolver {
|
|
9
|
+
softRemoveKey;
|
|
10
|
+
constructor(softRemoveKey) {
|
|
11
|
+
this.softRemoveKey = softRemoveKey;
|
|
12
|
+
}
|
|
13
|
+
resolve(see = "active", provided) {
|
|
14
|
+
const objectsToMerge = [];
|
|
15
|
+
if (provided)
|
|
16
|
+
objectsToMerge.push(provided);
|
|
17
|
+
if (this.softRemoveKey && see !== "all") {
|
|
18
|
+
objectsToMerge.push({
|
|
19
|
+
[this.softRemoveKey]: see === "active" ? null : { not: null },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const whereResolved = deepmerge_1.default.all(objectsToMerge);
|
|
23
|
+
return whereResolved;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.MergeWheresResolver = MergeWheresResolver;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function uncapitalize(text: string): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { VSLogLevel } from "../enums/vs-log-level.enum";
|
|
2
|
+
import { PerformData } from "../../types/utils/perform-data.type";
|
|
3
|
+
export declare class VSLogger {
|
|
4
|
+
private readonly logLevel;
|
|
5
|
+
private readonly loggerName;
|
|
6
|
+
private readonly slowOperationThresholdMs;
|
|
7
|
+
private static readonly DEFAULT_SLOW_OPERATION_MS;
|
|
8
|
+
private readonly useColors;
|
|
9
|
+
constructor(logLevel: VSLogLevel, loggerName: string, slowOperationThresholdMs?: number);
|
|
10
|
+
getLogLevel(): VSLogLevel;
|
|
11
|
+
private color;
|
|
12
|
+
private stringfy;
|
|
13
|
+
private buildPrefix;
|
|
14
|
+
private log;
|
|
15
|
+
logDebug(text: string, obj?: any): void;
|
|
16
|
+
logInfo(text: string, obj?: any): void;
|
|
17
|
+
logWarn(text: string, obj?: any): void;
|
|
18
|
+
/**
|
|
19
|
+
* Loga um erro. Se `err` for uma instância de `Error`, apenas nome, mensagem,
|
|
20
|
+
* stack e cause são logados (evita despejar propriedades internas desnecessárias).
|
|
21
|
+
*/
|
|
22
|
+
logError(text: string, err?: unknown): void;
|
|
23
|
+
startPerformLog(operation: string): PerformData | undefined;
|
|
24
|
+
endPerformLog(data: PerformData | undefined): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VSLogger = void 0;
|
|
4
|
+
const vs_log_level_enum_1 = require("../enums/vs-log-level.enum");
|
|
5
|
+
/**
|
|
6
|
+
* ANSI escape codes used to colorize log output.
|
|
7
|
+
* Kept as raw codes (instead of a dependency like chalk) since colors here
|
|
8
|
+
* are a "nice to have" for local/dev usage, not a hard requirement.
|
|
9
|
+
*/
|
|
10
|
+
const ANSI = {
|
|
11
|
+
reset: "\x1b[0m",
|
|
12
|
+
bold: "\x1b[1m",
|
|
13
|
+
dim: "\x1b[2m",
|
|
14
|
+
gray: "\x1b[90m",
|
|
15
|
+
cyan: "\x1b[36m",
|
|
16
|
+
yellow: "\x1b[33m",
|
|
17
|
+
red: "\x1b[31m",
|
|
18
|
+
magenta: "\x1b[35m",
|
|
19
|
+
};
|
|
20
|
+
const LEVEL_LABEL = {
|
|
21
|
+
[vs_log_level_enum_1.VSLogLevel.DEBUG]: "DEBUG",
|
|
22
|
+
[vs_log_level_enum_1.VSLogLevel.INFO]: "INFO",
|
|
23
|
+
[vs_log_level_enum_1.VSLogLevel.WARN]: "WARN",
|
|
24
|
+
[vs_log_level_enum_1.VSLogLevel.ERROR]: "ERROR",
|
|
25
|
+
};
|
|
26
|
+
const LEVEL_COLOR = {
|
|
27
|
+
[vs_log_level_enum_1.VSLogLevel.DEBUG]: ANSI.gray,
|
|
28
|
+
[vs_log_level_enum_1.VSLogLevel.INFO]: ANSI.cyan,
|
|
29
|
+
[vs_log_level_enum_1.VSLogLevel.WARN]: ANSI.yellow,
|
|
30
|
+
[vs_log_level_enum_1.VSLogLevel.ERROR]: ANSI.red,
|
|
31
|
+
};
|
|
32
|
+
class VSLogger {
|
|
33
|
+
logLevel;
|
|
34
|
+
loggerName;
|
|
35
|
+
slowOperationThresholdMs;
|
|
36
|
+
// * Acima disso, uma operação concluída é logada como WARN ao invés de DEBUG
|
|
37
|
+
static DEFAULT_SLOW_OPERATION_MS = 300;
|
|
38
|
+
useColors;
|
|
39
|
+
constructor(logLevel, loggerName, slowOperationThresholdMs = VSLogger.DEFAULT_SLOW_OPERATION_MS) {
|
|
40
|
+
this.logLevel = logLevel;
|
|
41
|
+
this.loggerName = loggerName;
|
|
42
|
+
this.slowOperationThresholdMs = slowOperationThresholdMs;
|
|
43
|
+
this.useColors = !process.env.NO_COLOR && !!process.stdout?.isTTY;
|
|
44
|
+
}
|
|
45
|
+
getLogLevel() {
|
|
46
|
+
return this.logLevel;
|
|
47
|
+
}
|
|
48
|
+
color(text, ansiColor) {
|
|
49
|
+
if (!this.useColors)
|
|
50
|
+
return text;
|
|
51
|
+
return `${ansiColor}${text}${ANSI.reset}`;
|
|
52
|
+
}
|
|
53
|
+
// * Evita quebrar em BigInt (comum em counts/ids do Prisma)
|
|
54
|
+
stringfy(obj) {
|
|
55
|
+
// const seen = new WeakSet<object>();
|
|
56
|
+
return JSON.stringify(obj, (_key, value) => {
|
|
57
|
+
if (typeof value === "bigint")
|
|
58
|
+
return `${value.toString()}n`;
|
|
59
|
+
if (value instanceof Error) {
|
|
60
|
+
return { name: value.name, message: value.message, stack: value.stack };
|
|
61
|
+
}
|
|
62
|
+
// if (typeof value === "object" && value !== null) {
|
|
63
|
+
// if (seen.has(value)) return "[Circular]";
|
|
64
|
+
// seen.add(value);
|
|
65
|
+
// }
|
|
66
|
+
return value;
|
|
67
|
+
}, 2);
|
|
68
|
+
}
|
|
69
|
+
buildPrefix(level) {
|
|
70
|
+
const timestamp = this.color(new Date().toISOString(), ANSI.dim);
|
|
71
|
+
const levelLabel = this.color(`[${LEVEL_LABEL[level]}]`, `${ANSI.bold}${LEVEL_COLOR[level]}`);
|
|
72
|
+
const name = this.color(`[${this.loggerName}]`, ANSI.magenta);
|
|
73
|
+
return `${timestamp} ${levelLabel} ${name}`;
|
|
74
|
+
}
|
|
75
|
+
log(level, text, obj) {
|
|
76
|
+
if (this.logLevel > level)
|
|
77
|
+
return;
|
|
78
|
+
const args = [`${this.buildPrefix(level)} ${text}`];
|
|
79
|
+
if (obj !== undefined) {
|
|
80
|
+
args.push("\n" + this.stringfy(obj));
|
|
81
|
+
}
|
|
82
|
+
if (level === vs_log_level_enum_1.VSLogLevel.ERROR) {
|
|
83
|
+
console.error(...args);
|
|
84
|
+
}
|
|
85
|
+
else if (level === vs_log_level_enum_1.VSLogLevel.WARN) {
|
|
86
|
+
console.warn(...args);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
console.log(...args);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
logDebug(text, obj) {
|
|
93
|
+
this.log(vs_log_level_enum_1.VSLogLevel.DEBUG, text, obj);
|
|
94
|
+
}
|
|
95
|
+
logInfo(text, obj) {
|
|
96
|
+
this.log(vs_log_level_enum_1.VSLogLevel.INFO, text, obj);
|
|
97
|
+
}
|
|
98
|
+
logWarn(text, obj) {
|
|
99
|
+
this.log(vs_log_level_enum_1.VSLogLevel.WARN, text, obj);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Loga um erro. Se `err` for uma instância de `Error`, apenas nome, mensagem,
|
|
103
|
+
* stack e cause são logados (evita despejar propriedades internas desnecessárias).
|
|
104
|
+
*/
|
|
105
|
+
logError(text, err) {
|
|
106
|
+
if (err instanceof Error) {
|
|
107
|
+
this.log(vs_log_level_enum_1.VSLogLevel.ERROR, text, {
|
|
108
|
+
name: err.name,
|
|
109
|
+
message: err.message,
|
|
110
|
+
stack: err.stack,
|
|
111
|
+
cause: err.cause,
|
|
112
|
+
});
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this.log(vs_log_level_enum_1.VSLogLevel.ERROR, text, err);
|
|
116
|
+
}
|
|
117
|
+
startPerformLog(operation) {
|
|
118
|
+
// * O timestamp é sempre capturado (é barato) para permitir detectar operações
|
|
119
|
+
// * lentas mesmo fora do DEBUG; a linha "Starting to X..." em si só aparece em DEBUG.
|
|
120
|
+
this.logDebug(`Starting to ${operation}...`);
|
|
121
|
+
return {
|
|
122
|
+
operation,
|
|
123
|
+
start: performance.now(),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
endPerformLog(data) {
|
|
127
|
+
if (!data)
|
|
128
|
+
return;
|
|
129
|
+
const end = performance.now();
|
|
130
|
+
const timeTook = end - data.start;
|
|
131
|
+
const timeTookLabel = timeTook.toFixed(2);
|
|
132
|
+
if (timeTook >= this.slowOperationThresholdMs) {
|
|
133
|
+
this.logWarn(`Took ${timeTookLabel}ms to ${data.operation} (slower than the ${this.slowOperationThresholdMs}ms threshold)`);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
this.logDebug(`Took ${timeTookLabel}ms to ${data.operation}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.VSLogger = VSLogger;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DynamicMethodOptions } from "../../types/decorators/dynamic-method-options.type";
|
|
2
|
+
import { QueryMethodOptions } from "../../types/decorators/query-method-options.type";
|
|
3
|
+
export declare class DecoratorsValidator {
|
|
4
|
+
private static readonly dynamicMethodOptionsSchema;
|
|
5
|
+
static validateDynamicMethodOptions(options: unknown): DynamicMethodOptions;
|
|
6
|
+
private static queryMethodOptionsSchema;
|
|
7
|
+
static validateQueryMethodOptions(options: unknown): QueryMethodOptions;
|
|
8
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.DecoratorsValidator = void 0;
|
|
40
|
+
const v = __importStar(require("valibot"));
|
|
41
|
+
const VSRepoError_1 = require("../../errors/VSRepoError");
|
|
42
|
+
const ordering_schema_1 = __importDefault(require("./schemas/ordering.schema"));
|
|
43
|
+
const vsrepo_error_type_enum_1 = require("../enums/vsrepo-error-type.enum");
|
|
44
|
+
class DecoratorsValidator {
|
|
45
|
+
static dynamicMethodOptionsSchema = v.object({
|
|
46
|
+
proxyTo: v.optional(v.string()),
|
|
47
|
+
injectOrdering: v.optional(ordering_schema_1.default),
|
|
48
|
+
});
|
|
49
|
+
static validateDynamicMethodOptions(options) {
|
|
50
|
+
const parsed = v.safeParse(this.dynamicMethodOptionsSchema, options);
|
|
51
|
+
if (!parsed.success) {
|
|
52
|
+
const firstIssue = parsed.issues[0];
|
|
53
|
+
const path = firstIssue.path?.length
|
|
54
|
+
? firstIssue.path.map(p => String(p.key)).join(".")
|
|
55
|
+
: "options";
|
|
56
|
+
throw new VSRepoError_1.VSRepoError(`${path}: ${firstIssue.message}`, vsrepo_error_type_enum_1.VSRepoErrorType.DECORATOR);
|
|
57
|
+
}
|
|
58
|
+
return parsed.output;
|
|
59
|
+
}
|
|
60
|
+
static queryMethodOptionsSchema = v.object({
|
|
61
|
+
modifying: v.optional(v.boolean(), false),
|
|
62
|
+
});
|
|
63
|
+
static validateQueryMethodOptions(options) {
|
|
64
|
+
const parsed = v.safeParse(this.queryMethodOptionsSchema, options);
|
|
65
|
+
if (!parsed.success) {
|
|
66
|
+
const firstIssue = parsed.issues[0];
|
|
67
|
+
const path = firstIssue.path?.length
|
|
68
|
+
? firstIssue.path.map(p => String(p.key)).join(".")
|
|
69
|
+
: "options";
|
|
70
|
+
throw new VSRepoError_1.VSRepoError(`${path}: ${firstIssue.message}`, vsrepo_error_type_enum_1.VSRepoErrorType.DECORATOR);
|
|
71
|
+
}
|
|
72
|
+
return parsed.output;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.DecoratorsValidator = DecoratorsValidator;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
declare const _default: v.UnionSchema<[v.RecordSchema<v.StringSchema<undefined>, v.PicklistSchema<["asc", "desc", "ASC", "DESC"], undefined>, undefined>, v.ArraySchema<v.RecordSchema<v.StringSchema<undefined>, v.PicklistSchema<["asc", "desc", "ASC", "DESC"], undefined>, undefined>, undefined>], undefined>;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const v = __importStar(require("valibot"));
|
|
37
|
+
const recordSchema = v.record(v.string(), v.picklist(["asc", "desc", "ASC", "DESC"]));
|
|
38
|
+
exports.default = v.union([recordSchema, v.array(recordSchema)]);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const v = __importStar(require("valibot"));
|
|
37
|
+
exports.default = v.object({
|
|
38
|
+
limit: v.optional(v.number()),
|
|
39
|
+
offset: v.optional(v.number()),
|
|
40
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
declare const _default: v.LooseObjectSchema<{
|
|
3
|
+
readonly AND: v.OptionalSchema<v.UnionSchema<[v.LooseObjectSchema<{}, undefined>, v.ArraySchema<v.LooseObjectSchema<{}, undefined>, undefined>], undefined>, undefined>;
|
|
4
|
+
readonly OR: v.OptionalSchema<v.UnionSchema<[v.LooseObjectSchema<{}, undefined>, v.ArraySchema<v.LooseObjectSchema<{}, undefined>, undefined>], undefined>, undefined>;
|
|
5
|
+
readonly NOT: v.OptionalSchema<v.UnionSchema<[v.LooseObjectSchema<{}, undefined>, v.ArraySchema<v.LooseObjectSchema<{}, undefined>, undefined>], undefined>, undefined>;
|
|
6
|
+
}, undefined>;
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const v = __importStar(require("valibot"));
|
|
37
|
+
// * Validação simplificada para não dar problema em ORMs com especifidades
|
|
38
|
+
exports.default = v.looseObject({
|
|
39
|
+
AND: v.optional(v.union([v.looseObject({}), v.array(v.looseObject({}))])),
|
|
40
|
+
OR: v.optional(v.union([v.looseObject({}), v.array(v.looseObject({}))])),
|
|
41
|
+
NOT: v.optional(v.union([v.looseObject({}), v.array(v.looseObject({}))])),
|
|
42
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { VSRepoOptions } from "../../types/vsrepo/vsrepo-options.type";
|
|
2
|
+
import { MethodOptions } from "../../types/utils/methods-options.type";
|
|
3
|
+
import { QueryMethodArg } from "../../types/utils/query-method-arg.type";
|
|
4
|
+
import { VSRepoTransactionOptions } from "../../types/vsrepo/vsrepo-transaction-options.type";
|
|
5
|
+
import { VSRepoOrmTypes } from "../../types/vsrepo/vsrepo-orm-types.type";
|
|
6
|
+
import { Pagination } from "../../types/utils/pagination.type";
|
|
7
|
+
import { Ordering } from "../../types/utils/ordering.type";
|
|
8
|
+
import { VSLogger } from "../utils/vs-logger.util";
|
|
9
|
+
import { VSRepoWhere } from "../../types/vsrepo/vsrepo-where.type";
|
|
10
|
+
import { VSRepoQueryOptions } from "../../types/vsrepo/vsrepo-query-options.type";
|
|
11
|
+
import { NumericLike } from "../../types/utils/numeric-like.type";
|
|
12
|
+
import { RestrictMethodOptions } from "../../types/utils/restrict-method-options.type";
|
|
13
|
+
export declare class VSRepoValidator<T, K, O extends VSRepoOrmTypes = VSRepoOrmTypes> {
|
|
14
|
+
private logger?;
|
|
15
|
+
setLogger(logger: VSLogger): void;
|
|
16
|
+
private failValidation;
|
|
17
|
+
private readonly constructorOptionsSchema;
|
|
18
|
+
validateConstructorOptions(options: unknown): VSRepoOptions<T, K>;
|
|
19
|
+
private readonly methodOptionsSchema;
|
|
20
|
+
validateMethodOptions(options?: unknown): MethodOptions<T, O>;
|
|
21
|
+
private readonly restrictMethodOptionsSchema;
|
|
22
|
+
validateRestrictMethodOptions(options?: unknown): RestrictMethodOptions<T, O>;
|
|
23
|
+
private readonly getAllMethodOptionsSchema;
|
|
24
|
+
validateGetAllMethodOptions(options?: unknown): MethodOptions<T, O> & {
|
|
25
|
+
pagination?: Pagination;
|
|
26
|
+
order?: Ordering<T>;
|
|
27
|
+
};
|
|
28
|
+
private queryArgSchema;
|
|
29
|
+
validateQueryMethodArg(arg?: unknown): QueryMethodArg<any>;
|
|
30
|
+
private queryOptionsSchema;
|
|
31
|
+
validateQueryOptions(options?: unknown): VSRepoQueryOptions;
|
|
32
|
+
private transactionOptionsSchema;
|
|
33
|
+
validateTransactionOptions(options: unknown): VSRepoTransactionOptions;
|
|
34
|
+
validateOrdering(value: unknown): Ordering<T>;
|
|
35
|
+
validatePagination(value: unknown): Pagination;
|
|
36
|
+
validateWhere(value: unknown): VSRepoWhere<T>;
|
|
37
|
+
private decimalLikeSchema;
|
|
38
|
+
private numericLikeSchema;
|
|
39
|
+
assertIsNumericLike(value: unknown): asserts value is NumericLike;
|
|
40
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.VSRepoValidator = void 0;
|
|
40
|
+
const v = __importStar(require("valibot"));
|
|
41
|
+
const vs_log_level_enum_1 = require("../enums/vs-log-level.enum");
|
|
42
|
+
const VSRepoError_1 = require("../../errors/VSRepoError");
|
|
43
|
+
const ordering_schema_1 = __importDefault(require("./schemas/ordering.schema"));
|
|
44
|
+
const vsrepo_error_type_enum_1 = require("../enums/vsrepo-error-type.enum");
|
|
45
|
+
const transaction_isolation_level_enum_1 = require("../enums/transaction-isolation-level.enum");
|
|
46
|
+
const pagination_schema_1 = __importDefault(require("./schemas/pagination.schema"));
|
|
47
|
+
const where_schema_1 = __importDefault(require("./schemas/where.schema"));
|
|
48
|
+
class VSRepoValidator {
|
|
49
|
+
// * Setado depois pelo VSRepository, pois no momento em que validateConstructorOptions
|
|
50
|
+
// * roda (validação das próprias options do construtor, incluindo o logLevel) o logger ainda não existe.
|
|
51
|
+
logger;
|
|
52
|
+
setLogger(logger) {
|
|
53
|
+
this.logger = logger;
|
|
54
|
+
}
|
|
55
|
+
failValidation(issue, type, fallbackPath = "options") {
|
|
56
|
+
const path = issue?.path?.length
|
|
57
|
+
? issue.path.map(p => String(p.key)).join(".")
|
|
58
|
+
: fallbackPath;
|
|
59
|
+
const message = `${path}: ${issue?.message ?? "validation failed"}`;
|
|
60
|
+
this.logger?.logError(`Validation failed (${type}): ${message}`);
|
|
61
|
+
throw new VSRepoError_1.VSRepoError(message, type);
|
|
62
|
+
}
|
|
63
|
+
constructorOptionsSchema = v.object({
|
|
64
|
+
// * Usando any ao invés de instanceof para não ter erro de referencia
|
|
65
|
+
adapter: v.any(),
|
|
66
|
+
pkName: v.string(),
|
|
67
|
+
softRemoveKey: v.optional(v.string()),
|
|
68
|
+
logLevel: v.optional(v.enum(vs_log_level_enum_1.VSLogLevel)),
|
|
69
|
+
logSlowThresholdMs: v.optional(v.pipe(v.number(), v.gtValue(0))),
|
|
70
|
+
defaultOrdering: v.optional(ordering_schema_1.default),
|
|
71
|
+
});
|
|
72
|
+
validateConstructorOptions(options) {
|
|
73
|
+
const parsed = v.safeParse(this.constructorOptionsSchema, options);
|
|
74
|
+
if (!parsed.success) {
|
|
75
|
+
this.failValidation(parsed.issues[0], vsrepo_error_type_enum_1.VSRepoErrorType.VALIDATOR);
|
|
76
|
+
}
|
|
77
|
+
return parsed.output;
|
|
78
|
+
}
|
|
79
|
+
methodOptionsSchema = v.object({
|
|
80
|
+
db: v.optional(v.any()),
|
|
81
|
+
see: v.optional(v.picklist(["active", "removed", "all"])),
|
|
82
|
+
relations: v.optional(v.looseObject({})),
|
|
83
|
+
select: v.optional(v.looseObject({})),
|
|
84
|
+
});
|
|
85
|
+
validateMethodOptions(options) {
|
|
86
|
+
const parsed = v.safeParse(this.methodOptionsSchema, options ?? {});
|
|
87
|
+
if (!parsed.success) {
|
|
88
|
+
this.failValidation(parsed.issues[0], vsrepo_error_type_enum_1.VSRepoErrorType.VALIDATOR);
|
|
89
|
+
}
|
|
90
|
+
return parsed.output;
|
|
91
|
+
}
|
|
92
|
+
restrictMethodOptionsSchema = v.object({
|
|
93
|
+
db: v.optional(v.any()),
|
|
94
|
+
see: v.optional(v.picklist(["active", "removed", "all"])),
|
|
95
|
+
});
|
|
96
|
+
validateRestrictMethodOptions(options) {
|
|
97
|
+
const parsed = v.safeParse(this.restrictMethodOptionsSchema, options ?? {});
|
|
98
|
+
if (!parsed.success) {
|
|
99
|
+
this.failValidation(parsed.issues[0], vsrepo_error_type_enum_1.VSRepoErrorType.VALIDATOR);
|
|
100
|
+
}
|
|
101
|
+
return parsed.output;
|
|
102
|
+
}
|
|
103
|
+
getAllMethodOptionsSchema = v.object({
|
|
104
|
+
...this.methodOptionsSchema.entries,
|
|
105
|
+
order: v.optional(ordering_schema_1.default),
|
|
106
|
+
pagination: v.optional(pagination_schema_1.default),
|
|
107
|
+
});
|
|
108
|
+
validateGetAllMethodOptions(options) {
|
|
109
|
+
const parsed = v.safeParse(this.getAllMethodOptionsSchema, options ?? {});
|
|
110
|
+
if (!parsed.success) {
|
|
111
|
+
this.failValidation(parsed.issues[0], vsrepo_error_type_enum_1.VSRepoErrorType.VALIDATOR);
|
|
112
|
+
}
|
|
113
|
+
return parsed.output;
|
|
114
|
+
}
|
|
115
|
+
queryArgSchema = v.object({
|
|
116
|
+
args: v.optional(v.array(v.any())),
|
|
117
|
+
db: v.optional(v.any()),
|
|
118
|
+
});
|
|
119
|
+
validateQueryMethodArg(arg) {
|
|
120
|
+
const parsed = v.safeParse(this.queryArgSchema, arg ?? {});
|
|
121
|
+
if (!parsed.success) {
|
|
122
|
+
this.failValidation(parsed.issues[0], vsrepo_error_type_enum_1.VSRepoErrorType.VALIDATOR);
|
|
123
|
+
}
|
|
124
|
+
return parsed.output;
|
|
125
|
+
}
|
|
126
|
+
queryOptionsSchema = v.object({
|
|
127
|
+
args: v.optional(v.array(v.any())),
|
|
128
|
+
db: v.optional(v.any()),
|
|
129
|
+
modifying: v.optional(v.boolean()),
|
|
130
|
+
});
|
|
131
|
+
validateQueryOptions(options) {
|
|
132
|
+
const parsed = v.safeParse(this.queryOptionsSchema, options ?? {});
|
|
133
|
+
if (!parsed.success) {
|
|
134
|
+
this.failValidation(parsed.issues[0], vsrepo_error_type_enum_1.VSRepoErrorType.VALIDATOR);
|
|
135
|
+
}
|
|
136
|
+
return parsed.output;
|
|
137
|
+
}
|
|
138
|
+
transactionOptionsSchema = v.object({
|
|
139
|
+
timeoutMs: v.optional(v.number()),
|
|
140
|
+
isolationLevel: v.optional(v.enum(transaction_isolation_level_enum_1.TransactionIsolationLevel)),
|
|
141
|
+
});
|
|
142
|
+
validateTransactionOptions(options) {
|
|
143
|
+
const parsed = v.safeParse(this.transactionOptionsSchema, options ?? {});
|
|
144
|
+
if (!parsed.success) {
|
|
145
|
+
this.failValidation(parsed.issues[0], vsrepo_error_type_enum_1.VSRepoErrorType.VALIDATOR);
|
|
146
|
+
}
|
|
147
|
+
return parsed.output;
|
|
148
|
+
}
|
|
149
|
+
validateOrdering(value) {
|
|
150
|
+
const parsed = v.safeParse(ordering_schema_1.default, value);
|
|
151
|
+
if (!parsed.success) {
|
|
152
|
+
this.failValidation(parsed.issues[0], vsrepo_error_type_enum_1.VSRepoErrorType.VALIDATOR, "ordering");
|
|
153
|
+
}
|
|
154
|
+
return parsed.output;
|
|
155
|
+
}
|
|
156
|
+
validatePagination(value) {
|
|
157
|
+
const parsed = v.safeParse(pagination_schema_1.default, value);
|
|
158
|
+
if (!parsed.success) {
|
|
159
|
+
this.failValidation(parsed.issues[0], vsrepo_error_type_enum_1.VSRepoErrorType.VALIDATOR, "pagination");
|
|
160
|
+
}
|
|
161
|
+
return parsed.output;
|
|
162
|
+
}
|
|
163
|
+
validateWhere(value) {
|
|
164
|
+
const parsed = v.safeParse(where_schema_1.default, value);
|
|
165
|
+
if (!parsed.success) {
|
|
166
|
+
this.failValidation(parsed.issues[0], vsrepo_error_type_enum_1.VSRepoErrorType.VALIDATOR, "where");
|
|
167
|
+
}
|
|
168
|
+
return parsed.output;
|
|
169
|
+
}
|
|
170
|
+
decimalLikeSchema = v.looseObject({
|
|
171
|
+
toNumber: v.function(),
|
|
172
|
+
decimalPlaces: v.function(),
|
|
173
|
+
});
|
|
174
|
+
numericLikeSchema = v.union([v.number(), v.bigint(), this.decimalLikeSchema]);
|
|
175
|
+
assertIsNumericLike(value) {
|
|
176
|
+
const parsed = v.safeParse(this.numericLikeSchema, value);
|
|
177
|
+
if (!parsed.success) {
|
|
178
|
+
this.failValidation(parsed.issues[0], vsrepo_error_type_enum_1.VSRepoErrorType.VALIDATOR);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports.VSRepoValidator = VSRepoValidator;
|