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.
Files changed (151) hide show
  1. package/README.md +827 -1322
  2. package/README.pt-BR.md +833 -1325
  3. package/dist/VSRepoAdapter.d.ts +109 -0
  4. package/dist/VSRepoAdapter.js +18 -0
  5. package/dist/VSRepository.d.ts +166 -1201
  6. package/dist/VSRepository.js +327 -237
  7. package/dist/decorators/dynamic-method.decorator.d.ts +25 -0
  8. package/dist/decorators/dynamic-method.decorator.js +38 -0
  9. package/dist/decorators/query-method.decorator.d.ts +27 -0
  10. package/dist/decorators/query-method.decorator.js +45 -0
  11. package/dist/errors/VSRepoAdapterError.d.ts +22 -0
  12. package/dist/errors/VSRepoAdapterError.js +31 -0
  13. package/dist/errors/VSRepoError.d.ts +15 -0
  14. package/dist/errors/VSRepoError.js +21 -0
  15. package/dist/index.d.ts +38 -1
  16. package/dist/index.js +28 -15
  17. package/dist/internal/constants/debug-arg-symbol.constant.d.ts +1 -0
  18. package/dist/internal/constants/debug-arg-symbol.constant.js +4 -0
  19. package/dist/internal/constants/dynamic-methods-key.constant.d.ts +1 -0
  20. package/dist/internal/constants/query-methods-key.constant.d.ts +1 -0
  21. package/dist/internal/constants/query-methods-key.constant.js +4 -0
  22. package/dist/internal/enums/adapter-error-code.enum.d.ts +125 -0
  23. package/dist/internal/enums/adapter-error-code.enum.js +129 -0
  24. package/dist/internal/enums/transaction-isolation-level.enum.d.ts +16 -0
  25. package/dist/internal/enums/transaction-isolation-level.enum.js +20 -0
  26. package/dist/internal/enums/vs-log-level.enum.d.ts +18 -0
  27. package/dist/internal/enums/vs-log-level.enum.js +22 -0
  28. package/dist/internal/enums/vsrepo-error-type.enum.d.ts +19 -0
  29. package/dist/internal/enums/vsrepo-error-type.enum.js +23 -0
  30. package/dist/internal/resolvers/dynamic-methods.resolver.d.ts +23 -0
  31. package/dist/internal/resolvers/dynamic-methods.resolver.js +910 -0
  32. package/dist/internal/resolvers/merge-wheres.resolver.d.ts +7 -0
  33. package/dist/internal/resolvers/merge-wheres.resolver.js +26 -0
  34. package/dist/internal/utils/uncapitalize.util.d.ts +1 -0
  35. package/dist/internal/utils/vs-logger.util.d.ts +25 -0
  36. package/dist/internal/utils/vs-logger.util.js +139 -0
  37. package/dist/internal/validators/decorators.validator.d.ts +8 -0
  38. package/dist/internal/validators/decorators.validator.js +75 -0
  39. package/dist/internal/validators/schemas/ordering.schema.d.ts +3 -0
  40. package/dist/internal/validators/schemas/ordering.schema.js +38 -0
  41. package/dist/internal/validators/schemas/pagination.schema.d.ts +6 -0
  42. package/dist/internal/validators/schemas/pagination.schema.js +40 -0
  43. package/dist/internal/validators/schemas/where.schema.d.ts +7 -0
  44. package/dist/internal/validators/schemas/where.schema.js +42 -0
  45. package/dist/internal/validators/vsrepo.validator.d.ts +40 -0
  46. package/dist/internal/validators/vsrepo.validator.js +182 -0
  47. package/dist/types/adapter/adapter-method-options.type.d.ts +24 -0
  48. package/dist/types/adapter/adapter-query-options.type.d.ts +5 -0
  49. package/dist/types/decorators/dynamic-method-options.type.d.ts +14 -0
  50. package/dist/types/decorators/query-method-options.type.d.ts +15 -0
  51. package/dist/types/dynamic-methods/dynamic-method-customization.type.d.ts +7 -0
  52. package/dist/types/dynamic-methods/dynamic-method-info.type.d.ts +18 -0
  53. package/dist/types/dynamic-methods/dynamic-method-where-ops.type.d.ts +6 -0
  54. package/dist/types/utils/count-result.type.d.ts +9 -0
  55. package/dist/types/utils/decimal-like.type.d.ts +23 -0
  56. package/dist/types/utils/deep-partial.type.d.ts +14 -0
  57. package/dist/types/utils/keys-of-type.type.d.ts +20 -0
  58. package/dist/types/utils/methods-options.type.d.ts +23 -0
  59. package/dist/types/utils/numeric-keys.type.d.ts +24 -0
  60. package/dist/types/utils/numeric-like.type.d.ts +10 -0
  61. package/dist/types/utils/ordering.type.d.ts +39 -0
  62. package/dist/types/utils/pagination.type.d.ts +11 -0
  63. package/dist/types/utils/perform-data.type.d.ts +4 -0
  64. package/dist/types/utils/primitive.type.d.ts +7 -0
  65. package/dist/types/utils/query-method-arg.type.d.ts +27 -0
  66. package/dist/types/utils/restrict-method-options.type.d.ts +14 -0
  67. package/dist/types/utils/see-mode.type.d.ts +12 -0
  68. package/dist/types/vsrepo/vsrepo-args.type.d.ts +9 -0
  69. package/dist/types/vsrepo/vsrepo-method.type.d.ts +4 -0
  70. package/dist/types/vsrepo/vsrepo-method.type.js +2 -0
  71. package/dist/types/vsrepo/vsrepo-options.type.d.ts +34 -0
  72. package/dist/types/vsrepo/vsrepo-options.type.js +2 -0
  73. package/dist/types/vsrepo/vsrepo-orm-types.type.d.ts +17 -0
  74. package/dist/types/vsrepo/vsrepo-orm-types.type.js +2 -0
  75. package/dist/types/vsrepo/vsrepo-pretty-where.type.d.ts +7 -0
  76. package/dist/types/vsrepo/vsrepo-pretty-where.type.js +2 -0
  77. package/dist/types/vsrepo/vsrepo-query-options.type.d.ts +17 -0
  78. package/dist/types/vsrepo/vsrepo-query-options.type.js +2 -0
  79. package/dist/types/vsrepo/vsrepo-query.type.d.ts +5 -0
  80. package/dist/types/vsrepo/vsrepo-query.type.js +2 -0
  81. package/dist/types/vsrepo/vsrepo-relations.type.d.ts +26 -0
  82. package/dist/types/vsrepo/vsrepo-relations.type.js +2 -0
  83. package/dist/types/vsrepo/vsrepo-resolve-args-data.type.d.ts +19 -0
  84. package/dist/types/vsrepo/vsrepo-resolve-args-data.type.js +2 -0
  85. package/dist/types/vsrepo/vsrepo-select.type.d.ts +15 -0
  86. package/dist/types/vsrepo/vsrepo-select.type.js +2 -0
  87. package/dist/types/vsrepo/vsrepo-transaction-options.type.d.ts +12 -0
  88. package/dist/types/vsrepo/vsrepo-transaction-options.type.js +2 -0
  89. package/dist/types/vsrepo/vsrepo-ugly-where.type.d.ts +9 -0
  90. package/dist/types/vsrepo/vsrepo-ugly-where.type.js +2 -0
  91. package/dist/types/vsrepo/vsrepo-where.type.d.ts +99 -0
  92. package/dist/types/vsrepo/vsrepo-where.type.js +2 -0
  93. package/package.json +16 -37
  94. package/README-DynamicRepo.md +0 -625
  95. package/README-DynamicRepo.pt-BR.md +0 -625
  96. package/dist/DynamicRepository.d.ts +0 -497
  97. package/dist/DynamicRepository.js +0 -26
  98. package/dist/VSRepoError.d.ts +0 -83
  99. package/dist/VSRepoError.js +0 -17
  100. package/dist/internal/decorators/dynamic-method.decorator.js +0 -14
  101. package/dist/internal/decorators/query-method.decorator.js +0 -20
  102. package/dist/internal/entities/dynamic-method-metadata.entity.js +0 -26
  103. package/dist/internal/errors/vs-repo.error.js +0 -31
  104. package/dist/internal/resolvers/base-methods.resolve.js +0 -541
  105. package/dist/internal/resolvers/create-update-payloads-with-relations.resolve.js +0 -143
  106. package/dist/internal/resolvers/data-payload-with-relations.resolve.js +0 -60
  107. package/dist/internal/resolvers/dbAndPrismaArgs.resolve.js +0 -63
  108. package/dist/internal/resolvers/dynamic-method-customization.resolve.js +0 -57
  109. package/dist/internal/resolvers/dynamic-method-info.resolve.js +0 -279
  110. package/dist/internal/resolvers/dynamic-methods-metadata.resolve.js +0 -15
  111. package/dist/internal/resolvers/merge-wheres.resolve.js +0 -22
  112. package/dist/internal/resolvers/pretty-wheres.resolve.js +0 -87
  113. package/dist/internal/resolvers/select.resolve.js +0 -7
  114. package/dist/internal/resolvers/specific-where.resolve.js +0 -84
  115. package/dist/internal/resolvers/ugly-where.resolve.js +0 -178
  116. package/dist/internal/utils/logger.util.js +0 -21
  117. package/dist/internal/utils/schemas.util.js +0 -31
  118. package/dist/internal/validation/build-config.validate.js +0 -84
  119. package/dist/internal/validation/constructor-config.validate.js +0 -64
  120. package/dist/internal/validation/dynamic-method-config.validate.js +0 -19
  121. package/dist/internal/validation/extension.validate.js +0 -15
  122. package/dist/internal/validation/is-object.validate.js +0 -6
  123. package/dist/internal/validation/method-options.validate.js +0 -42
  124. package/dist/internal/validation/obj-with-relations.validate.js +0 -37
  125. package/dist/internal/validation/prisma-client.validate.js +0 -10
  126. package/dist/internal/validation/query-method-arg.validate.js +0 -22
  127. package/dist/internal/validation/query-method-options.validate.js +0 -24
  128. package/scripts/configure-prisma-import.mjs +0 -283
  129. package/scripts/copy-types.mjs +0 -24
  130. /package/dist/{internal/decorators/types/dynamic-method-config.type.js → types/adapter/adapter-method-options.type.js} +0 -0
  131. /package/dist/{internal/errors/types/vs-repo-error-type.type.js → types/adapter/adapter-query-options.type.js} +0 -0
  132. /package/dist/{internal/errors/types/vs-repo-runtime-error-code.type.js → types/decorators/dynamic-method-options.type.js} +0 -0
  133. /package/dist/{internal/validation/types → types/decorators}/query-method-options.type.js +0 -0
  134. /package/dist/{internal/resolvers/types → types/dynamic-methods}/dynamic-method-customization.type.js +0 -0
  135. /package/dist/{internal/resolvers/types → types/dynamic-methods}/dynamic-method-info.type.js +0 -0
  136. /package/dist/{internal/resolvers/types → types/dynamic-methods}/dynamic-method-where-ops.type.js +0 -0
  137. /package/dist/{internal/resolvers/types/base-method-function.type.js → types/utils/count-result.type.js} +0 -0
  138. /package/dist/{internal/resolvers/types/pretty-where.type.js → types/utils/decimal-like.type.js} +0 -0
  139. /package/dist/{internal/resolvers/types/prisma-args.type.js → types/utils/deep-partial.type.js} +0 -0
  140. /package/dist/{internal/resolvers/types/repository-build-instance.type.js → types/utils/keys-of-type.type.js} +0 -0
  141. /package/dist/{internal/resolvers/types/resolve-db-and-prisma-args-data.type.js → types/utils/methods-options.type.js} +0 -0
  142. /package/dist/{internal/resolvers/types/ugly-where.type.js → types/utils/numeric-keys.type.js} +0 -0
  143. /package/dist/{internal/validation/types/base-methods.type.js → types/utils/numeric-like.type.js} +0 -0
  144. /package/dist/{internal/validation/types/build-config.type.js → types/utils/ordering.type.js} +0 -0
  145. /package/dist/{internal/validation/types → types/utils}/pagination.type.js +0 -0
  146. /package/dist/{internal/validation/types/constructor-config.type.js → types/utils/perform-data.type.js} +0 -0
  147. /package/dist/{internal/validation/types/method-options.type.js → types/utils/primitive.type.js} +0 -0
  148. /package/dist/{internal/validation/types → types/utils}/query-method-arg.type.js +0 -0
  149. /package/dist/{internal/validation/types/method.type.js → types/utils/restrict-method-options.type.js} +0 -0
  150. /package/dist/{internal/validation/types → types/utils}/see-mode.type.js +0 -0
  151. /package/dist/{internal/validation/types/relation.type.js → types/vsrepo/vsrepo-args.type.js} +0 -0
@@ -0,0 +1,24 @@
1
+ import { Ordering } from "../utils/ordering.type";
2
+ import { Pagination } from "../utils/pagination.type";
3
+ import { VSRepoRelations } from "../vsrepo/vsrepo-relations.type";
4
+ import { VSRepoSelect } from "../vsrepo/vsrepo-select.type";
5
+ /**
6
+ * Options passed down to a `VSRepoAdapter` method call, after `VSRepository`
7
+ * has resolved and validated the caller-provided `MethodOptions`.
8
+ *
9
+ * @template T Entity type managed by the repository.
10
+ *
11
+ * @publicApi
12
+ */
13
+ export type AdapterMethodOptions<T> = {
14
+ /** Fields (and nested relation fields) to select in the result. */
15
+ select?: VSRepoSelect<T>;
16
+ /** Relations to eagerly load alongside the result. */
17
+ relations?: VSRepoRelations<T>;
18
+ /** Pagination to apply to the query. */
19
+ pagination?: Pagination;
20
+ /** Ordering to apply to the query. */
21
+ order?: Ordering<T>;
22
+ /** Database client or transaction to run this operation in. */
23
+ db?: any;
24
+ };
@@ -0,0 +1,5 @@
1
+ export type AdapterQueryOptions = {
2
+ args?: any[];
3
+ db?: any;
4
+ modifying: boolean;
5
+ };
@@ -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,7 @@
1
+ export interface DynamicMethodCustomization {
2
+ ignoreConflicts?: boolean;
3
+ orderPosition?: number;
4
+ paginationPosition?: number;
5
+ injectOrdering?: object | object[];
6
+ distinctKeys?: string[];
7
+ }
@@ -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,6 @@
1
+ import { VSRepoPrettyWhere } from "../vsrepo/vsrepo-pretty-where.type";
2
+ import { VSRepoUglyWhere } from "../vsrepo/vsrepo-ugly-where.type";
3
+ export interface DynamicMethodWhereOps {
4
+ uglyWheres: VSRepoUglyWhere[];
5
+ prettyWheres: VSRepoPrettyWhere[];
6
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Return type of batch operations that report how many records were affected,
3
+ * such as `removeList`, `softRemoveList`, and `restoreList`.
4
+ *
5
+ * @publicApi
6
+ */
7
+ export type CountResult = {
8
+ count: number;
9
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Structural shape of an arbitrary-precision "Decimal" value, as commonly
3
+ * returned by ORMs for `decimal`/`numeric` columns (e.g. Prisma's
4
+ * `Prisma.Decimal`, built on top of `decimal.js`).
5
+ *
6
+ * Matched structurally (duck-typed) instead of importing a concrete class,
7
+ * so the core stays ORM-agnostic — any object exposing both `toNumber()`
8
+ * and `decimalPlaces()` is treated as Decimal-like by {@link NumericLike}
9
+ * and, transitively, by {@link NumericKeys}.
10
+ *
11
+ * Note that several ORMs (e.g. Drizzle, MikroORM, TypeORM) represent
12
+ * `decimal`/`numeric` columns as plain `string` by default, to avoid
13
+ * floating-point precision loss — a `string` value does **not** satisfy
14
+ * `DecimalLike`. Configure the column in a numeric mode (or provide a
15
+ * transformer) on those ORMs if you want the field to be eligible for
16
+ * `increment`/`decrement`/`multiply`/`divide`/`sum`/`average`/`min`/`max`.
17
+ *
18
+ * @publicApi
19
+ */
20
+ export type DecimalLike = {
21
+ toNumber(): number;
22
+ decimalPlaces(): number;
23
+ };
@@ -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,24 @@
1
+ import { NumericLike } from "./numeric-like.type";
2
+ /**
3
+ * Extracts the keys of `T` whose (non-nullable) value type is assignable to
4
+ * {@link NumericLike} — i.e. the fields eligible as the `field` argument of
5
+ * `increment`/`decrement`/`multiply`/`divide`/`sum`/`average`/`min`/`max`.
6
+ *
7
+ * Nullable/optional numeric fields (e.g. `number | null`) ARE included —
8
+ * the `null`/`undefined` part is stripped before the check, it isn't a
9
+ * reason to exclude the field. This means a field that is currently `NULL`
10
+ * in the database can be targeted; be aware that in standard SQL, arithmetic
11
+ * against a `NULL` value (`NULL + 5`) itself stays `NULL` — this type only
12
+ * governs what compiles, not the row's runtime value.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * type Product = { id: string; price: Decimal; stock: number | null; name: string };
17
+ * type Numeric = NumericKeys<Product>; // "price" | "stock"
18
+ * ```
19
+ *
20
+ * @publicApi
21
+ */
22
+ export type NumericKeys<T> = {
23
+ [P in keyof T]: NonNullable<T[P]> extends NumericLike ? P : never;
24
+ }[keyof T];
@@ -0,0 +1,10 @@
1
+ import { DecimalLike } from "./decimal-like.type";
2
+ /**
3
+ * Union of value types accepted as "numeric" by the atomic
4
+ * (`increment`/`decrement`/`multiply`/`divide`) and aggregate
5
+ * (`sum`/`average`/`min`/`max`) operations: a native `number`, a native
6
+ * `bigint`, or a {@link DecimalLike} object.
7
+ *
8
+ * @publicApi
9
+ */
10
+ export type NumericLike = number | bigint | DecimalLike;
@@ -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,4 @@
1
+ export type PerformData = {
2
+ start: number;
3
+ operation: string;
4
+ };
@@ -0,0 +1,7 @@
1
+ import { DecimalLike } from "./decimal-like.type";
2
+ /**
3
+ * Types treated as scalar (non-relation) values when walking an entity's shape.
4
+ *
5
+ * @publicApi
6
+ */
7
+ export type Primitive = string | number | boolean | bigint | symbol | undefined | null | Date | DecimalLike;
@@ -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,14 @@
1
+ import { VSRepoOrmTypes } from "../vsrepo/vsrepo-orm-types.type";
2
+ import { MethodOptions } from "./methods-options.type";
3
+ /**
4
+ * Narrowed variant of {@link MethodOptions} exposing only `db` and `see`.
5
+ *
6
+ * Used by base methods that don't shape/return an `Entity` — count-like
7
+ * operations (`total`, `has`, `sum`, `average`, `min`, `max`) and
8
+ * batch-delete-like operations (`removeList`, `softRemoveList`,
9
+ * `restoreList`) — where `select`/`relations` (which only make sense when
10
+ * an `Entity` is being returned) don't apply.
11
+ *
12
+ * @publicApi
13
+ */
14
+ export type RestrictMethodOptions<T, O extends VSRepoOrmTypes = VSRepoOrmTypes> = Pick<MethodOptions<T, O>, "db" | "see">;
@@ -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,4 @@
1
+ import { DynamicMethodOptions } from "../decorators/dynamic-method-options.type";
2
+ export type VSRepoMethod<T = any> = DynamicMethodOptions<T> & {
3
+ propertyKey: string | symbol;
4
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ export interface VSRepoPrettyWhere {
2
+ context: (string | number)[];
3
+ argName: string;
4
+ autoVal?: boolean | {} | null;
5
+ otherProps?: Record<string, unknown>;
6
+ betweenMode?: boolean;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { QueryMethodOptions } from "../decorators/query-method-options.type";
2
+ export type VSRepoQuery = QueryMethodOptions & {
3
+ propertyKey: string | symbol;
4
+ value: string;
5
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ export type VSRepoUglyWhere = {
2
+ pushProperty: string;
3
+ autoInjectVal?: boolean | {} | null;
4
+ properties?: {
5
+ ignoreCase?: boolean;
6
+ };
7
+ betweenMode?: boolean;
8
+ name: string;
9
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });