prisma-generator-express 1.65.2 → 1.67.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 (106) hide show
  1. package/README.md +51 -3480
  2. package/dist/client/encodeQueryParams.js +3 -1
  3. package/dist/client/encodeQueryParams.js.map +1 -1
  4. package/dist/copy/misc.d.ts +1 -0
  5. package/dist/copy/misc.js +14 -0
  6. package/dist/copy/misc.js.map +1 -1
  7. package/dist/copy/operationDefinitions.js +69 -6
  8. package/dist/copy/operationDefinitions.js.map +1 -1
  9. package/dist/generators/generateFastifyHandler.d.ts +2 -2
  10. package/dist/generators/generateFastifyHandler.js +15 -5
  11. package/dist/generators/generateFastifyHandler.js.map +1 -1
  12. package/dist/generators/generateHonoHandler.d.ts +2 -2
  13. package/dist/generators/generateHonoHandler.js +12 -5
  14. package/dist/generators/generateHonoHandler.js.map +1 -1
  15. package/dist/generators/generateImportPrismaStatement.d.ts +1 -0
  16. package/dist/generators/generateImportPrismaStatement.js +6 -0
  17. package/dist/generators/generateImportPrismaStatement.js.map +1 -1
  18. package/dist/generators/generateModelMetadata.js +20 -10
  19. package/dist/generators/generateModelMetadata.js.map +1 -1
  20. package/dist/generators/generateOperationCore.d.ts +3 -3
  21. package/dist/generators/generateOperationCore.js +51 -16
  22. package/dist/generators/generateOperationCore.js.map +1 -1
  23. package/dist/generators/generateQueryBuilderHelper.d.ts +1 -1
  24. package/dist/generators/generateQueryBuilderHelper.js +2 -4
  25. package/dist/generators/generateQueryBuilderHelper.js.map +1 -1
  26. package/dist/generators/generateRelationMeta.js +2 -2
  27. package/dist/generators/generateRelationMeta.js.map +1 -1
  28. package/dist/generators/generateRouteConfigType.d.ts +2 -2
  29. package/dist/generators/generateRouteConfigType.js +29 -11
  30. package/dist/generators/generateRouteConfigType.js.map +1 -1
  31. package/dist/generators/generateRouter.d.ts +7 -4
  32. package/dist/generators/generateRouter.js +107 -14
  33. package/dist/generators/generateRouter.js.map +1 -1
  34. package/dist/generators/generateRouterFastify.d.ts +7 -4
  35. package/dist/generators/generateRouterFastify.js +56 -28
  36. package/dist/generators/generateRouterFastify.js.map +1 -1
  37. package/dist/generators/generateRouterHono.d.ts +7 -4
  38. package/dist/generators/generateRouterHono.js +84 -53
  39. package/dist/generators/generateRouterHono.js.map +1 -1
  40. package/dist/generators/generateUnifiedDocs.d.ts +1 -1
  41. package/dist/generators/generateUnifiedDocs.js +15 -8
  42. package/dist/generators/generateUnifiedDocs.js.map +1 -1
  43. package/dist/generators/generateUnifiedHandler.d.ts +2 -2
  44. package/dist/generators/generateUnifiedHandler.js +11 -3
  45. package/dist/generators/generateUnifiedHandler.js.map +1 -1
  46. package/dist/guardOptions.js +12 -7
  47. package/dist/guardOptions.js.map +1 -1
  48. package/dist/index.d.ts +1 -1
  49. package/dist/index.js +22 -1
  50. package/dist/index.js.map +1 -1
  51. package/dist/utils/copyFiles.js +22 -6
  52. package/dist/utils/copyFiles.js.map +1 -1
  53. package/dist/utils/importExt.d.ts +1 -1
  54. package/dist/utils/pathCasing.d.ts +4 -0
  55. package/dist/utils/pathCasing.js +40 -0
  56. package/dist/utils/pathCasing.js.map +1 -0
  57. package/dist/utils/resolveImportStyle.js +13 -5
  58. package/dist/utils/resolveImportStyle.js.map +1 -1
  59. package/dist/utils/writeFileSafely.js.map +1 -1
  60. package/package.json +16 -3
  61. package/src/bin.ts +1 -1
  62. package/src/client/encodeQueryParams.ts +39 -35
  63. package/src/constants.ts +1 -1
  64. package/src/copy/autoIncludePlanner.ts +93 -27
  65. package/src/copy/autoIncludePlannerGuarded.ts +171 -48
  66. package/src/copy/autoIncludeRuntimeGuarded.ts +25 -7
  67. package/src/copy/buildModelOpenApi.ts +153 -50
  68. package/src/copy/concurrency.ts +10 -8
  69. package/src/copy/errorMapper.ts +68 -19
  70. package/src/copy/guardHelpers.ts +30 -9
  71. package/src/copy/materializedCount.ts +17 -5
  72. package/src/copy/misc.ts +88 -68
  73. package/src/copy/ndjson.ts +72 -0
  74. package/src/copy/operationDefinitions.ts +99 -21
  75. package/src/copy/operationRuntime.ts +100 -12
  76. package/src/copy/pagination.ts +25 -11
  77. package/src/copy/parseQueryParams.ts +47 -48
  78. package/src/copy/projectionDefaults.ts +6 -4
  79. package/src/copy/routeConfig.express.ts +16 -4
  80. package/src/copy/routeConfig.fastify.ts +16 -2
  81. package/src/copy/routeConfig.hono.ts +19 -9
  82. package/src/copy/routeConfig.ts +174 -39
  83. package/src/copy/scalarTypes.ts +7 -2
  84. package/src/copy/sse.ts +72 -19
  85. package/src/generators/generateFastifyHandler.ts +24 -13
  86. package/src/generators/generateHonoHandler.ts +21 -13
  87. package/src/generators/generateImportPrismaStatement.ts +93 -81
  88. package/src/generators/generateModelMetadata.ts +24 -12
  89. package/src/generators/generateOperationCore.ts +81 -33
  90. package/src/generators/generateQueryBuilderHelper.ts +20 -4
  91. package/src/generators/generateRelationMeta.ts +23 -11
  92. package/src/generators/generateRouteConfigType.ts +39 -13
  93. package/src/generators/generateRouter.ts +114 -17
  94. package/src/generators/generateRouterFastify.ts +67 -31
  95. package/src/generators/generateRouterHono.ts +108 -60
  96. package/src/generators/generateUnifiedDocs.ts +29 -8
  97. package/src/generators/generateUnifiedHandler.ts +16 -8
  98. package/src/generators/generateUnifiedScalarUI.ts +1 -1
  99. package/src/guardOptions.ts +105 -92
  100. package/src/index.ts +46 -4
  101. package/src/utils/copyFiles.ts +199 -168
  102. package/src/utils/importExt.ts +2 -2
  103. package/src/utils/pathCasing.ts +42 -0
  104. package/src/utils/resolveImportStyle.ts +37 -15
  105. package/src/utils/strings.ts +2 -2
  106. package/src/utils/writeFileSafely.ts +6 -2
@@ -1,168 +1,199 @@
1
- import { GeneratorOptions } from '@prisma/generator-helper'
2
- import * as fs from 'fs'
3
- import * as path from 'path'
4
- import { Target } from '../constants'
5
- import { ImportStyle } from './resolveImportStyle'
6
- import { importExt } from './importExt'
7
-
8
- const SHARED_FILES = [
9
- 'parseQueryParams.ts',
10
- 'buildModelOpenApi.ts',
11
- 'operationDefinitions.ts',
12
- 'misc.ts',
13
- 'routeConfig.ts',
14
- 'docsRenderer.ts',
15
- 'operationRuntime.ts',
16
- 'errorMapper.ts',
17
- 'sse.ts',
18
- 'pagination.ts',
19
- 'materializedCount.ts',
20
- 'guardHelpers.ts',
21
- 'scalarTypes.ts',
22
- 'concurrency.ts',
23
- 'projectionDefaults.ts',
24
- 'guardVariantRouting.ts',
25
- 'guardVariantError.ts',
26
- ]
27
-
28
- const EXPRESS_ONLY_FILES = [
29
- 'autoIncludePlanner.ts',
30
- 'autoIncludePlannerGuarded.ts',
31
- 'autoIncludeRuntime.ts',
32
- 'autoIncludeRuntimeGuarded.ts',
33
- 'materializedRouter.ts',
34
- ]
35
-
36
- interface CopyFileOptions {
37
- required?: boolean
38
- importRewrites?: Array<{ from: string; to: string }>
39
- destFilename?: string
40
- }
41
-
42
- function resolveTemplateDir(subpath: string): string {
43
- const fromSrc = path.join(__dirname, '..', '..', 'src', subpath)
44
- if (fs.existsSync(fromSrc)) return fromSrc
45
- const fromDist = path.join(__dirname, '..', subpath)
46
- if (fs.existsSync(fromDist)) return fromDist
47
- throw new Error(
48
- 'Template directory "' + subpath + '" not found.\n Searched:\n ' +
49
- fromSrc + '\n ' + fromDist + '\n __dirname: ' + __dirname,
50
- )
51
- }
52
-
53
- function escapeRegex(str: string): string {
54
- return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
55
- }
56
-
57
- const RELATIVE_IMPORT_RE =
58
- /(\b(?:import|export)\b[^'";]*?\bfrom\s+|\bimport\s+|\bimport\s*\(\s*)(['"])(\.{1,2}\/[^'"\n]+)\2/g
59
-
60
- const SKIP_EXTENSION_RE = /\.(m?[jt]sx?|json|css|svg|png|jpe?g|gif|webp|wasm)$/i
61
-
62
- function applyExtension(content: string, style: ImportStyle): string {
63
- if (style === 'none') return content
64
- const ext = importExt(style)
65
- if (!ext) return content
66
- return content.replace(RELATIVE_IMPORT_RE, (_match, prefix, quote, spec) => {
67
- if (SKIP_EXTENSION_RE.test(spec)) return prefix + quote + spec + quote
68
- return prefix + quote + spec + ext + quote
69
- })
70
- }
71
-
72
- function copyFileSync(
73
- srcDir: string,
74
- destDir: string,
75
- filename: string,
76
- importStyle: ImportStyle,
77
- options?: CopyFileOptions,
78
- ): string | null {
79
- const srcPath = path.join(srcDir, filename)
80
- const destFilename = options?.destFilename || filename
81
- const destPath = path.join(destDir, destFilename)
82
-
83
- if (!fs.existsSync(srcPath)) {
84
- if (options?.required) return 'Required file not found: ' + srcPath
85
- return null
86
- }
87
-
88
- const destDirPath = path.dirname(destPath)
89
- if (!fs.existsSync(destDirPath)) fs.mkdirSync(destDirPath, { recursive: true })
90
-
91
- let content = fs.readFileSync(srcPath, 'utf-8')
92
-
93
- if (options?.importRewrites) {
94
- for (const rewrite of options.importRewrites) {
95
- if (rewrite.from === rewrite.to) continue
96
- content = content.replace(
97
- new RegExp('from [\'"]' + escapeRegex(rewrite.from) + '[\'"]', 'g'),
98
- "from '" + rewrite.to + "'",
99
- )
100
- }
101
- }
102
-
103
- const header =
104
- '/**\n' +
105
- ' * Auto-generated by prisma-generator-express\n' +
106
- ' * DO NOT EDIT MANUALLY\n' +
107
- ' */\n\n'
108
-
109
- if (!content.startsWith('/**')) content = header + content
110
-
111
- content = applyExtension(content, importStyle)
112
-
113
- fs.writeFileSync(destPath, content)
114
- return null
115
- }
116
-
117
- export async function copyFiles(
118
- options: GeneratorOptions,
119
- target: Target,
120
- importStyle: ImportStyle,
121
- ): Promise<void> {
122
- const outputPath = options.generator.output?.value
123
- if (!outputPath) return
124
-
125
- const copyBase = resolveTemplateDir('copy')
126
- const errors: string[] = []
127
-
128
- console.log(' Copying utility files to: ' + outputPath + ' (target: ' + target + ')')
129
-
130
- for (const file of SHARED_FILES) {
131
- const err = copyFileSync(copyBase, outputPath, file, importStyle, { required: true })
132
- if (err) errors.push(err)
133
- }
134
-
135
- if (target === 'express') {
136
- for (const file of EXPRESS_ONLY_FILES) {
137
- const err = copyFileSync(copyBase, outputPath, file, importStyle, { required: true })
138
- if (err) errors.push(err)
139
- }
140
- }
141
-
142
- const targetConfigFile = 'routeConfig.' + target + '.ts'
143
- const err = copyFileSync(copyBase, outputPath, targetConfigFile, importStyle, {
144
- required: true,
145
- destFilename: 'routeConfig.target.ts',
146
- })
147
- if (err) errors.push(err)
148
-
149
- const clientDir = path.join(outputPath, 'client')
150
- if (!fs.existsSync(clientDir)) fs.mkdirSync(clientDir, { recursive: true })
151
-
152
- const clientSrcDir = resolveTemplateDir('client')
153
- const clientErr = copyFileSync(clientSrcDir, clientDir, 'encodeQueryParams.ts', importStyle, {
154
- required: true,
155
- importRewrites: [{ from: '../copy/misc', to: '../misc' }],
156
- })
157
- if (clientErr) errors.push(clientErr)
158
-
159
- if (errors.length > 0) {
160
- throw new Error(
161
- 'Failed to copy ' + errors.length + ' required file(s):\n' +
162
- errors.map((e) => ' - ' + e).join('\n') +
163
- '\n copyBase: ' + copyBase + '\n __dirname: ' + __dirname,
164
- )
165
- }
166
-
167
- console.log(' ✓ Utility files copied successfully')
168
- }
1
+ import { GeneratorOptions } from '@prisma/generator-helper'
2
+ import * as fs from 'fs'
3
+ import * as path from 'path'
4
+ import { Target } from '../constants'
5
+ import { ImportStyle } from './resolveImportStyle'
6
+ import { importExt } from './importExt'
7
+
8
+ const SHARED_FILES = [
9
+ 'parseQueryParams.ts',
10
+ 'buildModelOpenApi.ts',
11
+ 'operationDefinitions.ts',
12
+ 'misc.ts',
13
+ 'routeConfig.ts',
14
+ 'docsRenderer.ts',
15
+ 'operationRuntime.ts',
16
+ 'errorMapper.ts',
17
+ 'sse.ts',
18
+ 'pagination.ts',
19
+ 'materializedCount.ts',
20
+ 'guardHelpers.ts',
21
+ 'scalarTypes.ts',
22
+ 'concurrency.ts',
23
+ 'projectionDefaults.ts',
24
+ 'guardVariantRouting.ts',
25
+ 'guardVariantError.ts',
26
+ ]
27
+
28
+ const EXPRESS_ONLY_FILES = [
29
+ 'autoIncludePlanner.ts',
30
+ 'autoIncludePlannerGuarded.ts',
31
+ 'autoIncludeRuntime.ts',
32
+ 'autoIncludeRuntimeGuarded.ts',
33
+ 'materializedRouter.ts',
34
+ 'ndjson.ts',
35
+ ]
36
+
37
+ interface CopyFileOptions {
38
+ required?: boolean
39
+ importRewrites?: Array<{ from: string; to: string }>
40
+ destFilename?: string
41
+ }
42
+
43
+ function resolveTemplateDir(subpath: string): string {
44
+ const fromSrc = path.join(__dirname, '..', '..', 'src', subpath)
45
+ if (fs.existsSync(fromSrc)) return fromSrc
46
+ const fromDist = path.join(__dirname, '..', subpath)
47
+ if (fs.existsSync(fromDist)) return fromDist
48
+ throw new Error(
49
+ 'Template directory "' +
50
+ subpath +
51
+ '" not found.\n Searched:\n ' +
52
+ fromSrc +
53
+ '\n ' +
54
+ fromDist +
55
+ '\n __dirname: ' +
56
+ __dirname,
57
+ )
58
+ }
59
+
60
+ function escapeRegex(str: string): string {
61
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
62
+ }
63
+
64
+ const RELATIVE_IMPORT_RE =
65
+ /(\b(?:import|export)\b[^'";]*?\bfrom\s+|\bimport\s+|\bimport\s*\(\s*)(['"])(\.{1,2}\/[^'"\n]+)\2/g
66
+
67
+ const SKIP_EXTENSION_RE = /\.(m?[jt]sx?|json|css|svg|png|jpe?g|gif|webp|wasm)$/i
68
+
69
+ function applyExtension(content: string, style: ImportStyle): string {
70
+ if (style === 'none') return content
71
+ const ext = importExt(style)
72
+ if (!ext) return content
73
+ return content.replace(RELATIVE_IMPORT_RE, (_match, prefix, quote, spec) => {
74
+ if (SKIP_EXTENSION_RE.test(spec)) return prefix + quote + spec + quote
75
+ return prefix + quote + spec + ext + quote
76
+ })
77
+ }
78
+
79
+ function copyFileSync(
80
+ srcDir: string,
81
+ destDir: string,
82
+ filename: string,
83
+ importStyle: ImportStyle,
84
+ options?: CopyFileOptions,
85
+ ): string | null {
86
+ const srcPath = path.join(srcDir, filename)
87
+ const destFilename = options?.destFilename || filename
88
+ const destPath = path.join(destDir, destFilename)
89
+
90
+ if (!fs.existsSync(srcPath)) {
91
+ if (options?.required) return 'Required file not found: ' + srcPath
92
+ return null
93
+ }
94
+
95
+ const destDirPath = path.dirname(destPath)
96
+ if (!fs.existsSync(destDirPath))
97
+ fs.mkdirSync(destDirPath, { recursive: true })
98
+
99
+ let content = fs.readFileSync(srcPath, 'utf-8')
100
+
101
+ if (options?.importRewrites) {
102
+ for (const rewrite of options.importRewrites) {
103
+ if (rewrite.from === rewrite.to) continue
104
+ content = content.replace(
105
+ new RegExp('from [\'"]' + escapeRegex(rewrite.from) + '[\'"]', 'g'),
106
+ "from '" + rewrite.to + "'",
107
+ )
108
+ }
109
+ }
110
+
111
+ const header =
112
+ '/**\n' +
113
+ ' * Auto-generated by prisma-generator-express\n' +
114
+ ' * DO NOT EDIT MANUALLY\n' +
115
+ ' */\n\n'
116
+
117
+ if (!content.startsWith('/**')) content = header + content
118
+
119
+ content = applyExtension(content, importStyle)
120
+
121
+ fs.writeFileSync(destPath, content)
122
+ return null
123
+ }
124
+
125
+ export async function copyFiles(
126
+ options: GeneratorOptions,
127
+ target: Target,
128
+ importStyle: ImportStyle,
129
+ ): Promise<void> {
130
+ const outputPath = options.generator.output?.value
131
+ if (!outputPath) return
132
+
133
+ const copyBase = resolveTemplateDir('copy')
134
+ const errors: string[] = []
135
+
136
+ console.log(
137
+ ' Copying utility files to: ' + outputPath + ' (target: ' + target + ')',
138
+ )
139
+
140
+ for (const file of SHARED_FILES) {
141
+ const err = copyFileSync(copyBase, outputPath, file, importStyle, {
142
+ required: true,
143
+ })
144
+ if (err) errors.push(err)
145
+ }
146
+
147
+ if (target === 'express') {
148
+ for (const file of EXPRESS_ONLY_FILES) {
149
+ const err = copyFileSync(copyBase, outputPath, file, importStyle, {
150
+ required: true,
151
+ })
152
+ if (err) errors.push(err)
153
+ }
154
+ }
155
+
156
+ const targetConfigFile = 'routeConfig.' + target + '.ts'
157
+ const err = copyFileSync(
158
+ copyBase,
159
+ outputPath,
160
+ targetConfigFile,
161
+ importStyle,
162
+ {
163
+ required: true,
164
+ destFilename: 'routeConfig.target.ts',
165
+ },
166
+ )
167
+ if (err) errors.push(err)
168
+
169
+ const clientDir = path.join(outputPath, 'client')
170
+ if (!fs.existsSync(clientDir)) fs.mkdirSync(clientDir, { recursive: true })
171
+
172
+ const clientSrcDir = resolveTemplateDir('client')
173
+ const clientErr = copyFileSync(
174
+ clientSrcDir,
175
+ clientDir,
176
+ 'encodeQueryParams.ts',
177
+ importStyle,
178
+ {
179
+ required: true,
180
+ importRewrites: [{ from: '../copy/misc', to: '../misc' }],
181
+ },
182
+ )
183
+ if (clientErr) errors.push(clientErr)
184
+
185
+ if (errors.length > 0) {
186
+ throw new Error(
187
+ 'Failed to copy ' +
188
+ errors.length +
189
+ ' required file(s):\n' +
190
+ errors.map((e) => ' - ' + e).join('\n') +
191
+ '\n copyBase: ' +
192
+ copyBase +
193
+ '\n __dirname: ' +
194
+ __dirname,
195
+ )
196
+ }
197
+
198
+ console.log(' ✓ Utility files copied successfully')
199
+ }
@@ -1,7 +1,7 @@
1
- import { ImportStyle } from './resolveImportStyle'
1
+ import type { ImportStyle } from './resolveImportStyle'
2
2
 
3
3
  export function importExt(style: ImportStyle): string {
4
4
  if (style === 'js') return '.js'
5
5
  if (style === 'ts') return '.ts'
6
6
  return ''
7
- }
7
+ }
@@ -0,0 +1,42 @@
1
+ export type PathCase = 'lower' | 'kebab' | 'raw'
2
+
3
+ export function parsePathCase(raw: unknown): PathCase {
4
+ const value = String(raw ?? 'lower').toLowerCase()
5
+ if (value === 'lower' || value === 'kebab' || value === 'raw') return value
6
+ throw new Error(
7
+ `Invalid pathCase "${String(raw)}". Expected "lower", "kebab", or "raw".`,
8
+ )
9
+ }
10
+
11
+ export function toKebabCase(name: string): string {
12
+ let out = ''
13
+ for (let i = 0; i < name.length; i++) {
14
+ const ch = name[i]
15
+ const prev = i > 0 ? name[i - 1] : undefined
16
+ const next = name[i + 1]
17
+ const isUpper = ch >= 'A' && ch <= 'Z'
18
+ const prevIsLower = prev !== undefined && prev >= 'a' && prev <= 'z'
19
+ const prevIsDigit = prev !== undefined && prev >= '0' && prev <= '9'
20
+ const nextIsLower = next !== undefined && next >= 'a' && next <= 'z'
21
+ if (
22
+ isUpper &&
23
+ i > 0 &&
24
+ (prevIsLower ||
25
+ prevIsDigit ||
26
+ (prev !== undefined && prev >= 'A' && prev <= 'Z' && nextIsLower))
27
+ ) {
28
+ out += '-'
29
+ }
30
+ out += ch.toLowerCase()
31
+ }
32
+ return out
33
+ }
34
+
35
+ export function modelPathSegment(
36
+ modelName: string,
37
+ pathCase: PathCase,
38
+ ): string {
39
+ if (pathCase === 'raw') return modelName
40
+ if (pathCase === 'kebab') return toKebabCase(modelName)
41
+ return modelName.toLowerCase()
42
+ }
@@ -39,7 +39,8 @@ function stripJsonComments(input: string): string {
39
39
  }
40
40
  if (c === '/' && next === '*') {
41
41
  i += 2
42
- while (i < input.length && !(input[i] === '*' && input[i + 1] === '/')) i++
42
+ while (i < input.length && !(input[i] === '*' && input[i + 1] === '/'))
43
+ i++
43
44
  i += 2
44
45
  continue
45
46
  }
@@ -75,7 +76,10 @@ function findUpwards(startDir: string, filename: string): string | null {
75
76
  return result
76
77
  }
77
78
 
78
- function resolveExtendsTarget(extendsValue: string, fromFile: string): string | null {
79
+ function resolveExtendsTarget(
80
+ extendsValue: string,
81
+ fromFile: string,
82
+ ): string | null {
79
83
  const fromDir = path.dirname(fromFile)
80
84
  if (extendsValue.startsWith('.') || path.isAbsolute(extendsValue)) {
81
85
  const direct = path.resolve(fromDir, extendsValue)
@@ -90,7 +94,9 @@ function resolveExtendsTarget(extendsValue: string, fromFile: string): string |
90
94
  return require.resolve(extendsValue, { paths: [fromDir] })
91
95
  } catch {
92
96
  try {
93
- return require.resolve(extendsValue + '/tsconfig.json', { paths: [fromDir] })
97
+ return require.resolve(extendsValue + '/tsconfig.json', {
98
+ paths: [fromDir],
99
+ })
94
100
  } catch {
95
101
  return null
96
102
  }
@@ -102,7 +108,10 @@ type TsConfigRaw = {
102
108
  compilerOptions?: Record<string, unknown>
103
109
  }
104
110
 
105
- function readTsConfig(filePath: string, seen: Set<string> = new Set()): Record<string, unknown> {
111
+ function readTsConfig(
112
+ filePath: string,
113
+ seen: Set<string> = new Set(),
114
+ ): Record<string, unknown> {
106
115
  const abs = path.resolve(filePath)
107
116
  if (seen.has(abs)) return {}
108
117
  seen.add(abs)
@@ -143,21 +152,25 @@ function readPackageType(startDir: string): string | null {
143
152
 
144
153
  export function resolveImportStyle(options: GeneratorOptions): ImportStyle {
145
154
  const config = (options.generator.config || {}) as Record<string, string>
146
- const raw = typeof config.importStyle === 'string'
147
- ? config.importStyle.toLowerCase()
148
- : 'auto'
155
+ const raw =
156
+ typeof config.importStyle === 'string'
157
+ ? config.importStyle.toLowerCase()
158
+ : 'auto'
149
159
 
150
160
  if (!VALID_OVERRIDES.has(raw)) {
151
161
  console.warn(
152
- '[prisma-generator-express] Invalid importStyle "' + config.importStyle +
153
- '". Expected one of: auto, none, js, ts. Falling back to auto.',
162
+ '[prisma-generator-express] Invalid importStyle "' +
163
+ config.importStyle +
164
+ '". Expected one of: auto, none, js, ts. Falling back to auto.',
154
165
  )
155
166
  } else if (raw !== 'auto') {
156
167
  return raw as ImportStyle
157
168
  }
158
169
 
159
170
  const outputPath = options.generator.output?.value
160
- const schemaDir = options.schemaPath ? path.dirname(options.schemaPath) : process.cwd()
171
+ const schemaDir = options.schemaPath
172
+ ? path.dirname(options.schemaPath)
173
+ : process.cwd()
161
174
  const startDir = outputPath ? path.dirname(outputPath) : schemaDir
162
175
 
163
176
  const tsconfigPath =
@@ -171,12 +184,21 @@ export function resolveImportStyle(options: GeneratorOptions): ImportStyle {
171
184
  if (compilerOptions.allowImportingTsExtensions === true) return 'ts'
172
185
 
173
186
  const moduleVal = String(compilerOptions.module ?? '').toLowerCase()
174
- const moduleResolution = String(compilerOptions.moduleResolution ?? '').toLowerCase()
175
-
176
- if (NODE_MODULE_KEYWORDS.has(moduleVal) || NODE_MODULE_KEYWORDS.has(moduleResolution)) {
187
+ const moduleResolution = String(
188
+ compilerOptions.moduleResolution ?? '',
189
+ ).toLowerCase()
190
+
191
+ if (
192
+ NODE_MODULE_KEYWORDS.has(moduleVal) ||
193
+ NODE_MODULE_KEYWORDS.has(moduleResolution)
194
+ ) {
177
195
  return 'js'
178
196
  }
179
- if (moduleResolution === 'bundler' || moduleResolution === 'classic' || moduleResolution === 'node') {
197
+ if (
198
+ moduleResolution === 'bundler' ||
199
+ moduleResolution === 'classic' ||
200
+ moduleResolution === 'node'
201
+ ) {
180
202
  return 'none'
181
203
  }
182
204
 
@@ -184,4 +206,4 @@ export function resolveImportStyle(options: GeneratorOptions): ImportStyle {
184
206
  if (pkgType === 'module') return 'js'
185
207
 
186
208
  return 'none'
187
- }
209
+ }
@@ -1,2 +1,2 @@
1
- export const capitalize = (str: string) =>
2
- str.charAt(0).toUpperCase() + str.slice(1)
1
+ export const capitalize = (str: string) =>
2
+ str.charAt(0).toUpperCase() + str.slice(1)
@@ -41,7 +41,11 @@ export async function writeFileSafely({
41
41
  break
42
42
  default:
43
43
  if (!model) throw new Error('Model required for operation: ' + operation)
44
- filePath = path.join(outputPath, model.name, `${model.name}${operation}.ts`)
44
+ filePath = path.join(
45
+ outputPath,
46
+ model.name,
47
+ `${model.name}${operation}.ts`,
48
+ )
45
49
  }
46
50
 
47
51
  const dirPath = path.dirname(filePath)
@@ -54,4 +58,4 @@ export async function writeFileSafely({
54
58
  })
55
59
 
56
60
  fs.writeFileSync(filePath, formattedContent)
57
- }
61
+ }