vsrepo 1.4.0 → 2.0.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 +723 -1338
- package/README.pt-BR.md +729 -1341
- package/dist/VSRepoAdapter.d.ts +71 -0
- package/dist/VSRepoAdapter.js +18 -0
- package/dist/VSRepository.d.ts +135 -1201
- package/dist/VSRepository.js +273 -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 +34 -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 +33 -0
- package/dist/internal/validators/vsrepo.validator.js +160 -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/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/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 +6 -0
- package/dist/types/utils/query-method-arg.type.d.ts +27 -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-options.type.d.ts +34 -0
- package/dist/types/vsrepo/vsrepo-orm-types.type.d.ts +17 -0
- package/dist/types/vsrepo/vsrepo-pretty-where.type.d.ts +7 -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 -536
- 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/deep-partial.type.js} +0 -0
- /package/dist/{internal/resolvers/types/prisma-args.type.js → types/utils/keys-of-type.type.js} +0 -0
- /package/dist/{internal/resolvers/types/repository-build-instance.type.js → types/utils/methods-options.type.js} +0 -0
- /package/dist/{internal/resolvers/types/resolve-db-and-prisma-args-data.type.js → types/utils/ordering.type.js} +0 -0
- /package/dist/{internal/validation/types → types/utils}/pagination.type.js +0 -0
- /package/dist/{internal/resolvers/types/ugly-where.type.js → types/utils/perform-data.type.js} +0 -0
- /package/dist/{internal/validation/types/base-methods.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 → types/utils}/see-mode.type.js +0 -0
- /package/dist/{internal/validation/types/build-config.type.js → types/vsrepo/vsrepo-args.type.js} +0 -0
- /package/dist/{internal/validation/types/constructor-config.type.js → types/vsrepo/vsrepo-method.type.js} +0 -0
- /package/dist/{internal/validation/types/method-options.type.js → types/vsrepo/vsrepo-options.type.js} +0 -0
- /package/dist/{internal/validation/types/method.type.js → types/vsrepo/vsrepo-orm-types.type.js} +0 -0
- /package/dist/{internal/validation/types/relation.type.js → types/vsrepo/vsrepo-pretty-where.type.js} +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Ordering } from "../utils/ordering.type";
|
|
2
|
+
/**
|
|
3
|
+
* Options accepted by the `@DynamicMethod` decorator.
|
|
4
|
+
*
|
|
5
|
+
* @template T Entity type the decorated method operates on.
|
|
6
|
+
*
|
|
7
|
+
* @publicApi
|
|
8
|
+
*/
|
|
9
|
+
export type DynamicMethodOptions<T = any> = {
|
|
10
|
+
/** Redirects the method's logic to another valid dynamic-method pattern. Useful for method names that don't follow the naming convention. */
|
|
11
|
+
proxyTo?: string;
|
|
12
|
+
/** Fixed ordering automatically injected into the query, overriding the repository's `defaultOrdering`. */
|
|
13
|
+
injectOrdering?: Ordering<T>;
|
|
14
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options accepted by the `@QueryMethod` decorator.
|
|
3
|
+
*
|
|
4
|
+
* @publicApi
|
|
5
|
+
*/
|
|
6
|
+
export type QueryMethodOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* When `true`, the SQL is executed as a modifying statement (`INSERT`/`UPDATE`/`DELETE`)
|
|
9
|
+
* and the decorated method always resolves to the number of affected rows.
|
|
10
|
+
* When `false`, the SQL is executed as a read query and the method resolves
|
|
11
|
+
* to whatever return type is declared on the field.
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
modifying: boolean;
|
|
15
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type DynamicMethodInfo = {
|
|
2
|
+
onlyBaseWheres: boolean;
|
|
3
|
+
ignoreWhere: boolean;
|
|
4
|
+
ignoreOrderByAndPagination: boolean;
|
|
5
|
+
ignoreSelect: boolean;
|
|
6
|
+
ignoreIgnoreConflicts: boolean;
|
|
7
|
+
existsMode: boolean;
|
|
8
|
+
keyToMapReplaced: string;
|
|
9
|
+
argsCount: number;
|
|
10
|
+
method: string;
|
|
11
|
+
whereParams: string[];
|
|
12
|
+
otherParams: string[];
|
|
13
|
+
ignoreDistinct: boolean;
|
|
14
|
+
dataIndex?: number;
|
|
15
|
+
updateIndex?: number;
|
|
16
|
+
createIndex?: number;
|
|
17
|
+
whereIndex?: number;
|
|
18
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively makes all properties of `T` optional, including nested objects
|
|
3
|
+
* and array elements.
|
|
4
|
+
*
|
|
5
|
+
* Used to type the payloads accepted by `save`, `saveList`, and `patch`, which
|
|
6
|
+
* don't require every field of the entity to be present.
|
|
7
|
+
*
|
|
8
|
+
* @template T Type to make deeply partial.
|
|
9
|
+
*
|
|
10
|
+
* @publicApi
|
|
11
|
+
*/
|
|
12
|
+
export type DeepPartial<T> = T | (T extends Array<infer U> ? DeepPartial<U>[] : T extends object ? {
|
|
13
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
14
|
+
} : T);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the keys of `T` whose value type is assignable to `K`.
|
|
3
|
+
*
|
|
4
|
+
* Used internally to constrain `pkName` to the fields of the entity that
|
|
5
|
+
* actually match the configured primary key type.
|
|
6
|
+
*
|
|
7
|
+
* @template T Object type to inspect.
|
|
8
|
+
* @template K Value type to filter by.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* type User = { id: string; age: number; name: string };
|
|
13
|
+
* type StringKeys = KeysOfType<User, string>; // "id" | "name"
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @publicApi
|
|
17
|
+
*/
|
|
18
|
+
export type KeysOfType<T, K> = {
|
|
19
|
+
[P in keyof T]: T[P] extends K ? P : never;
|
|
20
|
+
}[keyof T];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SeeMode } from "./see-mode.type";
|
|
2
|
+
import { VSRepoOrmTypes } from "../vsrepo/vsrepo-orm-types.type";
|
|
3
|
+
import { VSRepoRelations } from "../vsrepo/vsrepo-relations.type";
|
|
4
|
+
import { VSRepoSelect } from "../vsrepo/vsrepo-select.type";
|
|
5
|
+
/**
|
|
6
|
+
* Options accepted by the base methods exposed by `VSRepository`
|
|
7
|
+
* (`get`, `getOrThrow`, `save`, `patch`, `remove`, etc) and by dynamic methods.
|
|
8
|
+
*
|
|
9
|
+
* @template T Entity type managed by the repository.
|
|
10
|
+
* @template K ORM type map (`dbClient`/`dbTransaction`) configured on the repository.
|
|
11
|
+
*
|
|
12
|
+
* @publicApi
|
|
13
|
+
*/
|
|
14
|
+
export type MethodOptions<T, K extends VSRepoOrmTypes = VSRepoOrmTypes> = {
|
|
15
|
+
/** Fields (and nested relation fields) to select in the result. */
|
|
16
|
+
select?: VSRepoSelect<T>;
|
|
17
|
+
/** Relations to eagerly load alongside the result. */
|
|
18
|
+
relations?: VSRepoRelations<T>;
|
|
19
|
+
/** Visibility mode for records with soft-delete. Defaults to `"active"`. */
|
|
20
|
+
see?: SeeMode;
|
|
21
|
+
/** Database client or transaction to run this operation in, instead of the repository's default client. */
|
|
22
|
+
db?: K["dbClient"] | K["dbTransaction"];
|
|
23
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Primitive } from "./primitive.type";
|
|
2
|
+
/**
|
|
3
|
+
* Sort direction accepted by `Ordering`. Case-insensitive: both the
|
|
4
|
+
* lowercase (`"asc"`/`"desc"`) and uppercase (`"ASC"`/`"DESC"`) forms are valid.
|
|
5
|
+
*
|
|
6
|
+
* @publicApi
|
|
7
|
+
*/
|
|
8
|
+
export type SortDirection = "asc" | "desc" | "ASC" | "DESC";
|
|
9
|
+
/**
|
|
10
|
+
* Ordering shape for a single level of an entity's fields.
|
|
11
|
+
*
|
|
12
|
+
* Scalar fields accept a `SortDirection` directly; nested object (to-one
|
|
13
|
+
* relation) fields accept a nested `Ordering`. Array (to-many relation)
|
|
14
|
+
* fields are not orderable and are excluded.
|
|
15
|
+
*
|
|
16
|
+
* @template T Entity type being ordered.
|
|
17
|
+
*
|
|
18
|
+
* @publicApi
|
|
19
|
+
*/
|
|
20
|
+
export type OrderByField<T> = {
|
|
21
|
+
[P in keyof T]?: NonNullable<T[P]> extends Primitive ? SortDirection : NonNullable<T[P]> extends Array<any> ? never : NonNullable<T[P]> extends object ? Ordering<NonNullable<T[P]>> : SortDirection;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Ordering accepted by repository methods that support `order`, such as `getAll` or a dynamic method with `Ordered`.
|
|
25
|
+
*
|
|
26
|
+
* Can be a single ordering object or a list of chained orderings, applied in
|
|
27
|
+
* the order they're declared.
|
|
28
|
+
*
|
|
29
|
+
* @template T Entity type being ordered.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const order: Ordering<User> = { createdAt: "desc" };
|
|
34
|
+
* const chained: Ordering<User> = [{ name: "asc" }, { createdAt: "desc" }];
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @publicApi
|
|
38
|
+
*/
|
|
39
|
+
export type Ordering<T> = OrderByField<T> | OrderByField<T>[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pagination options accepted by `getAll` and by dynamic methods with `Paginated`.
|
|
3
|
+
*
|
|
4
|
+
* @publicApi
|
|
5
|
+
*/
|
|
6
|
+
export type Pagination = {
|
|
7
|
+
/** Maximum number of records to return. */
|
|
8
|
+
limit?: number;
|
|
9
|
+
/** Number of records to skip before starting to return results. */
|
|
10
|
+
offset?: number;
|
|
11
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single argument accepted by a method declared with `@QueryMethod`.
|
|
3
|
+
*
|
|
4
|
+
* `args` are injected positionally into the raw SQL statement (`$1`, `$2`, ...),
|
|
5
|
+
* allowing safe parameter injection instead of string-concatenating values
|
|
6
|
+
* directly into the query.
|
|
7
|
+
*
|
|
8
|
+
* @template T Tuple type of the positional SQL parameters, e.g. `[email: string]`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* class UserRepository extends VSRepository<User, string> {
|
|
13
|
+
* @QueryMethod('SELECT * FROM "user" WHERE email = $1')
|
|
14
|
+
* declare findByEmailRaw: (arg: QueryMethodArg<[email: string]>) => Promise<User[]>;
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* await userRepository.findByEmailRaw({ args: ["joao@email.com"] });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @publicApi
|
|
21
|
+
*/
|
|
22
|
+
export type QueryMethodArg<T extends Array<any>> = {
|
|
23
|
+
/** Positional parameters injected into the SQL placeholders (`$1`, `$2`, ...). */
|
|
24
|
+
args?: T;
|
|
25
|
+
/** Database client or transaction to run this query in, instead of the repository's default client. */
|
|
26
|
+
db?: any;
|
|
27
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Visibility mode for records managed by soft-delete.
|
|
3
|
+
*
|
|
4
|
+
* - `"active"` — returns only non-deleted records (default).
|
|
5
|
+
* - `"removed"` — returns only deleted records.
|
|
6
|
+
* - `"all"` — returns all records, regardless of their deletion status.
|
|
7
|
+
*
|
|
8
|
+
* Only has effect when `softRemoveKey` is configured on the repository.
|
|
9
|
+
*
|
|
10
|
+
* @publicApi
|
|
11
|
+
*/
|
|
12
|
+
export type SeeMode = "active" | "removed" | "all";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AdapterMethodOptions } from "../adapter/adapter-method-options.type";
|
|
2
|
+
import { VSRepoWhere } from "./vsrepo-where.type";
|
|
3
|
+
export type VSRepoArgs<T> = {
|
|
4
|
+
where?: VSRepoWhere<T>;
|
|
5
|
+
obj?: object;
|
|
6
|
+
create?: object;
|
|
7
|
+
update?: object;
|
|
8
|
+
options?: AdapterMethodOptions<T>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { VSRepoAdapter } from "../../VSRepoAdapter";
|
|
2
|
+
import { VSLogLevel } from "../../internal/enums/vs-log-level.enum";
|
|
3
|
+
import { KeysOfType } from "../utils/keys-of-type.type";
|
|
4
|
+
import { Ordering } from "../utils/ordering.type";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration passed to the `VSRepository` constructor.
|
|
7
|
+
*
|
|
8
|
+
* @template T Entity type managed by the repository.
|
|
9
|
+
* @template K Type of the entity's primary key value.
|
|
10
|
+
*
|
|
11
|
+
* @publicApi
|
|
12
|
+
*/
|
|
13
|
+
export type VSRepoOptions<T, K> = {
|
|
14
|
+
/** Adapter that translates the repository's operations into calls against the underlying ORM/database. */
|
|
15
|
+
adapter: VSRepoAdapter<T>;
|
|
16
|
+
/** Name of the field that represents the entity's primary key (PK). */
|
|
17
|
+
pkName: KeysOfType<T, K>;
|
|
18
|
+
/**
|
|
19
|
+
* Name of the field used for soft-delete.
|
|
20
|
+
*
|
|
21
|
+
* When configured, enables the `softRemove`, `softRemoveList`, `restore`,
|
|
22
|
+
* and `restoreList` methods.
|
|
23
|
+
*/
|
|
24
|
+
softRemoveKey?: keyof T;
|
|
25
|
+
/** Minimum severity of messages printed by the repository's internal logger. Defaults to `VSLogLevel.WARN`. */
|
|
26
|
+
logLevel?: VSLogLevel;
|
|
27
|
+
/**
|
|
28
|
+
* Duration (in ms) above which a finished operation is logged as WARN
|
|
29
|
+
* instead of DEBUG, flagging potentially slow queries. Defaults to 300ms.
|
|
30
|
+
*/
|
|
31
|
+
logSlowThresholdMs?: number;
|
|
32
|
+
/** Default ordering automatically applied to queries that accept `order`, unless the call overrides it. */
|
|
33
|
+
defaultOrdering?: Ordering<T>;
|
|
34
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Describes the ORM-specific client and transaction types a `VSRepoAdapter`
|
|
3
|
+
* (and the `VSRepository` built on top of it) works with.
|
|
4
|
+
*
|
|
5
|
+
* Implementations provide their own concrete types for `dbClient` and
|
|
6
|
+
* `dbTransaction` (e.g. `PrismaClient`/`Prisma.TransactionClient`), which
|
|
7
|
+
* `VSRepository` then uses to type `getDbClient()`, `transaction()`, and
|
|
8
|
+
* the `db` option accepted by every method.
|
|
9
|
+
*
|
|
10
|
+
* @publicApi
|
|
11
|
+
*/
|
|
12
|
+
export type VSRepoOrmTypes = {
|
|
13
|
+
/** Main database client type used to run queries outside a transaction. */
|
|
14
|
+
dbClient: any;
|
|
15
|
+
/** Transaction client type used to run queries inside a `transaction()` callback. */
|
|
16
|
+
dbTransaction: any;
|
|
17
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { VSRepoOrmTypes } from "./vsrepo-orm-types.type";
|
|
2
|
+
/**
|
|
3
|
+
* Options accepted by `VSRepository.query()`.
|
|
4
|
+
*
|
|
5
|
+
* @publicApi
|
|
6
|
+
*/
|
|
7
|
+
export type VSRepoQueryOptions<T extends VSRepoOrmTypes = VSRepoOrmTypes> = {
|
|
8
|
+
/** Positional parameters injected into the SQL placeholders (`$1`, `$2`, ...). */
|
|
9
|
+
args?: any[];
|
|
10
|
+
/** Database client or transaction to run this query in, instead of the repository's default client. */
|
|
11
|
+
db?: T["dbClient"] | T["dbTransaction"];
|
|
12
|
+
/**
|
|
13
|
+
* Whether this is a modifying statement (`INSERT`/`UPDATE`/`DELETE`).
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
modifying?: boolean;
|
|
17
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Primitive } from "../utils/primitive.type";
|
|
2
|
+
/**
|
|
3
|
+
* Extracts the keys of `T` that represent relation fields (i.e. objects or
|
|
4
|
+
* arrays of objects, as opposed to scalar/`Primitive` fields).
|
|
5
|
+
*
|
|
6
|
+
* @template T Entity type to inspect.
|
|
7
|
+
*
|
|
8
|
+
* @publicApi
|
|
9
|
+
*/
|
|
10
|
+
export type RelationKeys<T> = {
|
|
11
|
+
[P in keyof T]: NonNullable<T[P]> extends Primitive ? never : NonNullable<T[P]> extends Array<infer U> ? NonNullable<U> extends Primitive ? never : P : NonNullable<T[P]> extends object ? P : never;
|
|
12
|
+
}[keyof T];
|
|
13
|
+
/**
|
|
14
|
+
* Shape accepted by the `relations` option of repository/adapter methods,
|
|
15
|
+
* used to eagerly load related records alongside the main result.
|
|
16
|
+
*
|
|
17
|
+
* Each relation field accepts either a `boolean` (load the relation as-is)
|
|
18
|
+
* or a nested `VSRepoRelations` to further eager-load relations of that relation.
|
|
19
|
+
*
|
|
20
|
+
* @template T Entity type being queried.
|
|
21
|
+
*
|
|
22
|
+
* @publicApi
|
|
23
|
+
*/
|
|
24
|
+
export type VSRepoRelations<T> = {
|
|
25
|
+
[P in RelationKeys<T>]?: NonNullable<T[P]> extends Array<infer U> ? U extends object ? boolean | VSRepoRelations<U> : boolean : NonNullable<T[P]> extends object ? boolean | VSRepoRelations<NonNullable<T[P]>> : boolean;
|
|
26
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { VSRepository } from "../../VSRepository";
|
|
2
|
+
import { Pagination } from "../utils/pagination.type";
|
|
3
|
+
import { MethodOptions } from "../utils/methods-options.type";
|
|
4
|
+
export interface VSRepoResolveArgsData<T, K> {
|
|
5
|
+
instance: VSRepository<T, K>;
|
|
6
|
+
options: MethodOptions<T>;
|
|
7
|
+
withoutWhere?: boolean;
|
|
8
|
+
withoutSelect?: boolean;
|
|
9
|
+
specificSelect?: object;
|
|
10
|
+
specificWhere?: object;
|
|
11
|
+
dataPayload?: object;
|
|
12
|
+
createPayload?: object;
|
|
13
|
+
updatePayload?: object;
|
|
14
|
+
pagination?: Pagination;
|
|
15
|
+
ordering?: object | object[];
|
|
16
|
+
ignoreConflicts?: boolean;
|
|
17
|
+
withOrderingAndPagination?: boolean;
|
|
18
|
+
distinctKeys?: string[];
|
|
19
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Primitive } from "../utils/primitive.type";
|
|
2
|
+
/**
|
|
3
|
+
* Selection shape accepted by the `select` option of repository/adapter methods.
|
|
4
|
+
*
|
|
5
|
+
* Scalar fields accept a `boolean`; relation fields accept either a `boolean`
|
|
6
|
+
* (select the relation with all of its own scalar fields) or a nested
|
|
7
|
+
* `VSRepoSelect` to further restrict which fields of the relation are returned.
|
|
8
|
+
*
|
|
9
|
+
* @template T Entity type being selected from.
|
|
10
|
+
*
|
|
11
|
+
* @publicApi
|
|
12
|
+
*/
|
|
13
|
+
export type VSRepoSelect<T> = {
|
|
14
|
+
[P in keyof T]?: NonNullable<T[P]> extends Primitive ? boolean : NonNullable<T[P]> extends Array<infer U> ? U extends Primitive ? boolean : VSRepoSelect<U> | boolean : NonNullable<T[P]> extends object ? VSRepoSelect<NonNullable<T[P]>> | boolean : boolean;
|
|
15
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TransactionIsolationLevel } from "../../internal/enums/transaction-isolation-level.enum";
|
|
2
|
+
/**
|
|
3
|
+
* Options accepted by `VSRepository.transaction()`.
|
|
4
|
+
*
|
|
5
|
+
* @publicApi
|
|
6
|
+
*/
|
|
7
|
+
export type VSRepoTransactionOptions = {
|
|
8
|
+
/** Isolation level to use for the transaction. Defaults to the underlying ORM's default. */
|
|
9
|
+
isolationLevel?: TransactionIsolationLevel;
|
|
10
|
+
/** Maximum time (in ms) the transaction is allowed to run before being aborted. */
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Primitive } from "../utils/primitive.type";
|
|
2
|
+
/**
|
|
3
|
+
* Operators available to filter a single scalar field's value.
|
|
4
|
+
*
|
|
5
|
+
* The set of operators offered narrows based on `V`'s type: numbers and dates
|
|
6
|
+
* additionally get `between`; strings additionally get `contains`, `startsWith`,
|
|
7
|
+
* `endsWith`, and `ignoreCase`; every non-boolean type additionally gets
|
|
8
|
+
* `in`, `notIn`, `gt`, `gte`, `lt`, and `lte`.
|
|
9
|
+
*
|
|
10
|
+
* @template V Type of the field's value.
|
|
11
|
+
*
|
|
12
|
+
* @publicApi
|
|
13
|
+
*/
|
|
14
|
+
export type VSRepoFieldOperators<V> = {
|
|
15
|
+
/** Matches records where the field equals `V`. */
|
|
16
|
+
equals?: V;
|
|
17
|
+
/** Negates the given value or operator object. */
|
|
18
|
+
not?: V | VSRepoFieldOperators<V>;
|
|
19
|
+
} & (V extends number | Date ? {
|
|
20
|
+
/** Matches records where the field is between the given `[min, max]` tuple, inclusive. */
|
|
21
|
+
between?: [V, V];
|
|
22
|
+
} : {}) & (V extends string ? {
|
|
23
|
+
/** Matches records where the field contains the given substring. */
|
|
24
|
+
contains?: string;
|
|
25
|
+
/** Matches records where the field starts with the given substring. */
|
|
26
|
+
startsWith?: string;
|
|
27
|
+
/** Matches records where the field ends with the given substring. */
|
|
28
|
+
endsWith?: string;
|
|
29
|
+
/** Applies the string filters above case-insensitively. */
|
|
30
|
+
ignoreCase?: boolean;
|
|
31
|
+
} : {}) & (V extends boolean ? {} : {
|
|
32
|
+
/** Matches records where the field is one of the given values. */
|
|
33
|
+
in?: V[];
|
|
34
|
+
/** Matches records where the field is none of the given values. */
|
|
35
|
+
notIn?: V[];
|
|
36
|
+
/** Matches records where the field is greater than the given value. */
|
|
37
|
+
gt?: V;
|
|
38
|
+
/** Matches records where the field is greater than or equal to the given value. */
|
|
39
|
+
gte?: V;
|
|
40
|
+
/** Matches records where the field is less than the given value. */
|
|
41
|
+
lt?: V;
|
|
42
|
+
/** Matches records where the field is less than or equal to the given value. */
|
|
43
|
+
lte?: V;
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* Value accepted for a single scalar field in a `VSRepoWhere`/`VSRepoWherePlain`
|
|
47
|
+
* filter: either a direct value (shorthand for `equals`) or a `VSRepoFieldOperators` object.
|
|
48
|
+
*
|
|
49
|
+
* @template V Type of the field's value.
|
|
50
|
+
*
|
|
51
|
+
* @publicApi
|
|
52
|
+
*/
|
|
53
|
+
export type VSRepoFieldWhere<V> = V | VSRepoFieldOperators<V>;
|
|
54
|
+
/**
|
|
55
|
+
* Field-level filters for an entity, without the top-level `AND`/`OR`/`NOT`
|
|
56
|
+
* logical operators (see `VSRepoWhere` for those).
|
|
57
|
+
*
|
|
58
|
+
* Scalar fields accept a `VSRepoFieldWhere`. To-many relation fields accept
|
|
59
|
+
* `_some`/`_every`/`_none` filters, applied to the related records. To-one
|
|
60
|
+
* relation fields accept `_with`/`_without` filters.
|
|
61
|
+
*
|
|
62
|
+
* @template T Entity type being filtered.
|
|
63
|
+
*
|
|
64
|
+
* @publicApi
|
|
65
|
+
*/
|
|
66
|
+
export type VSRepoWherePlain<T> = {
|
|
67
|
+
[P in keyof T]?: NonNullable<T[P]> extends Primitive ? VSRepoFieldWhere<T[P]> : NonNullable<T[P]> extends Array<infer U> ? U extends object ? {
|
|
68
|
+
/** Matches records where at least one related record matches the given filter. */
|
|
69
|
+
_some?: VSRepoWherePlain<U>;
|
|
70
|
+
/** Matches records where every related record matches the given filter. */
|
|
71
|
+
_every?: VSRepoWherePlain<U>;
|
|
72
|
+
/** Matches records where no related record matches the given filter. */
|
|
73
|
+
_none?: VSRepoWherePlain<U>;
|
|
74
|
+
} : VSRepoFieldWhere<T[P]> : NonNullable<T[P]> extends object ? {
|
|
75
|
+
/** Matches records whose related record matches the given filter. */
|
|
76
|
+
_with?: VSRepoWherePlain<NonNullable<T[P]>>;
|
|
77
|
+
/** Matches records whose related record does not match the given filter. */
|
|
78
|
+
_without?: VSRepoWherePlain<NonNullable<T[P]>>;
|
|
79
|
+
} : VSRepoFieldWhere<T[P]>;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Filter shape accepted by the `where` clause of repository/adapter methods.
|
|
83
|
+
*
|
|
84
|
+
* Combines `VSRepoWherePlain`'s field-level filters with the top-level
|
|
85
|
+
* logical operators `AND`, `OR`, and `NOT`, each accepting either a single
|
|
86
|
+
* filter object or a list of them.
|
|
87
|
+
*
|
|
88
|
+
* @template T Entity type being filtered.
|
|
89
|
+
*
|
|
90
|
+
* @publicApi
|
|
91
|
+
*/
|
|
92
|
+
export type VSRepoWhere<T> = VSRepoWherePlain<T> & {
|
|
93
|
+
/** Combines multiple filters, matching records that satisfy all of them. */
|
|
94
|
+
AND?: VSRepoWherePlain<T> | VSRepoWherePlain<T>[];
|
|
95
|
+
/** Combines multiple filters, matching records that satisfy at least one of them. */
|
|
96
|
+
OR?: VSRepoWherePlain<T> | VSRepoWherePlain<T>[];
|
|
97
|
+
/** Negates one or more filters, matching records that satisfy none of them. */
|
|
98
|
+
NOT?: VSRepoWherePlain<T> | VSRepoWherePlain<T>[];
|
|
99
|
+
};
|