@postxl/generator 0.74.2 → 1.0.1

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 (189) hide show
  1. package/LICENSE +50 -0
  2. package/README.md +79 -1
  3. package/dist/generator-manager.class.d.ts +59 -0
  4. package/dist/generator-manager.class.js +221 -0
  5. package/dist/generator.class.d.ts +90 -0
  6. package/dist/generator.class.js +32 -0
  7. package/dist/generator.context.d.ts +174 -0
  8. package/dist/generator.context.js +125 -0
  9. package/dist/helpers/branded.types.d.ts +149 -0
  10. package/dist/helpers/branded.types.js +111 -0
  11. package/dist/helpers/config-builder.class.d.ts +27 -0
  12. package/dist/helpers/config-builder.class.js +54 -0
  13. package/dist/helpers/import-generator.class.d.ts +70 -0
  14. package/dist/helpers/import-generator.class.js +166 -0
  15. package/dist/helpers/importable.types.d.ts +52 -0
  16. package/dist/helpers/importable.types.js +15 -0
  17. package/dist/helpers/index-generator.class.d.ts +10 -0
  18. package/dist/helpers/index-generator.class.js +46 -0
  19. package/dist/helpers/index.d.ts +8 -0
  20. package/dist/helpers/index.js +24 -0
  21. package/dist/helpers/package-json.generator.d.ts +56 -0
  22. package/dist/helpers/package-json.generator.js +36 -0
  23. package/dist/helpers/tsconfig.generator.d.ts +1 -0
  24. package/dist/helpers/tsconfig.generator.js +14 -0
  25. package/dist/helpers/verify-context.d.ts +4 -0
  26. package/dist/helpers/verify-context.js +23 -0
  27. package/dist/index.d.ts +5 -0
  28. package/dist/index.js +21 -0
  29. package/dist/utils/checksum.d.ts +10 -0
  30. package/dist/utils/checksum.js +132 -0
  31. package/dist/utils/fs-utils.d.ts +34 -0
  32. package/dist/utils/fs-utils.js +126 -0
  33. package/dist/utils/index.d.ts +10 -0
  34. package/dist/utils/index.js +26 -0
  35. package/dist/utils/jsdoc.d.ts +12 -0
  36. package/dist/utils/jsdoc.js +37 -0
  37. package/dist/utils/lint.d.ts +46 -0
  38. package/dist/utils/lint.js +154 -0
  39. package/dist/utils/lockfile.d.ts +7 -0
  40. package/dist/utils/lockfile.js +80 -0
  41. package/dist/utils/logger.class.d.ts +25 -0
  42. package/dist/utils/logger.class.js +55 -0
  43. package/dist/utils/merge-conflict.d.ts +55 -0
  44. package/dist/utils/merge-conflict.js +264 -0
  45. package/dist/utils/path.d.ts +52 -0
  46. package/dist/utils/path.js +183 -0
  47. package/dist/utils/prettier-config.d.ts +2 -0
  48. package/dist/utils/prettier-config.js +13 -0
  49. package/dist/utils/prettier.d.ts +5 -0
  50. package/dist/utils/prettier.js +67 -0
  51. package/dist/utils/prettier.skiptest.d.ts +1 -0
  52. package/dist/utils/prettier.skiptest.js +22 -0
  53. package/dist/utils/promise.d.ts +2 -0
  54. package/dist/utils/promise.js +10 -0
  55. package/dist/utils/string-functions.d.ts +9 -0
  56. package/dist/utils/string-functions.js +23 -0
  57. package/dist/utils/sync-log-result.d.ts +9 -0
  58. package/dist/utils/sync-log-result.js +90 -0
  59. package/dist/utils/sync.d.ts +143 -0
  60. package/dist/utils/sync.js +325 -0
  61. package/dist/utils/template.d.ts +66 -0
  62. package/dist/utils/template.js +159 -0
  63. package/dist/utils/vfs.class.d.ts +115 -0
  64. package/dist/utils/vfs.class.js +239 -0
  65. package/dist/utils/zip.d.ts +13 -0
  66. package/dist/utils/zip.js +40 -0
  67. package/package.json +57 -34
  68. package/dist/generator.d.ts +0 -13
  69. package/dist/generator.js +0 -455
  70. package/dist/generators/enums/react.generator.d.ts +0 -10
  71. package/dist/generators/enums/react.generator.js +0 -110
  72. package/dist/generators/enums/types.generator.d.ts +0 -10
  73. package/dist/generators/enums/types.generator.js +0 -39
  74. package/dist/generators/indices/data/module.generator.d.ts +0 -9
  75. package/dist/generators/indices/data/module.generator.js +0 -60
  76. package/dist/generators/indices/data/service.generator.d.ts +0 -9
  77. package/dist/generators/indices/data/service.generator.js +0 -249
  78. package/dist/generators/indices/data/types.generator.d.ts +0 -9
  79. package/dist/generators/indices/data/types.generator.js +0 -49
  80. package/dist/generators/indices/dispatcher-service.generator.d.ts +0 -9
  81. package/dist/generators/indices/dispatcher-service.generator.js +0 -107
  82. package/dist/generators/indices/export/class.generator.d.ts +0 -9
  83. package/dist/generators/indices/export/class.generator.js +0 -140
  84. package/dist/generators/indices/export/encoder.generator.d.ts +0 -9
  85. package/dist/generators/indices/export/encoder.generator.js +0 -50
  86. package/dist/generators/indices/import/convert-functions.generator.d.ts +0 -9
  87. package/dist/generators/indices/import/convert-functions.generator.js +0 -509
  88. package/dist/generators/indices/import/decoder.generator.d.ts +0 -9
  89. package/dist/generators/indices/import/decoder.generator.js +0 -40
  90. package/dist/generators/indices/import/service.generator.d.ts +0 -9
  91. package/dist/generators/indices/import/service.generator.js +0 -573
  92. package/dist/generators/indices/import/types.generator.d.ts +0 -9
  93. package/dist/generators/indices/import/types.generator.js +0 -242
  94. package/dist/generators/indices/repositories.generator.d.ts +0 -9
  95. package/dist/generators/indices/repositories.generator.js +0 -25
  96. package/dist/generators/indices/routes.generator.d.ts +0 -9
  97. package/dist/generators/indices/routes.generator.js +0 -29
  98. package/dist/generators/indices/seed-migration.generator.d.ts +0 -9
  99. package/dist/generators/indices/seed-migration.generator.js +0 -36
  100. package/dist/generators/indices/seed-template.generator.d.ts +0 -9
  101. package/dist/generators/indices/seed-template.generator.js +0 -80
  102. package/dist/generators/indices/testids.generator.d.ts +0 -7
  103. package/dist/generators/indices/testids.generator.js +0 -71
  104. package/dist/generators/indices/types.generator.d.ts +0 -10
  105. package/dist/generators/indices/types.generator.js +0 -35
  106. package/dist/generators/indices/update/actiontypes.generator.d.ts +0 -9
  107. package/dist/generators/indices/update/actiontypes.generator.js +0 -49
  108. package/dist/generators/indices/update/module.generator.d.ts +0 -9
  109. package/dist/generators/indices/update/module.generator.js +0 -41
  110. package/dist/generators/indices/update/service.generator.d.ts +0 -9
  111. package/dist/generators/indices/update/service.generator.js +0 -34
  112. package/dist/generators/indices/view/module.generator.d.ts +0 -9
  113. package/dist/generators/indices/view/module.generator.js +0 -39
  114. package/dist/generators/indices/view/service.generator.d.ts +0 -9
  115. package/dist/generators/indices/view/service.generator.js +0 -34
  116. package/dist/generators/models/admin.page.generator.d.ts +0 -7
  117. package/dist/generators/models/admin.page.generator.js +0 -74
  118. package/dist/generators/models/export/encoder.generator.d.ts +0 -9
  119. package/dist/generators/models/export/encoder.generator.js +0 -51
  120. package/dist/generators/models/import/decoder.generator.d.ts +0 -9
  121. package/dist/generators/models/import/decoder.generator.js +0 -148
  122. package/dist/generators/models/react/context.generator.d.ts +0 -9
  123. package/dist/generators/models/react/context.generator.js +0 -71
  124. package/dist/generators/models/react/index.d.ts +0 -10
  125. package/dist/generators/models/react/index.js +0 -31
  126. package/dist/generators/models/react/library.generator.d.ts +0 -10
  127. package/dist/generators/models/react/library.generator.js +0 -94
  128. package/dist/generators/models/react/lookup.generator.d.ts +0 -9
  129. package/dist/generators/models/react/lookup.generator.js +0 -175
  130. package/dist/generators/models/react/modals.generator.d.ts +0 -23
  131. package/dist/generators/models/react/modals.generator.js +0 -710
  132. package/dist/generators/models/repository.generator.d.ts +0 -9
  133. package/dist/generators/models/repository.generator.js +0 -955
  134. package/dist/generators/models/route.generator.d.ts +0 -9
  135. package/dist/generators/models/route.generator.js +0 -92
  136. package/dist/generators/models/seed.generator.d.ts +0 -21
  137. package/dist/generators/models/seed.generator.js +0 -285
  138. package/dist/generators/models/stub.generator.d.ts +0 -9
  139. package/dist/generators/models/stub.generator.js +0 -92
  140. package/dist/generators/models/types.generator.d.ts +0 -9
  141. package/dist/generators/models/types.generator.js +0 -125
  142. package/dist/generators/models/update/service.generator.d.ts +0 -10
  143. package/dist/generators/models/update/service.generator.js +0 -302
  144. package/dist/generators/models/view/service.generator.d.ts +0 -10
  145. package/dist/generators/models/view/service.generator.js +0 -239
  146. package/dist/lib/attributes.d.ts +0 -114
  147. package/dist/lib/attributes.js +0 -2
  148. package/dist/lib/exports.d.ts +0 -45
  149. package/dist/lib/exports.js +0 -90
  150. package/dist/lib/imports.d.ts +0 -65
  151. package/dist/lib/imports.js +0 -114
  152. package/dist/lib/meta.d.ts +0 -1191
  153. package/dist/lib/meta.js +0 -434
  154. package/dist/lib/schema/fields.d.ts +0 -46
  155. package/dist/lib/schema/fields.js +0 -62
  156. package/dist/lib/schema/schema.d.ts +0 -466
  157. package/dist/lib/schema/schema.js +0 -18
  158. package/dist/lib/schema/types.d.ts +0 -201
  159. package/dist/lib/schema/types.js +0 -112
  160. package/dist/lib/serializer.d.ts +0 -15
  161. package/dist/lib/serializer.js +0 -24
  162. package/dist/lib/test-id-collector.d.ts +0 -42
  163. package/dist/lib/test-id-collector.js +0 -53
  164. package/dist/lib/types.d.ts +0 -7
  165. package/dist/lib/types.js +0 -13
  166. package/dist/lib/typescript.d.ts +0 -5
  167. package/dist/lib/typescript.js +0 -22
  168. package/dist/lib/utils/ast.d.ts +0 -29
  169. package/dist/lib/utils/ast.js +0 -23
  170. package/dist/lib/utils/error.d.ts +0 -17
  171. package/dist/lib/utils/error.js +0 -52
  172. package/dist/lib/utils/file.d.ts +0 -10
  173. package/dist/lib/utils/file.js +0 -56
  174. package/dist/lib/utils/jsdoc.d.ts +0 -9
  175. package/dist/lib/utils/jsdoc.js +0 -37
  176. package/dist/lib/utils/logger.d.ts +0 -17
  177. package/dist/lib/utils/logger.js +0 -12
  178. package/dist/lib/utils/string.d.ts +0 -40
  179. package/dist/lib/utils/string.js +0 -187
  180. package/dist/lib/utils/types.d.ts +0 -12
  181. package/dist/lib/utils/types.js +0 -2
  182. package/dist/lib/zod.d.ts +0 -8
  183. package/dist/lib/zod.js +0 -60
  184. package/dist/prisma/attributes.d.ts +0 -21
  185. package/dist/prisma/attributes.js +0 -175
  186. package/dist/prisma/client-path.d.ts +0 -7
  187. package/dist/prisma/client-path.js +0 -29
  188. package/dist/prisma/parse.d.ts +0 -12
  189. package/dist/prisma/parse.js +0 -452
@@ -1,187 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.conjugateNames = exports.commentLines = exports.isPlural = exports.pluralize = exports.toPascalCase = exports.toCamelCase = exports.capitalize = exports.uncapitalize = void 0;
4
- /**
5
- * Returns the same string with a lowercase first letter.
6
- */
7
- const uncapitalize = (str) => {
8
- return str.charAt(0).toLowerCase() + str.slice(1);
9
- };
10
- exports.uncapitalize = uncapitalize;
11
- /**
12
- * Returns the same string with an uppercase first letter.
13
- */
14
- const capitalize = (str) => {
15
- return str.charAt(0).toUpperCase() + str.slice(1);
16
- };
17
- exports.capitalize = capitalize;
18
- /**
19
- * Returns the camelCase version of the given string.
20
- */
21
- const toCamelCase = (str) => {
22
- // If the string is already in camelCase format, return it unchanged
23
- if (/^[a-z][a-zA-Z]*$/.test(str)) {
24
- return str;
25
- }
26
- // Split the string into an array of words
27
- const words = str.split(/[\s_-]+/);
28
- // Convert the first word to lowercase and capitalize the rest
29
- const camelCasedWords = words.map((word, index) => (index === 0 ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1));
30
- // Join the words back together into a single string
31
- const camelCasedStr = camelCasedWords.join('');
32
- return camelCasedStr;
33
- };
34
- exports.toCamelCase = toCamelCase;
35
- /**
36
- * Returns the PascalCase version of the given string.
37
- */
38
- const toPascalCase = (str) => {
39
- const s = (0, exports.toCamelCase)(str);
40
- return s.charAt(0).toUpperCase() + s.slice(1);
41
- };
42
- exports.toPascalCase = toPascalCase;
43
- const IRREGULAR_PLURALS = Object.entries({
44
- abyss: 'abysses',
45
- aegis: 'aegises',
46
- alias: 'aliases',
47
- alumnus: 'alumni',
48
- amends: 'amends',
49
- analysis: 'analyses',
50
- apparatus: 'apparatuses',
51
- appendix: 'appendices',
52
- asbestos: 'asbestoses',
53
- atlas: 'atlases',
54
- axis: 'axes',
55
- basis: 'bases',
56
- biceps: 'bicepses',
57
- bus: 'buses',
58
- caress: 'caresses',
59
- child: 'children',
60
- children: 'children',
61
- circus: 'circuses',
62
- citrus: 'citruses',
63
- compass: 'compasses',
64
- crisis: 'crises',
65
- criterion: 'criteria',
66
- crocus: 'crocuses',
67
- data: 'data',
68
- datum: 'data',
69
- diabetes: 'diabetes',
70
- diagnosis: 'diagnoses',
71
- dross: 'drosses',
72
- egress: 'egresses',
73
- elvis: 'elvises',
74
- emboss: 'embosses',
75
- fiss: 'fisses',
76
- focus: 'foci',
77
- glass: 'glasses',
78
- hippocampus: 'hippocampi',
79
- // While `histories` is the plural of `history`, in a model context, `history` makes more sense:
80
- // If you have a model called `UserHistory`, calling the table `UserHistories` would be confusing.
81
- history: 'history',
82
- hypothesis: 'hypotheses',
83
- ignis: 'ignises',
84
- index: 'indices',
85
- iris: 'irises',
86
- jesus: 'jesuses',
87
- kudos: 'kudos',
88
- lens: 'lenses',
89
- man: 'men',
90
- matrix: 'matrices',
91
- medium: 'media',
92
- news: 'news',
93
- oasis: 'oases',
94
- parenthesis: 'parentheses',
95
- pass: 'passes',
96
- phenomenon: 'phenomena',
97
- prognosis: 'prognoses',
98
- radius: 'radii',
99
- ras: 'rasses',
100
- sepsis: 'sepses',
101
- species: 'species',
102
- status: 'statuses',
103
- suffix: 'suffixes',
104
- syllabus: 'syllabi',
105
- synopsis: 'synopses',
106
- thesis: 'theses',
107
- tress: 'tresses',
108
- virus: 'viruses',
109
- vortex: 'vortices',
110
- woman: 'women',
111
- });
112
- /**
113
- * Returns a pluralized version of the given string based on the count.
114
- */
115
- const pluralize = (s, count = 2) => {
116
- // NOTE: If there's one of something we simply use the singular form.
117
- if (count === 1) {
118
- return s;
119
- }
120
- // NOTE: For plural forms, we first check whether a word is irregular.
121
- const lower = s.toLowerCase();
122
- for (const [singular, plural] of IRREGULAR_PLURALS) {
123
- // NOTE: We check that items *end with* a given word because we use combined words
124
- // like `UserHistory` as input values of this function.
125
- if (lower.endsWith(singular)) {
126
- return s.slice(0, -singular.length + 1) + plural.slice(1);
127
- }
128
- }
129
- if (lower.endsWith('ss')) {
130
- return s.slice(0, -2) + 'sses';
131
- }
132
- if (
133
- // e.g. index
134
- lower.endsWith('x') ||
135
- // e.g. buzz
136
- lower.endsWith('z') ||
137
- // e.g. wish
138
- lower.endsWith('sh') ||
139
- // e.g. match
140
- lower.endsWith('ch')) {
141
- return s + 'es';
142
- }
143
- if (s.endsWith('y') &&
144
- !s.endsWith('ay') &&
145
- !s.endsWith('ey') &&
146
- !s.endsWith('iy') &&
147
- !s.endsWith('oy') &&
148
- !s.endsWith('uy')) {
149
- return s.slice(0, -1) + 'ies';
150
- }
151
- if (s.endsWith('s')) {
152
- return s;
153
- }
154
- return s + 's';
155
- };
156
- exports.pluralize = pluralize;
157
- /**
158
- * Returns true if the given string is already pluralized.
159
- */
160
- const isPlural = (s) => {
161
- const plural = (0, exports.pluralize)(s);
162
- return plural === s;
163
- };
164
- exports.isPlural = isPlural;
165
- /**
166
- * Converts each line of a string to a commented line
167
- */
168
- const commentLines = (lines) => {
169
- return lines
170
- .split('\n')
171
- .map((l) => `// ${l}`)
172
- .join('\n');
173
- };
174
- exports.commentLines = commentLines;
175
- /**
176
- * Provide all relevant conjugation of a name
177
- */
178
- const conjugateNames = (name) => ({
179
- PascalCase: (0, exports.toPascalCase)(name),
180
- camelCase: (0, exports.toCamelCase)(name),
181
- pluralized: (0, exports.capitalize)((0, exports.pluralize)(name)),
182
- uncapitalizedPlural: (0, exports.uncapitalize)((0, exports.pluralize)(name)),
183
- uncapitalized: (0, exports.uncapitalize)(name),
184
- capitalized: (0, exports.capitalize)(name),
185
- capitalizedPlural: (0, exports.capitalize)((0, exports.pluralize)(name)),
186
- });
187
- exports.conjugateNames = conjugateNames;
@@ -1,12 +0,0 @@
1
- type Without<T, U> = {
2
- [P in Exclude<keyof T, keyof U>]?: never;
3
- };
4
- export type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
5
- export type Exact<T, I> = T extends I ? (Exclude<keyof T, keyof I> extends never ? T : never) : never;
6
- export type UncapitalizeObjectKeys<T> = {
7
- [key in keyof T as Uncapitalize<key & string>]: T[key];
8
- };
9
- export type Prettify<T> = {
10
- [K in keyof T]: T[K];
11
- };
12
- export {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/dist/lib/zod.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { Field } from './schema/schema';
2
- /**
3
- * Returns the string defining the zod decoder for a given field.
4
- */
5
- export declare const getZodDecoderDefinition: ({ field, allowAnyOptionalField, }: {
6
- field: Field;
7
- allowAnyOptionalField?: boolean;
8
- }) => string;
package/dist/lib/zod.js DELETED
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getZodDecoderDefinition = void 0;
4
- const meta_1 = require("./meta");
5
- const types_1 = require("./types");
6
- /**
7
- * Returns the string defining the zod decoder for a given field.
8
- */
9
- const getZodDecoderDefinition = ({ field, allowAnyOptionalField, }) => {
10
- let definition = getZodTypeDefinition(field);
11
- if (field.kind === 'id') {
12
- const idModelMeta = (0, meta_1.getModelMetadata)({ model: field.model });
13
- definition += `.transform((x) => ${idModelMeta.types.toBrandedIdTypeFnName}(x))`;
14
- }
15
- if (field.kind === 'relation') {
16
- const refModelMeta = (0, meta_1.getModelMetadata)({ model: field.relationToModel });
17
- definition += `.transform((x) => ${refModelMeta.types.toBrandedIdTypeFnName}(x))`;
18
- }
19
- if (!field.isRequired) {
20
- definition += `.nullable()`;
21
- }
22
- if (allowAnyOptionalField) {
23
- definition += `.optional()`;
24
- }
25
- return definition;
26
- };
27
- exports.getZodDecoderDefinition = getZodDecoderDefinition;
28
- /**
29
- * Returns the string defining the type of the Zod decoder for a given field.
30
- */
31
- function getZodTypeDefinition(field) {
32
- switch (field.kind) {
33
- case 'scalar':
34
- switch (field.tsTypeName) {
35
- case 'Date': {
36
- return `date()`;
37
- }
38
- case 'number': {
39
- switch (field.schemaType) {
40
- case 'Int':
41
- case 'BigInt':
42
- return `number().int()`;
43
- default:
44
- return `number()`;
45
- }
46
- }
47
- default: {
48
- return `${field.tsTypeName}()`;
49
- }
50
- }
51
- case 'enum':
52
- return `enum([${field.enumerator.values.map((v) => `'${v}'`).join(', ')}])`;
53
- case 'id':
54
- return `${field.unbrandedTypeName}()`;
55
- case 'relation':
56
- return `${field.unbrandedTypeName}()`;
57
- default:
58
- throw new types_1.ExhaustiveSwitchCheck(field);
59
- }
60
- }
@@ -1,21 +0,0 @@
1
- import { DMMF } from '@prisma/generator-helper';
2
- import type { Attributes, AttributeValue, EnumAttributes, FieldAttributes, ModelAttributes } from '../lib/attributes';
3
- /**
4
- * Parses attributes from a given string using provided prefix.
5
- */
6
- export declare function parseAttributesFromDocumentation({ documentation }: {
7
- documentation?: string;
8
- }): Attributes;
9
- export declare function parseArgumentToStringOrStringArray(str: string): AttributeValue;
10
- /**
11
- * Returns attribute information for a given model.
12
- */
13
- export declare function getModelAttributes(model: DMMF.Model): ModelAttributes;
14
- /**
15
- * Returns attribute information for a given enum.
16
- */
17
- export declare function getEnumAttributes(model: DMMF.DatamodelEnum): EnumAttributes;
18
- /**
19
- * Returns all attributes assigned to a field
20
- */
21
- export declare function getFieldAttributes(field: DMMF.Field): FieldAttributes;
@@ -1,175 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getFieldAttributes = exports.getEnumAttributes = exports.getModelAttributes = exports.parseArgumentToStringOrStringArray = exports.parseAttributesFromDocumentation = void 0;
7
- const zod_1 = __importDefault(require("zod"));
8
- const error_1 = require("../lib/utils/error");
9
- const logger_1 = require("../lib/utils/logger");
10
- const string_1 = require("../lib/utils/string");
11
- /**
12
- * Parses attributes from a given string using provided prefix.
13
- */
14
- function parseAttributesFromDocumentation({ documentation }) {
15
- const prefix = '@@';
16
- if (!documentation) {
17
- return {};
18
- }
19
- return documentation
20
- .split('\n')
21
- .filter((d) => d.startsWith(prefix))
22
- .map((d) => d.replace(prefix, ''))
23
- .reduce((acc, line) => {
24
- const pattern = /(\w+)\((.*?)\)$/;
25
- if (!pattern.test(line)) {
26
- return acc;
27
- }
28
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
29
- const [attribute, arg] = line.match(pattern).slice(1);
30
- acc[(0, string_1.toCamelCase)(attribute)] = parseArgumentToStringOrStringArray(arg);
31
- return acc;
32
- }, {});
33
- }
34
- exports.parseAttributesFromDocumentation = parseAttributesFromDocumentation;
35
- function parseArgumentToStringOrStringArray(str) {
36
- if (str === '') {
37
- return '';
38
- }
39
- try {
40
- return JSON.parse(str);
41
- }
42
- catch (_a) {
43
- // ignore
44
- }
45
- try {
46
- return JSON.parse(`[${str}]`);
47
- }
48
- catch (_b) {
49
- // ignore
50
- }
51
- try {
52
- return JSON.parse(`"${str}"`);
53
- }
54
- catch (_c) {
55
- // ignore
56
- }
57
- throw new Error(`Could not parse attribute argument: ${str}`);
58
- }
59
- exports.parseArgumentToStringOrStringArray = parseArgumentToStringOrStringArray;
60
- const blankStringBooleanDecoder = zod_1.default
61
- .string()
62
- .transform(() => true)
63
- .or(zod_1.default.boolean())
64
- .optional()
65
- .default(false);
66
- /**
67
- * Returns attribute information for a given model.
68
- */
69
- function getModelAttributes(model) {
70
- const attributes = parseAttributesFromDocumentation(model);
71
- const decoder = zod_1.default
72
- .object({
73
- ignore: blankStringBooleanDecoder,
74
- description: zod_1.default.string().optional(),
75
- schema: zod_1.default.string({
76
- required_error: `The PostXL attribute ${(0, logger_1.highlight)('`///@@Schema`')} attribute must be provided (in addition to Prisma's @@schema attribute)!`,
77
- }),
78
- index: zod_1.default.array(zod_1.default.string()).optional(),
79
- seed: zod_1.default.string().optional(),
80
- systemUser: zod_1.default
81
- .string()
82
- .transform((t) => JSON.parse(t))
83
- .optional(),
84
- })
85
- .transform((obj) => ({
86
- ignore: obj.ignore,
87
- description: obj.description,
88
- databaseSchema: obj.schema,
89
- index: obj.index,
90
- systemUser: obj.systemUser,
91
- randomSeed: obj.seed !== undefined ? parseInt(obj.seed, 10) : undefined,
92
- }));
93
- const result = decoder.safeParse(attributes);
94
- if (!result.success) {
95
- throw new Error((0, error_1.formatZodError)(result.error));
96
- }
97
- return result.data;
98
- }
99
- exports.getModelAttributes = getModelAttributes;
100
- /**
101
- * Returns attribute information for a given enum.
102
- */
103
- function getEnumAttributes(model) {
104
- const attributes = parseAttributesFromDocumentation(model);
105
- const decoder = zod_1.default
106
- .object({
107
- description: zod_1.default.string().optional(),
108
- valueDescription: zod_1.default.record(zod_1.default.string()).optional(),
109
- })
110
- .transform((obj) => ({
111
- description: obj.description,
112
- valueDescription: obj.valueDescription,
113
- }));
114
- const result = decoder.safeParse(attributes);
115
- if (!result.success) {
116
- throw new Error(`Model ${model.name} has invalid model attributes: ${result.error.toString()}`);
117
- }
118
- return result.data;
119
- }
120
- exports.getEnumAttributes = getEnumAttributes;
121
- /**
122
- * Returns all attributes assigned to a field
123
- */
124
- function getFieldAttributes(field) {
125
- const attributes = parseAttributesFromDocumentation(field);
126
- // Prisma also has an "@ignore" attribute - see https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#ignore
127
- // The `isIgnored` property is not documented in the DMMF anymore, but it is still provided by Prisma.
128
- // In case it is found but our attribute is missing, we throw an error, forcing the user to also set our attribute.
129
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
130
- const isPrismaIgnored = field.isIgnored === true;
131
- const exampleDecoder = zod_1.default.union([zod_1.default.string(), zod_1.default.number(), zod_1.default.boolean(), zod_1.default.null()]);
132
- const examplesDecoder = exampleDecoder
133
- .transform((obj) => [obj])
134
- .or(zod_1.default.array(exampleDecoder))
135
- .optional();
136
- const decoder = zod_1.default
137
- .object({
138
- ignore: blankStringBooleanDecoder,
139
- description: zod_1.default.string().optional(),
140
- isDefault: blankStringBooleanDecoder,
141
- isNameField: blankStringBooleanDecoder,
142
- label: zod_1.default.string().optional(),
143
- example: examplesDecoder,
144
- examples: examplesDecoder,
145
- maxLength: zod_1.default
146
- .number()
147
- .or(zod_1.default.string().transform((s) => parseInt(s, 10)))
148
- .optional(),
149
- readonly: blankStringBooleanDecoder,
150
- })
151
- .transform((obj) => {
152
- var _a, _b;
153
- if (isPrismaIgnored && !obj.ignore) {
154
- throw new Error(`Field ${field.name} is ignored by Prisma, but is missing the "ignore" PostXL attribute!`);
155
- }
156
- return {
157
- ignore: obj.ignore,
158
- description: obj.description,
159
- isDefaultField: obj.isDefault,
160
- isNameField: obj.isNameField,
161
- label: (_a = obj.label) !== null && _a !== void 0 ? _a : (0, string_1.toPascalCase)(field.name),
162
- examples: obj.examples || obj.example,
163
- maxLength: obj.maxLength,
164
- isReadonly: obj.readonly || field.isGenerated || field.isUpdatedAt || field.name === 'createdAt' || field.isId,
165
- isUpdatedAt: (_b = field.isUpdatedAt) !== null && _b !== void 0 ? _b : false,
166
- isCreatedAt: field.name === 'createdAt',
167
- };
168
- });
169
- const result = decoder.safeParse(attributes);
170
- if (!result.success) {
171
- throw new Error(`Field ${field.name} has invalid field attributes: ${result.error.toString()}`);
172
- }
173
- return result.data;
174
- }
175
- exports.getFieldAttributes = getFieldAttributes;
@@ -1,7 +0,0 @@
1
- import { GeneratorConfig } from '@prisma/generator-helper';
2
- /**
3
- * Returns the Node import path for the Prisma Client.
4
- *
5
- * NOTE: This should normally be @prisma/client, but can be different if output is specified in schema.prisma.
6
- */
7
- export declare function getClientImportPath(generators: GeneratorConfig[]): string;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getClientImportPath = void 0;
4
- /**
5
- * Returns the Node import path for the Prisma Client.
6
- *
7
- * NOTE: This should normally be @prisma/client, but can be different if output is specified in schema.prisma.
8
- */
9
- function getClientImportPath(generators) {
10
- var _a;
11
- const clientGenerator = generators.find((g) => g.provider.value === 'prisma-client-js');
12
- if (!clientGenerator) {
13
- return '@prisma/client';
14
- }
15
- const output = (_a = clientGenerator.output) === null || _a === void 0 ? void 0 : _a.value;
16
- if (!output) {
17
- return '@prisma/client';
18
- }
19
- //if output contains @..., return everything starting from @ and replace \\ with /
20
- if (output.includes('@')) {
21
- return output.substring(output.lastIndexOf('@')).replace(/\\/g, '/');
22
- }
23
- //if output contains node_modules, return everything after node_modules and replace \\ with /
24
- if (output.includes('node_modules')) {
25
- return output.substring(output.indexOf('node_modules') + 'node_modules'.length).replace(/\\/g, '/');
26
- }
27
- return '@prisma/client';
28
- }
29
- exports.getClientImportPath = getClientImportPath;
@@ -1,12 +0,0 @@
1
- import { DMMF } from '@prisma/generator-helper';
2
- import * as Schema from '../lib/schema/schema';
3
- /**
4
- * Converts a Prisma schema (DMMF) document to a Schema that's passed around generators.
5
- */
6
- export declare function parsePrismaSchema({ datamodel: { enums: enumsRaw, models: modelsRaw }, config, }: {
7
- datamodel: DMMF.Datamodel;
8
- config: Schema.SchemaConfig;
9
- }): {
10
- models: Schema.Model[];
11
- enums: Schema.Enum[];
12
- };