zenstack 0.6.0-pre.11 → 0.6.0-pre.13

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 (203) hide show
  1. package/cli/cli-error.d.ts +5 -0
  2. package/cli/cli-error.js +12 -0
  3. package/cli/cli-error.js.map +1 -0
  4. package/cli/cli-util.d.ts +18 -0
  5. package/cli/cli-util.js +168 -0
  6. package/cli/cli-util.js.map +1 -0
  7. package/cli/index.d.ts +10 -0
  8. package/cli/index.js +78 -6531
  9. package/cli/index.js.map +1 -0
  10. package/cli/plugin-runner.d.ts +14 -0
  11. package/cli/plugin-runner.js +133 -0
  12. package/cli/plugin-runner.js.map +1 -0
  13. package/global.d.js +1 -0
  14. package/global.d.js.map +1 -0
  15. package/language-server/constants.d.ts +12 -0
  16. package/language-server/constants.js +24 -0
  17. package/language-server/constants.js.map +1 -0
  18. package/language-server/main.d.ts +1 -0
  19. package/language-server/main.js +20 -6436
  20. package/language-server/main.js.map +1 -0
  21. package/language-server/types.d.ts +10 -0
  22. package/language-server/types.js +1 -0
  23. package/language-server/types.js.map +1 -0
  24. package/language-server/utils.d.ts +10 -0
  25. package/language-server/utils.js +28 -0
  26. package/language-server/utils.js.map +1 -0
  27. package/language-server/validator/attribute-validator.d.ts +9 -0
  28. package/language-server/validator/attribute-validator.js +15 -0
  29. package/language-server/validator/attribute-validator.js.map +1 -0
  30. package/language-server/validator/datamodel-validator.d.ts +16 -0
  31. package/language-server/validator/datamodel-validator.js +365 -0
  32. package/language-server/validator/datamodel-validator.js.map +1 -0
  33. package/language-server/validator/datasource-validator.d.ts +13 -0
  34. package/language-server/validator/datasource-validator.js +85 -0
  35. package/language-server/validator/datasource-validator.js.map +1 -0
  36. package/language-server/validator/enum-validator.d.ts +9 -0
  37. package/language-server/validator/enum-validator.js +18 -0
  38. package/language-server/validator/enum-validator.js.map +1 -0
  39. package/language-server/validator/expression-validator.d.ts +11 -0
  40. package/language-server/validator/expression-validator.js +40 -0
  41. package/language-server/validator/expression-validator.js.map +1 -0
  42. package/language-server/validator/schema-validator.d.ts +10 -0
  43. package/language-server/validator/schema-validator.js +35 -0
  44. package/language-server/validator/schema-validator.js.map +1 -0
  45. package/language-server/validator/utils.d.ts +24 -0
  46. package/language-server/validator/utils.js +116 -0
  47. package/language-server/validator/utils.js.map +1 -0
  48. package/language-server/validator/zmodel-validator.d.ts +21 -0
  49. package/language-server/validator/zmodel-validator.js +72 -0
  50. package/language-server/validator/zmodel-validator.js.map +1 -0
  51. package/language-server/zmodel-linker.d.ts +29 -0
  52. package/language-server/zmodel-linker.js +364 -0
  53. package/language-server/zmodel-linker.js.map +1 -0
  54. package/language-server/zmodel-module.d.ts +41 -0
  55. package/language-server/zmodel-module.js +84 -0
  56. package/language-server/zmodel-module.js.map +1 -0
  57. package/language-server/zmodel-scope.d.ts +10 -0
  58. package/language-server/zmodel-scope.js +34 -0
  59. package/language-server/zmodel-scope.js.map +1 -0
  60. package/language-server/zmodel-workspace-manager.d.ts +8 -0
  61. package/language-server/zmodel-workspace-manager.js +25 -0
  62. package/language-server/zmodel-workspace-manager.js.map +1 -0
  63. package/package.json +20 -15
  64. package/plugins/access-policy/expression-writer.d.ts +38 -0
  65. package/plugins/access-policy/expression-writer.js +323 -0
  66. package/plugins/access-policy/expression-writer.js.map +1 -0
  67. package/plugins/access-policy/index.d.ts +4 -0
  68. package/plugins/access-policy/index.js +15 -4289
  69. package/plugins/access-policy/index.js.map +1 -0
  70. package/plugins/access-policy/policy-guard-generator.d.ts +15 -0
  71. package/plugins/access-policy/policy-guard-generator.js +345 -0
  72. package/plugins/access-policy/policy-guard-generator.js.map +1 -0
  73. package/plugins/access-policy/typescript-expression-transformer.d.ts +26 -0
  74. package/plugins/access-policy/typescript-expression-transformer.js +110 -0
  75. package/plugins/access-policy/typescript-expression-transformer.js.map +1 -0
  76. package/plugins/access-policy/utils.d.ts +5 -0
  77. package/plugins/access-policy/utils.js +16 -0
  78. package/plugins/access-policy/utils.js.map +1 -0
  79. package/plugins/access-policy/zod-schema-generator.d.ts +12 -0
  80. package/plugins/access-policy/zod-schema-generator.js +174 -0
  81. package/plugins/access-policy/zod-schema-generator.js.map +1 -0
  82. package/plugins/model-meta/index.d.ts +4 -0
  83. package/plugins/model-meta/index.js +130 -0
  84. package/plugins/model-meta/index.js.map +1 -0
  85. package/plugins/plugin-utils.d.ts +16 -0
  86. package/plugins/plugin-utils.js +58 -0
  87. package/plugins/plugin-utils.js.map +1 -0
  88. package/plugins/prisma/indent-string.d.ts +4 -0
  89. package/plugins/prisma/indent-string.js +16 -0
  90. package/plugins/prisma/indent-string.js.map +1 -0
  91. package/plugins/prisma/index.d.ts +4 -0
  92. package/plugins/prisma/index.js +15 -3740
  93. package/plugins/prisma/index.js.map +1 -0
  94. package/plugins/prisma/prisma-builder.d.ts +123 -0
  95. package/plugins/prisma/prisma-builder.js +256 -0
  96. package/plugins/prisma/prisma-builder.js.map +1 -0
  97. package/plugins/prisma/schema-generator.d.ts +22 -0
  98. package/plugins/prisma/schema-generator.js +201 -0
  99. package/plugins/prisma/schema-generator.js.map +1 -0
  100. package/plugins/react-hooks/index.d.ts +4 -0
  101. package/plugins/react-hooks/index.js +14 -4332
  102. package/plugins/react-hooks/index.js.map +1 -0
  103. package/plugins/react-hooks/react-hooks-generator.d.ts +3 -0
  104. package/plugins/react-hooks/react-hooks-generator.js +333 -0
  105. package/plugins/react-hooks/react-hooks-generator.js.map +1 -0
  106. package/plugins/trpc/config.d.ts +9 -0
  107. package/plugins/trpc/config.js +12 -0
  108. package/plugins/trpc/config.js.map +1 -0
  109. package/plugins/trpc/generator.d.ts +4 -0
  110. package/plugins/trpc/generator.js +132 -0
  111. package/plugins/trpc/generator.js.map +1 -0
  112. package/plugins/trpc/helpers.d.ts +9 -0
  113. package/plugins/trpc/helpers.js +144 -0
  114. package/plugins/trpc/helpers.js.map +1 -0
  115. package/plugins/trpc/index.d.ts +5 -0
  116. package/plugins/trpc/index.js +14 -5401
  117. package/plugins/trpc/index.js.map +1 -0
  118. package/plugins/trpc/project.d.ts +2 -0
  119. package/plugins/trpc/project.js +21 -0
  120. package/plugins/trpc/project.js.map +1 -0
  121. package/plugins/trpc/types.d.ts +0 -0
  122. package/plugins/trpc/types.js +1 -0
  123. package/plugins/trpc/types.js.map +1 -0
  124. package/plugins/trpc/utils/removeDir.d.ts +1 -0
  125. package/plugins/trpc/utils/removeDir.js +22 -0
  126. package/plugins/trpc/utils/removeDir.js.map +1 -0
  127. package/plugins/trpc/utils/uncapitalizeFirstLetter.d.ts +1 -0
  128. package/plugins/trpc/utils/uncapitalizeFirstLetter.js +11 -0
  129. package/plugins/trpc/utils/uncapitalizeFirstLetter.js.map +1 -0
  130. package/plugins/zod/generator.d.ts +4 -0
  131. package/plugins/zod/generator.js +78 -0
  132. package/plugins/zod/generator.js.map +1 -0
  133. package/plugins/zod/helpers/aggregate-helpers.d.ts +5 -0
  134. package/plugins/zod/helpers/aggregate-helpers.js +77 -0
  135. package/plugins/zod/helpers/aggregate-helpers.js.map +1 -0
  136. package/plugins/zod/helpers/comments-helpers.d.ts +6 -0
  137. package/plugins/zod/helpers/comments-helpers.js +91 -0
  138. package/plugins/zod/helpers/comments-helpers.js.map +1 -0
  139. package/plugins/zod/helpers/helpers.d.ts +8 -0
  140. package/plugins/zod/helpers/helpers.js +39 -0
  141. package/plugins/zod/helpers/helpers.js.map +1 -0
  142. package/plugins/zod/helpers/include-helpers.d.ts +2 -0
  143. package/plugins/zod/helpers/include-helpers.js +94 -0
  144. package/plugins/zod/helpers/include-helpers.js.map +1 -0
  145. package/plugins/zod/helpers/index.d.ts +4 -0
  146. package/plugins/zod/helpers/index.js +50 -0
  147. package/plugins/zod/helpers/index.js.map +1 -0
  148. package/plugins/zod/helpers/model-helpers.d.ts +6 -0
  149. package/plugins/zod/helpers/model-helpers.js +50 -0
  150. package/plugins/zod/helpers/model-helpers.js.map +1 -0
  151. package/plugins/zod/helpers/modelArgs-helpers.d.ts +2 -0
  152. package/plugins/zod/helpers/modelArgs-helpers.js +62 -0
  153. package/plugins/zod/helpers/modelArgs-helpers.js.map +1 -0
  154. package/plugins/zod/helpers/mongodb-helpers.d.ts +3 -0
  155. package/plugins/zod/helpers/mongodb-helpers.js +63 -0
  156. package/plugins/zod/helpers/mongodb-helpers.js.map +1 -0
  157. package/plugins/zod/helpers/select-helpers.d.ts +2 -0
  158. package/plugins/zod/helpers/select-helpers.js +150 -0
  159. package/plugins/zod/helpers/select-helpers.js.map +1 -0
  160. package/plugins/zod/index.d.ts +5 -0
  161. package/plugins/zod/index.js +14 -4824
  162. package/plugins/zod/index.js.map +1 -0
  163. package/plugins/zod/transformer.d.ts +70 -0
  164. package/plugins/zod/transformer.js +464 -0
  165. package/plugins/zod/transformer.js.map +1 -0
  166. package/plugins/zod/types.d.ts +20 -0
  167. package/plugins/zod/types.js +1 -0
  168. package/plugins/zod/types.js.map +1 -0
  169. package/plugins/zod/utils/formatFile.d.ts +1 -0
  170. package/plugins/zod/utils/formatFile.js +35 -0
  171. package/plugins/zod/utils/formatFile.js.map +1 -0
  172. package/plugins/zod/utils/removeDir.d.ts +1 -0
  173. package/plugins/zod/utils/removeDir.js +22 -0
  174. package/plugins/zod/utils/removeDir.js.map +1 -0
  175. package/plugins/zod/utils/writeFileSafely.d.ts +1 -0
  176. package/plugins/zod/utils/writeFileSafely.js +18 -0
  177. package/plugins/zod/utils/writeFileSafely.js.map +1 -0
  178. package/res/prism-zmodel.js +2 -4
  179. package/res/stdlib.zmodel +12 -1
  180. package/telemetry.d.ts +21 -0
  181. package/telemetry.js +102 -0
  182. package/telemetry.js.map +1 -0
  183. package/types.d.ts +11 -0
  184. package/types.js +1 -0
  185. package/types.js.map +1 -0
  186. package/utils/ast-utils.d.ts +15 -0
  187. package/utils/ast-utils.js +79 -0
  188. package/utils/ast-utils.js.map +1 -0
  189. package/utils/exec-utils.d.ts +6 -0
  190. package/utils/exec-utils.js +17 -0
  191. package/utils/exec-utils.js.map +1 -0
  192. package/utils/indent-string.d.ts +4 -0
  193. package/utils/indent-string.js +16 -0
  194. package/utils/indent-string.js.map +1 -0
  195. package/utils/pkg-utils.d.ts +3 -0
  196. package/utils/pkg-utils.js +43 -0
  197. package/utils/pkg-utils.js.map +1 -0
  198. package/asset/logo-256-bg.png +0 -0
  199. package/asset/logo-dark-256.png +0 -0
  200. package/asset/logo-light-256.png +0 -0
  201. package/extension.js +0 -39
  202. package/res/package.template.json +0 -9
  203. package/res/tsconfig.template.json +0 -17
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["name","run","model","options","dmmf","generate"],"sources":["../../../src/plugins/trpc/index.ts"],"sourcesContent":["import { DMMF } from '@prisma/generator-helper';\nimport { PluginOptions } from '@zenstackhq/sdk';\nimport { Model } from '@zenstackhq/sdk/ast';\nimport { generate } from './generator';\n\nexport const name = 'tRPC';\n\nexport default async function run(model: Model, options: PluginOptions, dmmf: DMMF.Document) {\n return generate(model, options, dmmf);\n}\n"],"mappings":";;;;;;;AAGA;AAEO,MAAMA,IAAI,GAAG,MAAM;AAAC;AAEZ,eAAeC,GAAG,CAACC,KAAY,EAAEC,OAAsB,EAAEC,IAAmB,EAAE;EACzF,OAAO,IAAAC,mBAAQ,EAACH,KAAK,EAAEC,OAAO,EAAEC,IAAI,CAAC;AACzC"}
@@ -0,0 +1,2 @@
1
+ import { Project } from 'ts-morph';
2
+ export declare const project: Project;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.project = void 0;
7
+ var _tsMorph = require("ts-morph");
8
+ const compilerOptions = {
9
+ target: _tsMorph.ScriptTarget.ES2019,
10
+ module: _tsMorph.ModuleKind.CommonJS,
11
+ emitDecoratorMetadata: true,
12
+ experimentalDecorators: true,
13
+ esModuleInterop: true
14
+ };
15
+ const project = new _tsMorph.Project({
16
+ compilerOptions: {
17
+ ...compilerOptions
18
+ }
19
+ });
20
+ exports.project = project;
21
+ //# sourceMappingURL=project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.js","names":["compilerOptions","target","ScriptTarget","ES2019","module","ModuleKind","CommonJS","emitDecoratorMetadata","experimentalDecorators","esModuleInterop","project","Project"],"sources":["../../../src/plugins/trpc/project.ts"],"sourcesContent":["import { Project, ScriptTarget, ModuleKind, CompilerOptions } from 'ts-morph';\n\nconst compilerOptions: CompilerOptions = {\n target: ScriptTarget.ES2019,\n module: ModuleKind.CommonJS,\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n esModuleInterop: true,\n};\n\nexport const project = new Project({\n compilerOptions: {\n ...compilerOptions,\n },\n});\n"],"mappings":";;;;;;AAAA;AAEA,MAAMA,eAAgC,GAAG;EACrCC,MAAM,EAAEC,qBAAY,CAACC,MAAM;EAC3BC,MAAM,EAAEC,mBAAU,CAACC,QAAQ;EAC3BC,qBAAqB,EAAE,IAAI;EAC3BC,sBAAsB,EAAE,IAAI;EAC5BC,eAAe,EAAE;AACrB,CAAC;AAEM,MAAMC,OAAO,GAAG,IAAIC,gBAAO,CAAC;EAC/BX,eAAe,EAAE;IACb,GAAGA;EACP;AACJ,CAAC,CAAC;AAAC"}
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../src/plugins/trpc/types.ts"],"sourcesContent":[""],"mappings":""}
@@ -0,0 +1 @@
1
+ export default function removeDir(dirPath: string, onlyContent: boolean): Promise<void>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = removeDir;
7
+ var _path = _interopRequireDefault(require("path"));
8
+ var _fs = require("fs");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ async function removeDir(dirPath, onlyContent) {
11
+ const dirEntries = await _fs.promises.readdir(dirPath, {
12
+ withFileTypes: true
13
+ });
14
+ await Promise.all(dirEntries.map(async dirEntry => {
15
+ const fullPath = _path.default.join(dirPath, dirEntry.name);
16
+ return dirEntry.isDirectory() ? await removeDir(fullPath, false) : await _fs.promises.unlink(fullPath);
17
+ }));
18
+ if (!onlyContent) {
19
+ await _fs.promises.rmdir(dirPath);
20
+ }
21
+ }
22
+ //# sourceMappingURL=removeDir.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"removeDir.js","names":["removeDir","dirPath","onlyContent","dirEntries","fs","readdir","withFileTypes","Promise","all","map","dirEntry","fullPath","path","join","name","isDirectory","unlink","rmdir"],"sources":["../../../../src/plugins/trpc/utils/removeDir.ts"],"sourcesContent":["import path from 'path';\nimport { promises as fs } from 'fs';\n\nexport default async function removeDir(dirPath: string, onlyContent: boolean) {\n const dirEntries = await fs.readdir(dirPath, { withFileTypes: true });\n await Promise.all(\n dirEntries.map(async (dirEntry) => {\n const fullPath = path.join(dirPath, dirEntry.name);\n return dirEntry.isDirectory() ? await removeDir(fullPath, false) : await fs.unlink(fullPath);\n })\n );\n if (!onlyContent) {\n await fs.rmdir(dirPath);\n }\n}\n"],"mappings":";;;;;;AAAA;AACA;AAAoC;AAErB,eAAeA,SAAS,CAACC,OAAe,EAAEC,WAAoB,EAAE;EAC3E,MAAMC,UAAU,GAAG,MAAMC,YAAE,CAACC,OAAO,CAACJ,OAAO,EAAE;IAAEK,aAAa,EAAE;EAAK,CAAC,CAAC;EACrE,MAAMC,OAAO,CAACC,GAAG,CACbL,UAAU,CAACM,GAAG,CAAC,MAAOC,QAAQ,IAAK;IAC/B,MAAMC,QAAQ,GAAGC,aAAI,CAACC,IAAI,CAACZ,OAAO,EAAES,QAAQ,CAACI,IAAI,CAAC;IAClD,OAAOJ,QAAQ,CAACK,WAAW,EAAE,GAAG,MAAMf,SAAS,CAACW,QAAQ,EAAE,KAAK,CAAC,GAAG,MAAMP,YAAE,CAACY,MAAM,CAACL,QAAQ,CAAC;EAChG,CAAC,CAAC,CACL;EACD,IAAI,CAACT,WAAW,EAAE;IACd,MAAME,YAAE,CAACa,KAAK,CAAChB,OAAO,CAAC;EAC3B;AACJ"}
@@ -0,0 +1 @@
1
+ export declare const uncapitalizeFirstLetter: (str: string) => string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.uncapitalizeFirstLetter = void 0;
7
+ const uncapitalizeFirstLetter = str => {
8
+ return str.charAt(0).toLowerCase() + str.slice(1);
9
+ };
10
+ exports.uncapitalizeFirstLetter = uncapitalizeFirstLetter;
11
+ //# sourceMappingURL=uncapitalizeFirstLetter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uncapitalizeFirstLetter.js","names":["uncapitalizeFirstLetter","str","charAt","toLowerCase","slice"],"sources":["../../../../src/plugins/trpc/utils/uncapitalizeFirstLetter.ts"],"sourcesContent":["export const uncapitalizeFirstLetter = (str: string) => {\n return str.charAt(0).toLowerCase() + str.slice(1);\n};\n"],"mappings":";;;;;;AAAO,MAAMA,uBAAuB,GAAIC,GAAW,IAAK;EACpD,OAAOA,GAAG,CAACC,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,EAAE,GAAGF,GAAG,CAACG,KAAK,CAAC,CAAC,CAAC;AACrD,CAAC;AAAC"}
@@ -0,0 +1,4 @@
1
+ import { DMMF } from '@prisma/generator-helper';
2
+ import { PluginOptions } from '@zenstackhq/sdk';
3
+ import { Model } from '@zenstackhq/sdk/ast';
4
+ export declare function generate(model: Model, options: PluginOptions, dmmf: DMMF.Document): Promise<void>;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.generate = generate;
7
+ var _sdk = require("@zenstackhq/sdk");
8
+ var _ast = require("@zenstackhq/sdk/ast");
9
+ var _fs = require("fs");
10
+ var _helpers = require("./helpers");
11
+ var _aggregateHelpers = require("./helpers/aggregate-helpers");
12
+ var _transformer = _interopRequireDefault(require("./transformer"));
13
+ var _removeDir = _interopRequireDefault(require("./utils/removeDir"));
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ async function generate(model, options, dmmf) {
16
+ var _dataSource$fields$fi;
17
+ await handleGeneratorOutputValue(options.output ?? './generated');
18
+ const prismaClientDmmf = dmmf;
19
+ const modelOperations = prismaClientDmmf.mappings.modelOperations;
20
+ const inputObjectTypes = prismaClientDmmf.schema.inputObjectTypes.prisma;
21
+ const outputObjectTypes = prismaClientDmmf.schema.outputObjectTypes.prisma;
22
+ const enumTypes = prismaClientDmmf.schema.enumTypes;
23
+ const models = prismaClientDmmf.datamodel.models;
24
+ const hiddenModels = [];
25
+ const hiddenFields = [];
26
+ (0, _helpers.resolveModelsComments)(models, modelOperations, enumTypes, hiddenModels, hiddenFields);
27
+ await generateEnumSchemas(prismaClientDmmf.schema.enumTypes.prisma, prismaClientDmmf.schema.enumTypes.model ?? []);
28
+ const dataSource = model.declarations.find(d => (0, _ast.isDataSource)(d));
29
+ const dataSourceProvider = (0, _sdk.getLiteral)(dataSource === null || dataSource === void 0 ? void 0 : (_dataSource$fields$fi = dataSource.fields.find(f => f.name === 'provider')) === null || _dataSource$fields$fi === void 0 ? void 0 : _dataSource$fields$fi.value);
30
+ _transformer.default.provider = dataSourceProvider;
31
+ const generatorConfigOptions = {};
32
+ Object.entries(options).forEach(([k, v]) => generatorConfigOptions[k] = v);
33
+ const addMissingInputObjectTypeOptions = (0, _helpers.resolveAddMissingInputObjectTypeOptions)(generatorConfigOptions);
34
+ (0, _helpers.addMissingInputObjectTypes)(inputObjectTypes, outputObjectTypes, models, modelOperations, dataSourceProvider, addMissingInputObjectTypeOptions);
35
+ const aggregateOperationSupport = (0, _aggregateHelpers.resolveAggregateOperationSupport)(inputObjectTypes);
36
+ (0, _helpers.hideInputObjectTypesAndRelatedFields)(inputObjectTypes, hiddenModels, hiddenFields);
37
+ await generateObjectSchemas(inputObjectTypes);
38
+ await generateModelSchemas(models, modelOperations, aggregateOperationSupport);
39
+ }
40
+ async function handleGeneratorOutputValue(output) {
41
+ // create the output directory and delete contents that might exist from a previous run
42
+ await _fs.promises.mkdir(output, {
43
+ recursive: true
44
+ });
45
+ const isRemoveContentsOnly = true;
46
+ await (0, _removeDir.default)(output, isRemoveContentsOnly);
47
+ _transformer.default.setOutputPath(output);
48
+ }
49
+ async function generateEnumSchemas(prismaSchemaEnum, modelSchemaEnum) {
50
+ const enumTypes = [...prismaSchemaEnum, ...modelSchemaEnum];
51
+ const enumNames = enumTypes.map(enumItem => enumItem.name);
52
+ _transformer.default.enumNames = enumNames ?? [];
53
+ const transformer = new _transformer.default({
54
+ enumTypes
55
+ });
56
+ await transformer.generateEnumSchemas();
57
+ }
58
+ async function generateObjectSchemas(inputObjectTypes) {
59
+ for (let i = 0; i < inputObjectTypes.length; i += 1) {
60
+ var _inputObjectTypes$i, _inputObjectTypes$i2;
61
+ const fields = (_inputObjectTypes$i = inputObjectTypes[i]) === null || _inputObjectTypes$i === void 0 ? void 0 : _inputObjectTypes$i.fields;
62
+ const name = (_inputObjectTypes$i2 = inputObjectTypes[i]) === null || _inputObjectTypes$i2 === void 0 ? void 0 : _inputObjectTypes$i2.name;
63
+ const transformer = new _transformer.default({
64
+ name,
65
+ fields
66
+ });
67
+ await transformer.generateObjectSchema();
68
+ }
69
+ }
70
+ async function generateModelSchemas(models, modelOperations, aggregateOperationSupport) {
71
+ const transformer = new _transformer.default({
72
+ models,
73
+ modelOperations,
74
+ aggregateOperationSupport
75
+ });
76
+ await transformer.generateModelSchemas();
77
+ }
78
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","names":["generate","model","options","dmmf","handleGeneratorOutputValue","output","prismaClientDmmf","modelOperations","mappings","inputObjectTypes","schema","prisma","outputObjectTypes","enumTypes","models","datamodel","hiddenModels","hiddenFields","resolveModelsComments","generateEnumSchemas","dataSource","declarations","find","d","isDataSource","dataSourceProvider","getLiteral","fields","f","name","value","Transformer","provider","generatorConfigOptions","Object","entries","forEach","k","v","addMissingInputObjectTypeOptions","resolveAddMissingInputObjectTypeOptions","addMissingInputObjectTypes","aggregateOperationSupport","resolveAggregateOperationSupport","hideInputObjectTypesAndRelatedFields","generateObjectSchemas","generateModelSchemas","fs","mkdir","recursive","isRemoveContentsOnly","removeDir","setOutputPath","prismaSchemaEnum","modelSchemaEnum","enumNames","map","enumItem","transformer","i","length","generateObjectSchema"],"sources":["../../../src/plugins/zod/generator.ts"],"sourcesContent":["import { ConnectorType, DMMF } from '@prisma/generator-helper';\nimport { Dictionary } from '@prisma/internals';\nimport { PluginOptions, getLiteral } from '@zenstackhq/sdk';\nimport { DataSource, Model, isDataSource } from '@zenstackhq/sdk/ast';\nimport { promises as fs } from 'fs';\nimport {\n addMissingInputObjectTypes,\n hideInputObjectTypesAndRelatedFields,\n resolveAddMissingInputObjectTypeOptions,\n resolveModelsComments,\n} from './helpers';\nimport { resolveAggregateOperationSupport } from './helpers/aggregate-helpers';\nimport Transformer from './transformer';\nimport { AggregateOperationSupport } from './types';\nimport removeDir from './utils/removeDir';\n\nexport async function generate(model: Model, options: PluginOptions, dmmf: DMMF.Document) {\n await handleGeneratorOutputValue((options.output as string) ?? './generated');\n\n const prismaClientDmmf = dmmf;\n\n const modelOperations = prismaClientDmmf.mappings.modelOperations;\n const inputObjectTypes = prismaClientDmmf.schema.inputObjectTypes.prisma;\n const outputObjectTypes = prismaClientDmmf.schema.outputObjectTypes.prisma;\n const enumTypes = prismaClientDmmf.schema.enumTypes;\n const models: DMMF.Model[] = prismaClientDmmf.datamodel.models;\n const hiddenModels: string[] = [];\n const hiddenFields: string[] = [];\n resolveModelsComments(models, modelOperations, enumTypes, hiddenModels, hiddenFields);\n\n await generateEnumSchemas(prismaClientDmmf.schema.enumTypes.prisma, prismaClientDmmf.schema.enumTypes.model ?? []);\n\n const dataSource = model.declarations.find((d): d is DataSource => isDataSource(d));\n\n const dataSourceProvider = getLiteral<string>(\n dataSource?.fields.find((f) => f.name === 'provider')?.value\n ) as ConnectorType;\n\n Transformer.provider = dataSourceProvider;\n\n const generatorConfigOptions: Dictionary<string> = {};\n Object.entries(options).forEach(([k, v]) => (generatorConfigOptions[k] = v as string));\n\n const addMissingInputObjectTypeOptions = resolveAddMissingInputObjectTypeOptions(generatorConfigOptions);\n addMissingInputObjectTypes(\n inputObjectTypes,\n outputObjectTypes,\n models,\n modelOperations,\n dataSourceProvider,\n addMissingInputObjectTypeOptions\n );\n\n const aggregateOperationSupport = resolveAggregateOperationSupport(inputObjectTypes);\n\n hideInputObjectTypesAndRelatedFields(inputObjectTypes, hiddenModels, hiddenFields);\n\n await generateObjectSchemas(inputObjectTypes);\n await generateModelSchemas(models, modelOperations, aggregateOperationSupport);\n}\n\nasync function handleGeneratorOutputValue(output: string) {\n // create the output directory and delete contents that might exist from a previous run\n await fs.mkdir(output, { recursive: true });\n const isRemoveContentsOnly = true;\n await removeDir(output, isRemoveContentsOnly);\n\n Transformer.setOutputPath(output);\n}\n\nasync function generateEnumSchemas(prismaSchemaEnum: DMMF.SchemaEnum[], modelSchemaEnum: DMMF.SchemaEnum[]) {\n const enumTypes = [...prismaSchemaEnum, ...modelSchemaEnum];\n const enumNames = enumTypes.map((enumItem) => enumItem.name);\n Transformer.enumNames = enumNames ?? [];\n const transformer = new Transformer({\n enumTypes,\n });\n await transformer.generateEnumSchemas();\n}\n\nasync function generateObjectSchemas(inputObjectTypes: DMMF.InputType[]) {\n for (let i = 0; i < inputObjectTypes.length; i += 1) {\n const fields = inputObjectTypes[i]?.fields;\n const name = inputObjectTypes[i]?.name;\n const transformer = new Transformer({ name, fields });\n await transformer.generateObjectSchema();\n }\n}\n\nasync function generateModelSchemas(\n models: DMMF.Model[],\n modelOperations: DMMF.ModelMapping[],\n aggregateOperationSupport: AggregateOperationSupport\n) {\n const transformer = new Transformer({\n models,\n modelOperations,\n aggregateOperationSupport,\n });\n await transformer.generateModelSchemas();\n}\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA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AC,CAAC;EACF,MAAM6C,WAAW,CAACvC,mBAAmB,EAAE;AAC3C;AAEA,eAAe0B,qBAAqB,CAACpC,gBAAkC,EAAE;EACrE,KAAK,IAAIkD,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGlD,gBAAgB,CAACmD,MAAM,EAAED,CAAC,IAAI,CAAC,EAAE;IAAA;IACjD,MAAMhC,MAAM,0BAAGlB,gBAAgB,CAACkD,CAAC,CAAC,wDAAnB,oBAAqBhC,MAAM;IAC1C,MAAME,IAAI,2BAAGpB,gBAAgB,CAACkD,CAAC,CAAC,yDAAnB,qBAAqB9B,IAAI;IACtC,MAAM6B,WAAW,GAAG,IAAI3B,oBAAW,CAAC;MAAEF,IAAI;MAAEF;IAAO,CAAC,CAAC;IACrD,MAAM+B,WAAW,CAACG,oBAAoB,EAAE;EAC5C;AACJ;AAEA,eAAef,oBAAoB,CAC/BhC,MAAoB,EACpBP,eAAoC,EACpCmC,yBAAoD,EACtD;EACE,MAAMgB,WAAW,GAAG,IAAI3B,oBAAW,CAAC;IAChCjB,MAAM;IACNP,eAAe;IACfmC;EACJ,CAAC,CAAC;EACF,MAAMgB,WAAW,CAACZ,oBAAoB,EAAE;AAC5C"}
@@ -0,0 +1,5 @@
1
+ import { DMMF } from '@prisma/generator-helper';
2
+ import { AggregateOperationSupport } from '../types';
3
+ export declare const isAggregateInputType: (name: string) => boolean;
4
+ export declare function addMissingInputObjectTypesForAggregate(inputObjectTypes: DMMF.InputType[], outputObjectTypes: DMMF.OutputType[]): void;
5
+ export declare function resolveAggregateOperationSupport(inputObjectTypes: DMMF.InputType[]): AggregateOperationSupport;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.addMissingInputObjectTypesForAggregate = addMissingInputObjectTypesForAggregate;
7
+ exports.isAggregateInputType = void 0;
8
+ exports.resolveAggregateOperationSupport = resolveAggregateOperationSupport;
9
+ const isAggregateOutputType = name => /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(name);
10
+ const isAggregateInputType = name => name.endsWith('CountAggregateInput') || name.endsWith('SumAggregateInput') || name.endsWith('AvgAggregateInput') || name.endsWith('MinAggregateInput') || name.endsWith('MaxAggregateInput');
11
+ exports.isAggregateInputType = isAggregateInputType;
12
+ function addMissingInputObjectTypesForAggregate(inputObjectTypes, outputObjectTypes) {
13
+ const aggregateOutputTypes = outputObjectTypes.filter(({
14
+ name
15
+ }) => isAggregateOutputType(name));
16
+ for (const aggregateOutputType of aggregateOutputTypes) {
17
+ const name = aggregateOutputType.name.replace(/(?:OutputType|Output)$/, '');
18
+ inputObjectTypes.push({
19
+ constraints: {
20
+ maxNumFields: null,
21
+ minNumFields: null
22
+ },
23
+ name: `${name}Input`,
24
+ fields: aggregateOutputType.fields.map(field => ({
25
+ name: field.name,
26
+ isNullable: false,
27
+ isRequired: false,
28
+ inputTypes: [{
29
+ isList: false,
30
+ type: 'True',
31
+ location: 'scalar'
32
+ }]
33
+ }))
34
+ });
35
+ }
36
+ }
37
+ function resolveAggregateOperationSupport(inputObjectTypes) {
38
+ const aggregateOperationSupport = {};
39
+ for (const inputType of inputObjectTypes) {
40
+ if (isAggregateInputType(inputType.name)) {
41
+ const name = inputType.name.replace('AggregateInput', '');
42
+ if (name.endsWith('Count')) {
43
+ const model = name.replace('Count', '');
44
+ aggregateOperationSupport[model] = {
45
+ ...aggregateOperationSupport[model],
46
+ count: true
47
+ };
48
+ } else if (name.endsWith('Min')) {
49
+ const model = name.replace('Min', '');
50
+ aggregateOperationSupport[model] = {
51
+ ...aggregateOperationSupport[model],
52
+ min: true
53
+ };
54
+ } else if (name.endsWith('Max')) {
55
+ const model = name.replace('Max', '');
56
+ aggregateOperationSupport[model] = {
57
+ ...aggregateOperationSupport[model],
58
+ max: true
59
+ };
60
+ } else if (name.endsWith('Sum')) {
61
+ const model = name.replace('Sum', '');
62
+ aggregateOperationSupport[model] = {
63
+ ...aggregateOperationSupport[model],
64
+ sum: true
65
+ };
66
+ } else if (name.endsWith('Avg')) {
67
+ const model = name.replace('Avg', '');
68
+ aggregateOperationSupport[model] = {
69
+ ...aggregateOperationSupport[model],
70
+ avg: true
71
+ };
72
+ }
73
+ }
74
+ }
75
+ return aggregateOperationSupport;
76
+ }
77
+ //# sourceMappingURL=aggregate-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aggregate-helpers.js","names":["isAggregateOutputType","name","test","isAggregateInputType","endsWith","addMissingInputObjectTypesForAggregate","inputObjectTypes","outputObjectTypes","aggregateOutputTypes","filter","aggregateOutputType","replace","push","constraints","maxNumFields","minNumFields","fields","map","field","isNullable","isRequired","inputTypes","isList","type","location","resolveAggregateOperationSupport","aggregateOperationSupport","inputType","model","count","min","max","sum","avg"],"sources":["../../../../src/plugins/zod/helpers/aggregate-helpers.ts"],"sourcesContent":["import { DMMF } from '@prisma/generator-helper';\nimport { AggregateOperationSupport } from '../types';\n\nconst isAggregateOutputType = (name: string) => /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(name);\n\nexport const isAggregateInputType = (name: string) =>\n name.endsWith('CountAggregateInput') ||\n name.endsWith('SumAggregateInput') ||\n name.endsWith('AvgAggregateInput') ||\n name.endsWith('MinAggregateInput') ||\n name.endsWith('MaxAggregateInput');\n\nexport function addMissingInputObjectTypesForAggregate(\n inputObjectTypes: DMMF.InputType[],\n outputObjectTypes: DMMF.OutputType[]\n) {\n const aggregateOutputTypes = outputObjectTypes.filter(({ name }) => isAggregateOutputType(name));\n for (const aggregateOutputType of aggregateOutputTypes) {\n const name = aggregateOutputType.name.replace(/(?:OutputType|Output)$/, '');\n inputObjectTypes.push({\n constraints: { maxNumFields: null, minNumFields: null },\n name: `${name}Input`,\n fields: aggregateOutputType.fields.map((field) => ({\n name: field.name,\n isNullable: false,\n isRequired: false,\n inputTypes: [\n {\n isList: false,\n type: 'True',\n location: 'scalar',\n },\n ],\n })),\n });\n }\n}\n\nexport function resolveAggregateOperationSupport(inputObjectTypes: DMMF.InputType[]) {\n const aggregateOperationSupport: AggregateOperationSupport = {};\n for (const inputType of inputObjectTypes) {\n if (isAggregateInputType(inputType.name)) {\n const name = inputType.name.replace('AggregateInput', '');\n if (name.endsWith('Count')) {\n const model = name.replace('Count', '');\n aggregateOperationSupport[model] = {\n ...aggregateOperationSupport[model],\n count: true,\n };\n } else if (name.endsWith('Min')) {\n const model = name.replace('Min', '');\n aggregateOperationSupport[model] = {\n ...aggregateOperationSupport[model],\n min: true,\n };\n } else if (name.endsWith('Max')) {\n const model = name.replace('Max', '');\n aggregateOperationSupport[model] = {\n ...aggregateOperationSupport[model],\n max: true,\n };\n } else if (name.endsWith('Sum')) {\n const model = name.replace('Sum', '');\n aggregateOperationSupport[model] = {\n ...aggregateOperationSupport[model],\n sum: true,\n };\n } else if (name.endsWith('Avg')) {\n const model = name.replace('Avg', '');\n aggregateOperationSupport[model] = {\n ...aggregateOperationSupport[model],\n avg: true,\n };\n }\n }\n }\n return aggregateOperationSupport;\n}\n"],"mappings":";;;;;;;;AAGA,MAAMA,qBAAqB,GAAIC,IAAY,IAAK,+CAA+C,CAACC,IAAI,CAACD,IAAI,CAAC;AAEnG,MAAME,oBAAoB,GAAIF,IAAY,IAC7CA,IAAI,CAACG,QAAQ,CAAC,qBAAqB,CAAC,IACpCH,IAAI,CAACG,QAAQ,CAAC,mBAAmB,CAAC,IAClCH,IAAI,CAACG,QAAQ,CAAC,mBAAmB,CAAC,IAClCH,IAAI,CAACG,QAAQ,CAAC,mBAAmB,CAAC,IAClCH,IAAI,CAACG,QAAQ,CAAC,mBAAmB,CAAC;AAAC;AAEhC,SAASC,sCAAsC,CAClDC,gBAAkC,EAClCC,iBAAoC,EACtC;EACE,MAAMC,oBAAoB,GAAGD,iBAAiB,CAACE,MAAM,CAAC,CAAC;IAAER;EAAK,CAAC,KAAKD,qBAAqB,CAACC,IAAI,CAAC,CAAC;EAChG,KAAK,MAAMS,mBAAmB,IAAIF,oBAAoB,EAAE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;QACrCe,yBAAyB,CAACE,KAAK,CAAC,GAAG;UAC/B,GAAGF,yBAAyB,CAACE,KAAK,CAAC;UACnCE,GAAG,EAAE;QACT,CAAC;MACL,CAAC,MAAM,IAAI7B,IAAI,CAACG,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC7B,MAAMwB,KAAK,GAAG3B,IAAI,CAACU,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;QACrCe,yBAAyB,CAACE,KAAK,CAAC,GAAG;UAC/B,GAAGF,yBAAyB,CAACE,KAAK,CAAC;UACnCG,GAAG,EAAE;QACT,CAAC;MACL,CAAC,MAAM,IAAI9B,IAAI,CAACG,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC7B,MAAMwB,KAAK,GAAG3B,IAAI,CAACU,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;QACrCe,yBAAyB,CAACE,KAAK,CAAC,GAAG;UAC/B,GAAGF,yBAAyB,CAACE,KAAK,CAAC;UACnCI,GAAG,EAAE;QACT,CAAC;MACL,CAAC,MAAM,IAAI/B,IAAI,CAACG,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC7B,MAAMwB,KAAK,GAAG3B,IAAI,CAACU,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;QACrCe,yBAAyB,CAACE,KAAK,CAAC,GAAG;UAC/B,GAAGF,yBAAyB,CAACE,KAAK,CAAC;UACnCK,GAAG,EAAE;QACT,CAAC;MACL;IACJ;EACJ;EACA,OAAOP,yBAAyB;AACpC"}
@@ -0,0 +1,6 @@
1
+ import { DMMF } from '@prisma/generator-helper';
2
+ export declare function resolveModelsComments(models: DMMF.Model[], modelOperations: DMMF.ModelMapping[], enumTypes: {
3
+ model?: DMMF.SchemaEnum[];
4
+ prisma: DMMF.SchemaEnum[];
5
+ }, hiddenModels: string[], hiddenFields: string[]): void;
6
+ export declare function hideInputObjectTypesAndRelatedFields(inputObjectTypes: DMMF.InputType[], hiddenModels: string[], hiddenFields: string[]): void;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hideInputObjectTypesAndRelatedFields = hideInputObjectTypesAndRelatedFields;
7
+ exports.resolveModelsComments = resolveModelsComments;
8
+ const modelAttributeRegex = /(@@Gen\.)+([A-z])+(\()+(.+)+(\))+/;
9
+ const attributeNameRegex = /(?:\.)+([A-Za-z])+(?:\()+/;
10
+ const attributeArgsRegex = /(?:\()+([A-Za-z])+:+(.+)+(?:\))+/;
11
+ function resolveModelsComments(models, modelOperations, enumTypes, hiddenModels, hiddenFields) {
12
+ models = collectHiddenModels(models, hiddenModels);
13
+ collectHiddenFields(models, hiddenModels, hiddenFields);
14
+ hideModelOperations(models, modelOperations);
15
+ hideEnums(enumTypes, hiddenModels);
16
+ }
17
+ function collectHiddenModels(models, hiddenModels) {
18
+ return models.map(model => {
19
+ if (model.documentation) {
20
+ var _model$documentation, _model$documentation$, _attribute$match, _attribute$match$, _attribute$match2, _attribute$match2$;
21
+ const attribute = (_model$documentation = model.documentation) === null || _model$documentation === void 0 ? void 0 : (_model$documentation$ = _model$documentation.match(modelAttributeRegex)) === null || _model$documentation$ === void 0 ? void 0 : _model$documentation$[0];
22
+ const attributeName = attribute === null || attribute === void 0 ? void 0 : (_attribute$match = attribute.match(attributeNameRegex)) === null || _attribute$match === void 0 ? void 0 : (_attribute$match$ = _attribute$match[0]) === null || _attribute$match$ === void 0 ? void 0 : _attribute$match$.slice(1, -1);
23
+ if (attributeName !== 'model') model;
24
+ const rawAttributeArgs = attribute === null || attribute === void 0 ? void 0 : (_attribute$match2 = attribute.match(attributeArgsRegex)) === null || _attribute$match2 === void 0 ? void 0 : (_attribute$match2$ = _attribute$match2[0]) === null || _attribute$match2$ === void 0 ? void 0 : _attribute$match2$.slice(1, -1);
25
+ const parsedAttributeArgs = {};
26
+ if (rawAttributeArgs) {
27
+ const rawAttributeArgsParts = rawAttributeArgs.split(':').map(it => it.trim()).map(part => part.startsWith('[') ? part : part.split(',')).flat().map(it => it.trim());
28
+ for (let i = 0; i < rawAttributeArgsParts.length; i += 2) {
29
+ const key = rawAttributeArgsParts[i];
30
+ const value = rawAttributeArgsParts[i + 1];
31
+ parsedAttributeArgs[key] = JSON.parse(value);
32
+ }
33
+ }
34
+ if (parsedAttributeArgs.hide) {
35
+ hiddenModels.push(model.name);
36
+ return null;
37
+ }
38
+ }
39
+ return model;
40
+ }).filter(Boolean);
41
+ }
42
+ function collectHiddenFields(models, hiddenModels, hiddenFields) {
43
+ models.forEach(model => {
44
+ model.fields.forEach(field => {
45
+ if (hiddenModels.includes(field.type)) {
46
+ hiddenFields.push(field.name);
47
+ if (field.relationFromFields) {
48
+ field.relationFromFields.forEach(item => hiddenFields.push(item));
49
+ }
50
+ }
51
+ });
52
+ });
53
+ }
54
+ function hideEnums(enumTypes, hiddenModels) {
55
+ enumTypes.prisma = enumTypes.prisma.filter(item => !hiddenModels.find(model => item.name.startsWith(model)));
56
+ }
57
+ function hideModelOperations(models, modelOperations) {
58
+ let i = modelOperations.length;
59
+ while (i >= 0) {
60
+ --i;
61
+ const modelOperation = modelOperations[i];
62
+ if (modelOperation && !models.find(model => {
63
+ return model.name === modelOperation.model;
64
+ })) {
65
+ modelOperations.splice(i, 1);
66
+ }
67
+ }
68
+ }
69
+ function hideInputObjectTypesAndRelatedFields(inputObjectTypes, hiddenModels, hiddenFields) {
70
+ let j = inputObjectTypes.length;
71
+ while (j >= 0) {
72
+ var _inputType$meta;
73
+ --j;
74
+ const inputType = inputObjectTypes[j];
75
+ if (inputType && (hiddenModels.includes(inputType === null || inputType === void 0 ? void 0 : (_inputType$meta = inputType.meta) === null || _inputType$meta === void 0 ? void 0 : _inputType$meta.source) || hiddenModels.find(model => inputType.name.startsWith(model)))) {
76
+ inputObjectTypes.splice(j, 1);
77
+ } else {
78
+ var _inputType$fields;
79
+ let k = (inputType === null || inputType === void 0 ? void 0 : (_inputType$fields = inputType.fields) === null || _inputType$fields === void 0 ? void 0 : _inputType$fields.length) ?? 0;
80
+ while (k >= 0) {
81
+ var _inputType$fields2;
82
+ --k;
83
+ const field = inputType === null || inputType === void 0 ? void 0 : (_inputType$fields2 = inputType.fields) === null || _inputType$fields2 === void 0 ? void 0 : _inputType$fields2[k];
84
+ if (field && hiddenFields.includes(field.name)) {
85
+ inputObjectTypes[j].fields.splice(k, 1);
86
+ }
87
+ }
88
+ }
89
+ }
90
+ }
91
+ //# sourceMappingURL=comments-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comments-helpers.js","names":["modelAttributeRegex","attributeNameRegex","attributeArgsRegex","resolveModelsComments","models","modelOperations","enumTypes","hiddenModels","hiddenFields","collectHiddenModels","collectHiddenFields","hideModelOperations","hideEnums","map","model","documentation","attribute","match","attributeName","slice","rawAttributeArgs","parsedAttributeArgs","rawAttributeArgsParts","split","it","trim","part","startsWith","flat","i","length","key","value","JSON","parse","hide","push","name","filter","Boolean","forEach","fields","field","includes","type","relationFromFields","item","prisma","find","modelOperation","splice","hideInputObjectTypesAndRelatedFields","inputObjectTypes","j","inputType","meta","source","k"],"sources":["../../../../src/plugins/zod/helpers/comments-helpers.ts"],"sourcesContent":["import { DMMF } from '@prisma/generator-helper';\n\nconst modelAttributeRegex = /(@@Gen\\.)+([A-z])+(\\()+(.+)+(\\))+/;\nconst attributeNameRegex = /(?:\\.)+([A-Za-z])+(?:\\()+/;\nconst attributeArgsRegex = /(?:\\()+([A-Za-z])+:+(.+)+(?:\\))+/;\n\nexport function resolveModelsComments(\n models: DMMF.Model[],\n modelOperations: DMMF.ModelMapping[],\n enumTypes: { model?: DMMF.SchemaEnum[]; prisma: DMMF.SchemaEnum[] },\n hiddenModels: string[],\n hiddenFields: string[]\n) {\n models = collectHiddenModels(models, hiddenModels);\n collectHiddenFields(models, hiddenModels, hiddenFields);\n hideModelOperations(models, modelOperations);\n hideEnums(enumTypes, hiddenModels);\n}\n\nfunction collectHiddenModels(models: DMMF.Model[], hiddenModels: string[]) {\n return models\n .map((model) => {\n if (model.documentation) {\n const attribute = model.documentation?.match(modelAttributeRegex)?.[0];\n const attributeName = attribute?.match(attributeNameRegex)?.[0]?.slice(1, -1);\n if (attributeName !== 'model') model;\n const rawAttributeArgs = attribute?.match(attributeArgsRegex)?.[0]?.slice(1, -1);\n\n const parsedAttributeArgs: Record<string, unknown> = {};\n if (rawAttributeArgs) {\n const rawAttributeArgsParts = rawAttributeArgs\n .split(':')\n .map((it) => it.trim())\n .map((part) => (part.startsWith('[') ? part : part.split(',')))\n .flat()\n .map((it) => it.trim());\n\n for (let i = 0; i < rawAttributeArgsParts.length; i += 2) {\n const key = rawAttributeArgsParts[i];\n const value = rawAttributeArgsParts[i + 1];\n parsedAttributeArgs[key] = JSON.parse(value);\n }\n }\n if (parsedAttributeArgs.hide) {\n hiddenModels.push(model.name);\n return null as unknown as DMMF.Model;\n }\n }\n return model;\n })\n .filter(Boolean);\n}\n\nfunction collectHiddenFields(models: DMMF.Model[], hiddenModels: string[], hiddenFields: string[]) {\n models.forEach((model) => {\n model.fields.forEach((field) => {\n if (hiddenModels.includes(field.type)) {\n hiddenFields.push(field.name);\n if (field.relationFromFields) {\n field.relationFromFields.forEach((item) => hiddenFields.push(item));\n }\n }\n });\n });\n}\nfunction hideEnums(enumTypes: { model?: DMMF.SchemaEnum[]; prisma: DMMF.SchemaEnum[] }, hiddenModels: string[]) {\n enumTypes.prisma = enumTypes.prisma.filter((item) => !hiddenModels.find((model) => item.name.startsWith(model)));\n}\n\nfunction hideModelOperations(models: DMMF.Model[], modelOperations: DMMF.ModelMapping[]) {\n let i = modelOperations.length;\n while (i >= 0) {\n --i;\n const modelOperation = modelOperations[i];\n if (\n modelOperation &&\n !models.find((model) => {\n return model.name === modelOperation.model;\n })\n ) {\n modelOperations.splice(i, 1);\n }\n }\n}\n\nexport function hideInputObjectTypesAndRelatedFields(\n inputObjectTypes: DMMF.InputType[],\n hiddenModels: string[],\n hiddenFields: string[]\n) {\n let j = inputObjectTypes.length;\n while (j >= 0) {\n --j;\n const inputType = inputObjectTypes[j];\n if (\n inputType &&\n (hiddenModels.includes(inputType?.meta?.source as string) ||\n hiddenModels.find((model) => inputType.name.startsWith(model)))\n ) {\n inputObjectTypes.splice(j, 1);\n } else {\n let k = inputType?.fields?.length ?? 0;\n while (k >= 0) {\n --k;\n const field = inputType?.fields?.[k];\n if (field && hiddenFields.includes(field.name)) {\n inputObjectTypes[j].fields.splice(k, 1);\n }\n }\n }\n }\n}\n"],"mappings":";;;;;;;AAEA,MAAMA,mBAAmB,GAAG,mCAAmC;AAC/D,MAAMC,kBAAkB,GAAG,2BAA2B;AACtD,MAAMC,kBAAkB,GAAG,kCAAkC;AAEtD,SAASC,qBAAqB,CACjCC,MAAoB,EACpBC,eAAoC,EACpCC,SAAmE,EACnEC,YAAsB,EACtBC,YAAsB,EACxB;EACEJ,MAAM,GAAGK,mBAAmB,CAACL,MAAM,EAAEG,YAAY,CAAC;EAClDG,mBAAmB,CAACN,MAAM,EAAEG,YAAY,EAAEC,YAAY,CAAC;EACvDG,mBAAmB,CAACP,MAAM,EAAEC,eAAe,CAAC;EAC5CO,SAAS,CAACN,SAAS,EAAEC,YAAY,CAAC;AACtC;AAEA,SAASE,mBAAmB,CAACL,MAAoB,EAAEG,YAAsB,EAAE;EACvE,OAAOH,MAAM,CACRS,GAAG,CAAEC,KAAK,IAAK;IACZ,IAAIA,KAAK,CAACC,aAAa,EAAE;MAAA;MACrB,MAAMC,SAAS,2BAAGF,KAAK,CAACC,aAAa,kFAAnB,qBAAqBE,KAAK,CAACjB,mBAAmB,CAAC,0DAA/C,sBAAkD,CAAC,CAAC;MACtE,MAAMkB,aAAa,GAAGF,SAAS,aAATA,SAAS,2CAATA,SAAS,CAAEC,KAAK,CAAChB,kBAAkB,CAAC,0EAApC,iBAAuC,CAAC,CAAC,sDAAzC,kBAA2CkB,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;MAC7E,IAAID,aAAa,KAAK,OAAO,EAAEJ,KAAK;M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C,IAAI,CAAC,EAAE;IAAA;IACX,EAAEA,CAAC;IACH,MAAMC,SAAS,GAAGF,gBAAgB,CAACC,CAAC,CAAC;IACrC,IACIC,SAAS,KACR/C,YAAY,CAACoC,QAAQ,CAACW,SAAS,aAATA,SAAS,0CAATA,SAAS,CAAEC,IAAI,oDAAf,gBAAiBC,MAAM,CAAW,IACrDjD,YAAY,CAACyC,IAAI,CAAElC,KAAK,IAAKwC,SAAS,CAACjB,IAAI,CAACV,UAAU,CAACb,KAAK,CAAC,CAAC,CAAC,EACrE;MACEsC,gBAAgB,CAACF,MAAM,CAACG,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC,MAAM;MAAA;MACH,IAAII,CAAC,GAAG,CAAAH,SAAS,aAATA,SAAS,4CAATA,SAAS,CAAEb,MAAM,sDAAjB,kBAAmBX,MAAM,KAAI,CAAC;MACtC,OAAO2B,CAAC,IAAI,CAAC,EAAE;QAAA;QACX,EAAEA,CAAC;QACH,MAAMf,KAAK,GAAGY,SAAS,aAATA,SAAS,6CAATA,SAAS,CAAEb,MAAM,uDAAjB,mBAAoBgB,CAAC,CAAC;QACpC,IAAIf,KAAK,IAAIlC,YAAY,CAACmC,QAAQ,CAACD,KAAK,CAACL,IAAI,CAAC,EAAE;UAC5Ce,gBAAgB,CAACC,CAAC,CAAC,CAACZ,MAAM,CAACS,MAAM,CAACO,CAAC,EAAE,CAAC,CAAC;QAC3C;MACJ;IACJ;EACJ;AACJ"}
@@ -0,0 +1,8 @@
1
+ import { DMMF, ConnectorType, Dictionary } from '@prisma/generator-helper';
2
+ interface AddMissingInputObjectTypeOptions {
3
+ isGenerateSelect: boolean;
4
+ isGenerateInclude: boolean;
5
+ }
6
+ export declare function addMissingInputObjectTypes(inputObjectTypes: DMMF.InputType[], outputObjectTypes: DMMF.OutputType[], models: DMMF.Model[], modelOperations: DMMF.ModelMapping[], dataSourceProvider: ConnectorType, options: AddMissingInputObjectTypeOptions): void;
7
+ export declare function resolveAddMissingInputObjectTypeOptions(generatorConfigOptions: Dictionary<string>): AddMissingInputObjectTypeOptions;
8
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.addMissingInputObjectTypes = addMissingInputObjectTypes;
7
+ exports.resolveAddMissingInputObjectTypeOptions = resolveAddMissingInputObjectTypeOptions;
8
+ var _transformer = _interopRequireDefault(require("../transformer"));
9
+ var _mongodbHelpers = require("./mongodb-helpers");
10
+ var _aggregateHelpers = require("./aggregate-helpers");
11
+ var _selectHelpers = require("./select-helpers");
12
+ var _includeHelpers = require("./include-helpers");
13
+ var _modelArgsHelpers = require("./modelArgs-helpers");
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ function addMissingInputObjectTypes(inputObjectTypes, outputObjectTypes, models, modelOperations, dataSourceProvider, options) {
16
+ // TODO: remove once Prisma fix this issue: https://github.com/prisma/prisma/issues/14900
17
+ if (dataSourceProvider === 'mongodb') {
18
+ (0, _mongodbHelpers.addMissingInputObjectTypesForMongoDbRawOpsAndQueries)(modelOperations, outputObjectTypes, inputObjectTypes);
19
+ }
20
+ (0, _aggregateHelpers.addMissingInputObjectTypesForAggregate)(inputObjectTypes, outputObjectTypes);
21
+ if (options.isGenerateSelect) {
22
+ (0, _selectHelpers.addMissingInputObjectTypesForSelect)(inputObjectTypes, outputObjectTypes, models);
23
+ _transformer.default.setIsGenerateSelect(true);
24
+ }
25
+ if (options.isGenerateSelect || options.isGenerateInclude) {
26
+ (0, _modelArgsHelpers.addMissingInputObjectTypesForModelArgs)(inputObjectTypes, models, options.isGenerateSelect, options.isGenerateInclude);
27
+ }
28
+ if (options.isGenerateInclude) {
29
+ (0, _includeHelpers.addMissingInputObjectTypesForInclude)(inputObjectTypes, models, options.isGenerateSelect);
30
+ _transformer.default.setIsGenerateInclude(true);
31
+ }
32
+ }
33
+ function resolveAddMissingInputObjectTypeOptions(generatorConfigOptions) {
34
+ return {
35
+ isGenerateSelect: generatorConfigOptions.isGenerateSelect !== 'false',
36
+ isGenerateInclude: generatorConfigOptions.isGenerateInclude !== 'false'
37
+ };
38
+ }
39
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","names":["addMissingInputObjectTypes","inputObjectTypes","outputObjectTypes","models","modelOperations","dataSourceProvider","options","addMissingInputObjectTypesForMongoDbRawOpsAndQueries","addMissingInputObjectTypesForAggregate","isGenerateSelect","addMissingInputObjectTypesForSelect","Transformer","setIsGenerateSelect","isGenerateInclude","addMissingInputObjectTypesForModelArgs","addMissingInputObjectTypesForInclude","setIsGenerateInclude","resolveAddMissingInputObjectTypeOptions","generatorConfigOptions"],"sources":["../../../../src/plugins/zod/helpers/helpers.ts"],"sourcesContent":["import { DMMF, ConnectorType, Dictionary } from '@prisma/generator-helper';\nimport Transformer from '../transformer';\nimport { addMissingInputObjectTypesForMongoDbRawOpsAndQueries } from './mongodb-helpers';\nimport { addMissingInputObjectTypesForAggregate } from './aggregate-helpers';\nimport { addMissingInputObjectTypesForSelect } from './select-helpers';\nimport { addMissingInputObjectTypesForInclude } from './include-helpers';\nimport { addMissingInputObjectTypesForModelArgs } from './modelArgs-helpers';\n\ninterface AddMissingInputObjectTypeOptions {\n isGenerateSelect: boolean;\n isGenerateInclude: boolean;\n}\n\nexport function addMissingInputObjectTypes(\n inputObjectTypes: DMMF.InputType[],\n outputObjectTypes: DMMF.OutputType[],\n models: DMMF.Model[],\n modelOperations: DMMF.ModelMapping[],\n dataSourceProvider: ConnectorType,\n options: AddMissingInputObjectTypeOptions\n) {\n // TODO: remove once Prisma fix this issue: https://github.com/prisma/prisma/issues/14900\n if (dataSourceProvider === 'mongodb') {\n addMissingInputObjectTypesForMongoDbRawOpsAndQueries(modelOperations, outputObjectTypes, inputObjectTypes);\n }\n addMissingInputObjectTypesForAggregate(inputObjectTypes, outputObjectTypes);\n if (options.isGenerateSelect) {\n addMissingInputObjectTypesForSelect(inputObjectTypes, outputObjectTypes, models);\n Transformer.setIsGenerateSelect(true);\n }\n if (options.isGenerateSelect || options.isGenerateInclude) {\n addMissingInputObjectTypesForModelArgs(\n inputObjectTypes,\n models,\n options.isGenerateSelect,\n options.isGenerateInclude\n );\n }\n if (options.isGenerateInclude) {\n addMissingInputObjectTypesForInclude(inputObjectTypes, models, options.isGenerateSelect);\n Transformer.setIsGenerateInclude(true);\n }\n}\n\nexport function resolveAddMissingInputObjectTypeOptions(\n generatorConfigOptions: Dictionary<string>\n): AddMissingInputObjectTypeOptions {\n return {\n isGenerateSelect: generatorConfigOptions.isGenerateSelect !== 'false',\n isGenerateInclude: generatorConfigOptions.isGenerateInclude !== 'false',\n };\n}\n"],"mappings":";;;;;;;AACA;AACA;AACA;AACA;AACA;AACA;AAA6E;AAOtE,SAASA,0BAA0B,CACtCC,gBAAkC,EAClCC,iBAAoC,EACpCC,MAAoB,EACpBC,eAAoC,EACpCC,kBAAiC,EACjCC,OAAyC,EAC3C;EACE;EACA,IAAID,kBAAkB,KAAK,SAAS,EAAE;IAClC,IAAAE,oEAAoD,EAACH,eAAe,EAAEF,iBAAiB,EAAED,gBAAgB,CAAC;EAC9G;EACA,IAAAO,wDAAsC,EAACP,gBAAgB,EAAEC,iBAAiB,CAAC;EAC3E,IAAII,OAAO,CAACG,gBAAgB,EAAE;IAC1B,IAAAC,kDAAmC,EAACT,gBAAgB,EAAEC,iBAAiB,EAAEC,MAAM,CAAC;IAChFQ,oBAAW,CAACC,mBAAmB,CAAC,IAAI,CAAC;EACzC;EACA,IAAIN,OAAO,CAACG,gBAAgB,IAAIH,OAAO,CAACO,iBAAiB,EAAE;IACvD,IAAAC,wDAAsC,EAClCb,gBAAgB,EAChBE,MAAM,EACNG,OAAO,CAACG,gBAAgB,EACxBH,OAAO,CAACO,iBAAiB,CAC5B;EACL;EACA,IAAIP,OAAO,CAACO,iBAAiB,EAAE;IAC3B,IAAAE,oDAAoC,EAACd,gBAAgB,EAAEE,MAAM,EAAEG,OAAO,CAACG,gBAAgB,CAAC;IACxFE,oBAAW,CAACK,oBAAoB,CAAC,IAAI,CAAC;EAC1C;AACJ;AAEO,SAASC,uCAAuC,CACnDC,sBAA0C,EACV;EAChC,OAAO;IACHT,gBAAgB,EAAES,sBAAsB,CAACT,gBAAgB,KAAK,OAAO;IACrEI,iBAAiB,EAAEK,sBAAsB,CAACL,iBAAiB,KAAK;EACpE,CAAC;AACL"}
@@ -0,0 +1,2 @@
1
+ import { DMMF } from '@prisma/generator-helper';
2
+ export declare function addMissingInputObjectTypesForInclude(inputObjectTypes: DMMF.InputType[], models: DMMF.Model[], isGenerateSelect: boolean): void;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.addMissingInputObjectTypesForInclude = addMissingInputObjectTypesForInclude;
7
+ var _modelHelpers = require("./model-helpers");
8
+ function addMissingInputObjectTypesForInclude(inputObjectTypes, models, isGenerateSelect) {
9
+ // generate input object types necessary to support ModelInclude with relation support
10
+ const generatedIncludeInputObjectTypes = generateModelIncludeInputObjectTypes(models, isGenerateSelect);
11
+ for (const includeInputObjectType of generatedIncludeInputObjectTypes) {
12
+ inputObjectTypes.push(includeInputObjectType);
13
+ }
14
+ }
15
+ function generateModelIncludeInputObjectTypes(models, isGenerateSelect) {
16
+ const modelIncludeInputObjectTypes = [];
17
+ for (const model of models) {
18
+ const {
19
+ name: modelName,
20
+ fields: modelFields
21
+ } = model;
22
+ const fields = [];
23
+ for (const modelField of modelFields) {
24
+ const {
25
+ name: modelFieldName,
26
+ isList,
27
+ type
28
+ } = modelField;
29
+ const isRelationField = (0, _modelHelpers.checkIsModelRelationField)(modelField);
30
+ if (isRelationField) {
31
+ const field = {
32
+ name: modelFieldName,
33
+ isRequired: false,
34
+ isNullable: false,
35
+ inputTypes: [{
36
+ isList: false,
37
+ type: 'Boolean',
38
+ location: 'scalar'
39
+ }, {
40
+ isList: false,
41
+ type: isList ? `${type}FindManyArgs` : `${type}Args`,
42
+ location: 'inputObjectTypes',
43
+ namespace: 'prisma'
44
+ }]
45
+ };
46
+ fields.push(field);
47
+ }
48
+ }
49
+
50
+ /**
51
+ * include is not generated for models that do not have a relation with any other models
52
+ * -> continue onto the next model
53
+ */
54
+ const hasRelationToAnotherModel = (0, _modelHelpers.checkModelHasModelRelation)(model);
55
+ if (!hasRelationToAnotherModel) {
56
+ continue;
57
+ }
58
+ const hasManyRelationToAnotherModel = (0, _modelHelpers.checkModelHasManyModelRelation)(model);
59
+ const shouldAddCountField = hasManyRelationToAnotherModel;
60
+ if (shouldAddCountField) {
61
+ const inputTypes = [{
62
+ isList: false,
63
+ type: 'Boolean',
64
+ location: 'scalar'
65
+ }];
66
+ if (isGenerateSelect) {
67
+ inputTypes.push({
68
+ isList: false,
69
+ type: `${modelName}CountOutputTypeArgs`,
70
+ location: 'inputObjectTypes',
71
+ namespace: 'prisma'
72
+ });
73
+ }
74
+ const _countField = {
75
+ name: '_count',
76
+ isRequired: false,
77
+ isNullable: false,
78
+ inputTypes
79
+ };
80
+ fields.push(_countField);
81
+ }
82
+ const modelIncludeInputObjectType = {
83
+ name: `${modelName}Include`,
84
+ constraints: {
85
+ maxNumFields: null,
86
+ minNumFields: null
87
+ },
88
+ fields
89
+ };
90
+ modelIncludeInputObjectTypes.push(modelIncludeInputObjectType);
91
+ }
92
+ return modelIncludeInputObjectTypes;
93
+ }
94
+ //# sourceMappingURL=include-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"include-helpers.js","names":["addMissingInputObjectTypesForInclude","inputObjectTypes","models","isGenerateSelect","generatedIncludeInputObjectTypes","generateModelIncludeInputObjectTypes","includeInputObjectType","push","modelIncludeInputObjectTypes","model","name","modelName","fields","modelFields","modelField","modelFieldName","isList","type","isRelationField","checkIsModelRelationField","field","isRequired","isNullable","inputTypes","location","namespace","hasRelationToAnotherModel","checkModelHasModelRelation","hasManyRelationToAnotherModel","checkModelHasManyModelRelation","shouldAddCountField","_countField","modelIncludeInputObjectType","constraints","maxNumFields","minNumFields"],"sources":["../../../../src/plugins/zod/helpers/include-helpers.ts"],"sourcesContent":["import { DMMF } from '@prisma/generator-helper';\nimport { checkIsModelRelationField, checkModelHasModelRelation, checkModelHasManyModelRelation } from './model-helpers';\n\nexport function addMissingInputObjectTypesForInclude(\n inputObjectTypes: DMMF.InputType[],\n models: DMMF.Model[],\n isGenerateSelect: boolean\n) {\n // generate input object types necessary to support ModelInclude with relation support\n const generatedIncludeInputObjectTypes = generateModelIncludeInputObjectTypes(models, isGenerateSelect);\n\n for (const includeInputObjectType of generatedIncludeInputObjectTypes) {\n inputObjectTypes.push(includeInputObjectType);\n }\n}\nfunction generateModelIncludeInputObjectTypes(models: DMMF.Model[], isGenerateSelect: boolean) {\n const modelIncludeInputObjectTypes: DMMF.InputType[] = [];\n for (const model of models) {\n const { name: modelName, fields: modelFields } = model;\n const fields: DMMF.SchemaArg[] = [];\n\n for (const modelField of modelFields) {\n const { name: modelFieldName, isList, type } = modelField;\n\n const isRelationField = checkIsModelRelationField(modelField);\n\n if (isRelationField) {\n const field: DMMF.SchemaArg = {\n name: modelFieldName,\n isRequired: false,\n isNullable: false,\n inputTypes: [\n { isList: false, type: 'Boolean', location: 'scalar' },\n {\n isList: false,\n type: isList ? `${type}FindManyArgs` : `${type}Args`,\n location: 'inputObjectTypes',\n namespace: 'prisma',\n },\n ],\n };\n fields.push(field);\n }\n }\n\n /**\n * include is not generated for models that do not have a relation with any other models\n * -> continue onto the next model\n */\n const hasRelationToAnotherModel = checkModelHasModelRelation(model);\n if (!hasRelationToAnotherModel) {\n continue;\n }\n\n const hasManyRelationToAnotherModel = checkModelHasManyModelRelation(model);\n\n const shouldAddCountField = hasManyRelationToAnotherModel;\n if (shouldAddCountField) {\n const inputTypes: DMMF.SchemaArgInputType[] = [{ isList: false, type: 'Boolean', location: 'scalar' }];\n if (isGenerateSelect) {\n inputTypes.push({\n isList: false,\n type: `${modelName}CountOutputTypeArgs`,\n location: 'inputObjectTypes',\n namespace: 'prisma',\n });\n }\n const _countField: DMMF.SchemaArg = {\n name: '_count',\n isRequired: false,\n isNullable: false,\n inputTypes,\n };\n fields.push(_countField);\n }\n\n const modelIncludeInputObjectType: DMMF.InputType = {\n name: `${modelName}Include`,\n constraints: {\n maxNumFields: null,\n minNumFields: null,\n },\n fields,\n };\n modelIncludeInputObjectTypes.push(modelIncludeInputObjectType);\n }\n return modelIncludeInputObjectTypes;\n}\n"],"mappings":";;;;;;AACA;AAEO,SAASA,oCAAoC,CAChDC,gBAAkC,EAClCC,MAAoB,EACpBC,gBAAyB,EAC3B;EACE;EACA,MAAMC,gCAAgC,GAAGC,oCAAoC,CAACH,MAAM,EAAEC,gBAAgB,CAAC;EAEvG,KAAK,MAAMG,sBAAsB,IAAIF,gCAAgC,EAAE;IACnEH,gBAAgB,CAACM,IAAI,CAACD,sBAAsB,CAAC;EACjD;AACJ;AACA,SAASD,oCAAoC,CAACH,MAAoB,EAAEC,gBAAyB,EAAE;EAC3F,MAAMK,4BAA8C,GAAG,EAAE;EACzD,KAAK,MAAMC,KAAK,IAAIP,MAAM,EAAE;IACxB,MAAM;MAAEQ,IAAI,EAAEC,SAAS;MAAEC,MAAM,EAAEC;IAAY,CAAC,GAAGJ,KAAK;IACtD,MAAMG,MAAwB,GAAG,EAAE;IAEnC,KAAK,MAAME,UAAU,IAAID,WAAW,EAAE;MAClC,MAAM;QAAEH,IAAI,EAAEK,cAAc;QAAEC,MAAM;QAAEC;MAAK,CAAC,GAAGH,UAAU;MAEzD,MAAMI,eAAe,GAAG,IAAAC,uCAAyB,EAACL,UAAU,CAAC;MAE7D,IAAII,eAAe,EAAE;QACjB,MAAME,KAAqB,GAAG;UAC1BV,IAAI,EAAEK,cAAc;UACpBM,UAAU,EAAE,KAAK;UACjBC,UAAU,EAAE,KAAK;UACjBC,UAAU,EAAE,CACR;YAAEP,MAAM,EAAE,KAAK;YAAEC,IAAI,EAAE,SAAS;YAAEO,Q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AOxB,4BAA4B;AACvC"}
@@ -0,0 +1,4 @@
1
+ export * from './comments-helpers';
2
+ export * from './helpers';
3
+ export * from './model-helpers';
4
+ export * from './mongodb-helpers';