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.
Files changed (143) hide show
  1. package/README.md +723 -1338
  2. package/README.pt-BR.md +729 -1341
  3. package/dist/VSRepoAdapter.d.ts +71 -0
  4. package/dist/VSRepoAdapter.js +18 -0
  5. package/dist/VSRepository.d.ts +135 -1201
  6. package/dist/VSRepository.js +273 -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 +34 -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 +33 -0
  46. package/dist/internal/validators/vsrepo.validator.js +160 -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/deep-partial.type.d.ts +14 -0
  56. package/dist/types/utils/keys-of-type.type.d.ts +20 -0
  57. package/dist/types/utils/methods-options.type.d.ts +23 -0
  58. package/dist/types/utils/ordering.type.d.ts +39 -0
  59. package/dist/types/utils/pagination.type.d.ts +11 -0
  60. package/dist/types/utils/perform-data.type.d.ts +4 -0
  61. package/dist/types/utils/primitive.type.d.ts +6 -0
  62. package/dist/types/utils/query-method-arg.type.d.ts +27 -0
  63. package/dist/types/utils/see-mode.type.d.ts +12 -0
  64. package/dist/types/vsrepo/vsrepo-args.type.d.ts +9 -0
  65. package/dist/types/vsrepo/vsrepo-method.type.d.ts +4 -0
  66. package/dist/types/vsrepo/vsrepo-options.type.d.ts +34 -0
  67. package/dist/types/vsrepo/vsrepo-orm-types.type.d.ts +17 -0
  68. package/dist/types/vsrepo/vsrepo-pretty-where.type.d.ts +7 -0
  69. package/dist/types/vsrepo/vsrepo-query-options.type.d.ts +17 -0
  70. package/dist/types/vsrepo/vsrepo-query-options.type.js +2 -0
  71. package/dist/types/vsrepo/vsrepo-query.type.d.ts +5 -0
  72. package/dist/types/vsrepo/vsrepo-query.type.js +2 -0
  73. package/dist/types/vsrepo/vsrepo-relations.type.d.ts +26 -0
  74. package/dist/types/vsrepo/vsrepo-relations.type.js +2 -0
  75. package/dist/types/vsrepo/vsrepo-resolve-args-data.type.d.ts +19 -0
  76. package/dist/types/vsrepo/vsrepo-resolve-args-data.type.js +2 -0
  77. package/dist/types/vsrepo/vsrepo-select.type.d.ts +15 -0
  78. package/dist/types/vsrepo/vsrepo-select.type.js +2 -0
  79. package/dist/types/vsrepo/vsrepo-transaction-options.type.d.ts +12 -0
  80. package/dist/types/vsrepo/vsrepo-transaction-options.type.js +2 -0
  81. package/dist/types/vsrepo/vsrepo-ugly-where.type.d.ts +9 -0
  82. package/dist/types/vsrepo/vsrepo-ugly-where.type.js +2 -0
  83. package/dist/types/vsrepo/vsrepo-where.type.d.ts +99 -0
  84. package/dist/types/vsrepo/vsrepo-where.type.js +2 -0
  85. package/package.json +16 -37
  86. package/README-DynamicRepo.md +0 -625
  87. package/README-DynamicRepo.pt-BR.md +0 -625
  88. package/dist/DynamicRepository.d.ts +0 -497
  89. package/dist/DynamicRepository.js +0 -26
  90. package/dist/VSRepoError.d.ts +0 -83
  91. package/dist/VSRepoError.js +0 -17
  92. package/dist/internal/decorators/dynamic-method.decorator.js +0 -14
  93. package/dist/internal/decorators/query-method.decorator.js +0 -20
  94. package/dist/internal/entities/dynamic-method-metadata.entity.js +0 -26
  95. package/dist/internal/errors/vs-repo.error.js +0 -31
  96. package/dist/internal/resolvers/base-methods.resolve.js +0 -536
  97. package/dist/internal/resolvers/create-update-payloads-with-relations.resolve.js +0 -143
  98. package/dist/internal/resolvers/data-payload-with-relations.resolve.js +0 -60
  99. package/dist/internal/resolvers/dbAndPrismaArgs.resolve.js +0 -63
  100. package/dist/internal/resolvers/dynamic-method-customization.resolve.js +0 -57
  101. package/dist/internal/resolvers/dynamic-method-info.resolve.js +0 -279
  102. package/dist/internal/resolvers/dynamic-methods-metadata.resolve.js +0 -15
  103. package/dist/internal/resolvers/merge-wheres.resolve.js +0 -22
  104. package/dist/internal/resolvers/pretty-wheres.resolve.js +0 -87
  105. package/dist/internal/resolvers/select.resolve.js +0 -7
  106. package/dist/internal/resolvers/specific-where.resolve.js +0 -84
  107. package/dist/internal/resolvers/ugly-where.resolve.js +0 -178
  108. package/dist/internal/utils/logger.util.js +0 -21
  109. package/dist/internal/utils/schemas.util.js +0 -31
  110. package/dist/internal/validation/build-config.validate.js +0 -84
  111. package/dist/internal/validation/constructor-config.validate.js +0 -64
  112. package/dist/internal/validation/dynamic-method-config.validate.js +0 -19
  113. package/dist/internal/validation/extension.validate.js +0 -15
  114. package/dist/internal/validation/is-object.validate.js +0 -6
  115. package/dist/internal/validation/method-options.validate.js +0 -42
  116. package/dist/internal/validation/obj-with-relations.validate.js +0 -37
  117. package/dist/internal/validation/prisma-client.validate.js +0 -10
  118. package/dist/internal/validation/query-method-arg.validate.js +0 -22
  119. package/dist/internal/validation/query-method-options.validate.js +0 -24
  120. package/scripts/configure-prisma-import.mjs +0 -283
  121. package/scripts/copy-types.mjs +0 -24
  122. /package/dist/{internal/decorators/types/dynamic-method-config.type.js → types/adapter/adapter-method-options.type.js} +0 -0
  123. /package/dist/{internal/errors/types/vs-repo-error-type.type.js → types/adapter/adapter-query-options.type.js} +0 -0
  124. /package/dist/{internal/errors/types/vs-repo-runtime-error-code.type.js → types/decorators/dynamic-method-options.type.js} +0 -0
  125. /package/dist/{internal/validation/types → types/decorators}/query-method-options.type.js +0 -0
  126. /package/dist/{internal/resolvers/types → types/dynamic-methods}/dynamic-method-customization.type.js +0 -0
  127. /package/dist/{internal/resolvers/types → types/dynamic-methods}/dynamic-method-info.type.js +0 -0
  128. /package/dist/{internal/resolvers/types → types/dynamic-methods}/dynamic-method-where-ops.type.js +0 -0
  129. /package/dist/{internal/resolvers/types/base-method-function.type.js → types/utils/count-result.type.js} +0 -0
  130. /package/dist/{internal/resolvers/types/pretty-where.type.js → types/utils/deep-partial.type.js} +0 -0
  131. /package/dist/{internal/resolvers/types/prisma-args.type.js → types/utils/keys-of-type.type.js} +0 -0
  132. /package/dist/{internal/resolvers/types/repository-build-instance.type.js → types/utils/methods-options.type.js} +0 -0
  133. /package/dist/{internal/resolvers/types/resolve-db-and-prisma-args-data.type.js → types/utils/ordering.type.js} +0 -0
  134. /package/dist/{internal/validation/types → types/utils}/pagination.type.js +0 -0
  135. /package/dist/{internal/resolvers/types/ugly-where.type.js → types/utils/perform-data.type.js} +0 -0
  136. /package/dist/{internal/validation/types/base-methods.type.js → types/utils/primitive.type.js} +0 -0
  137. /package/dist/{internal/validation/types → types/utils}/query-method-arg.type.js +0 -0
  138. /package/dist/{internal/validation/types → types/utils}/see-mode.type.js +0 -0
  139. /package/dist/{internal/validation/types/build-config.type.js → types/vsrepo/vsrepo-args.type.js} +0 -0
  140. /package/dist/{internal/validation/types/constructor-config.type.js → types/vsrepo/vsrepo-method.type.js} +0 -0
  141. /package/dist/{internal/validation/types/method-options.type.js → types/vsrepo/vsrepo-options.type.js} +0 -0
  142. /package/dist/{internal/validation/types/method.type.js → types/vsrepo/vsrepo-orm-types.type.js} +0 -0
  143. /package/dist/{internal/validation/types/relation.type.js → types/vsrepo/vsrepo-pretty-where.type.js} +0 -0
@@ -0,0 +1,71 @@
1
+ import { AdapterMethodOptions } from "./types/adapter/adapter-method-options.type";
2
+ import { AdapterQueryOptions } from "./types/adapter/adapter-query-options.type";
3
+ import { CountResult } from "./types/utils/count-result.type";
4
+ import { DeepPartial } from "./types/utils/deep-partial.type";
5
+ import { VSRepoTransactionOptions } from "./types/vsrepo/vsrepo-transaction-options.type";
6
+ import { VSRepoWhere } from "./types/vsrepo/vsrepo-where.type";
7
+ /**
8
+ * Contract implemented by ORM-specific adapters (e.g. Prisma, TypeORM) that
9
+ * `VSRepository` delegates every operation to.
10
+ *
11
+ * Implementing this class is what makes `VSRepository` usable with a given
12
+ * ORM/database: `VSRepository` never talks to the ORM directly, it only
13
+ * calls these methods with already-resolved `VSRepoWhere`/`AdapterMethodOptions`.
14
+ *
15
+ * @template T Entity type this adapter operates on.
16
+ *
17
+ * @publicApi
18
+ */
19
+ export declare abstract class VSRepoAdapter<T> {
20
+ /** Runs `fn` inside a native transaction of the underlying ORM/database. */
21
+ abstract runInTransaction<R>(fn: (tx: any) => Promise<R>, options?: VSRepoTransactionOptions): Promise<R>;
22
+ /** Returns the underlying ORM client instance used outside of transactions. */
23
+ abstract getDbClient(): any;
24
+ /** Executes a raw query/statement against the underlying database, used by `@QueryMethod`. */
25
+ abstract query<T = any>(query: string, options?: AdapterQueryOptions): Promise<T>;
26
+ /** Fetches a single record matching `where`. */
27
+ abstract findOne(where: VSRepoWhere<T>, options?: AdapterMethodOptions<T>): Promise<T | null>;
28
+ /** Fetches a single record matching `where`, throwing if none is found. */
29
+ abstract findOneOrThrow(where: VSRepoWhere<T>, options?: AdapterMethodOptions<T>): Promise<T>;
30
+ /** Fetches all records matching `where`. */
31
+ abstract findMany(where: VSRepoWhere<T>, options?: AdapterMethodOptions<T> & {
32
+ distinct?: (keyof T)[];
33
+ }): Promise<T[]>;
34
+ /** Creates or updates (upsert) a single record. */
35
+ abstract save(obj: DeepPartial<T>, options?: AdapterMethodOptions<T>): Promise<T>;
36
+ /** Creates or updates (upsert) multiple records in a single operation. */
37
+ abstract saveMany(objs: DeepPartial<T>[], options?: AdapterMethodOptions<T>): Promise<T[]>;
38
+ /** Creates a single record. */
39
+ abstract create(objs: DeepPartial<T>, options?: AdapterMethodOptions<T>): Promise<T>;
40
+ /** Creates multiple records in a single operation. */
41
+ abstract createMany(objs: DeepPartial<T>[], options?: AdapterMethodOptions<T> & {
42
+ ignoreConflicts?: boolean;
43
+ }): Promise<CountResult>;
44
+ /** Creates multiple records in a single operation, returning the created records. */
45
+ abstract createManyReturning(objs: DeepPartial<T>[], options?: AdapterMethodOptions<T> & {
46
+ ignoreConflicts?: boolean;
47
+ }): Promise<T[]>;
48
+ /** Deletes a single record matching `where`. */
49
+ abstract delete(where: VSRepoWhere<T>, options?: AdapterMethodOptions<T>): Promise<T>;
50
+ /** Deletes every record matching `where`, returning the count of affected rows. */
51
+ abstract deleteMany(where: VSRepoWhere<T>, options?: AdapterMethodOptions<T>): Promise<CountResult>;
52
+ /** Deletes every record matching `where`, returning the deleted records. */
53
+ abstract deleteManyReturning(where: VSRepoWhere<T>, options?: AdapterMethodOptions<T>): Promise<T[]>;
54
+ /** Updates a single record matching `where`. */
55
+ abstract update(where: VSRepoWhere<T>, obj: DeepPartial<T>, options?: AdapterMethodOptions<T>): Promise<T>;
56
+ /** Updates every record matching `where`, returning the count of affected rows. */
57
+ abstract updateMany(where: VSRepoWhere<T>, obj: DeepPartial<T>, options?: AdapterMethodOptions<T>): Promise<CountResult>;
58
+ /** Updates every record matching `where`, returning the updated records. */
59
+ abstract updateManyReturning(where: VSRepoWhere<T>, obj: DeepPartial<T>, options?: AdapterMethodOptions<T>): Promise<T[]>;
60
+ /** Returns the number of records matching `where`. */
61
+ abstract count(where: VSRepoWhere<T>, options?: AdapterMethodOptions<T>): Promise<number>;
62
+ /** Checks whether at least one record matching `where` exists. */
63
+ abstract exists(where: VSRepoWhere<T>, options?: AdapterMethodOptions<T>): Promise<boolean>;
64
+ /**
65
+ * Fetches a single record matching `where` and returns it deep-merged, in
66
+ * memory, with the provided object — does **not** persist anything.
67
+ */
68
+ abstract merge<K>(where: VSRepoWhere<T>, obj: DeepPartial<T>, options?: AdapterMethodOptions<T>): Promise<K & T>;
69
+ /** Creates a record if none matches `where`, otherwise updates it. */
70
+ abstract upsert(where: VSRepoWhere<T>, create: DeepPartial<T>, update: DeepPartial<T>, options?: AdapterMethodOptions<T>): Promise<T>;
71
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VSRepoAdapter = void 0;
4
+ /**
5
+ * Contract implemented by ORM-specific adapters (e.g. Prisma, TypeORM) that
6
+ * `VSRepository` delegates every operation to.
7
+ *
8
+ * Implementing this class is what makes `VSRepository` usable with a given
9
+ * ORM/database: `VSRepository` never talks to the ORM directly, it only
10
+ * calls these methods with already-resolved `VSRepoWhere`/`AdapterMethodOptions`.
11
+ *
12
+ * @template T Entity type this adapter operates on.
13
+ *
14
+ * @publicApi
15
+ */
16
+ class VSRepoAdapter {
17
+ }
18
+ exports.VSRepoAdapter = VSRepoAdapter;