prisma-generator-express 1.34.0 → 1.34.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.
@@ -1,9 +1,18 @@
1
1
  import { DMMF } from '@prisma/generator-helper'
2
+ import { toCamelCase } from '../utils/strings.js'
2
3
 
3
4
  export interface UnifiedHandlerOptions {
4
5
  model: DMMF.Model
5
6
  }
6
7
 
8
+ const CORE_NAME_MAP: Record<string, string> = {
9
+ delete: 'deleteUnique',
10
+ }
11
+
12
+ function coreFnName(op: string): string {
13
+ return CORE_NAME_MAP[op] || op
14
+ }
15
+
7
16
  const ALL_OPS = [
8
17
  'findMany',
9
18
  'findFirst',
@@ -27,9 +36,10 @@ const ALL_OPS = [
27
36
 
28
37
  export function generateUnifiedHandler(options: UnifiedHandlerOptions): string {
29
38
  const modelName = options.model.name
39
+ const prefix = toCamelCase(modelName)
30
40
 
31
41
  const handlers = ALL_OPS.map((op) => {
32
- const exportName = `${modelName}${op.charAt(0).toUpperCase() + op.slice(1)}`
42
+ const exportName = `${prefix}${op.charAt(0).toUpperCase() + op.slice(1)}`
33
43
 
34
44
  return `
35
45
  export async function ${exportName}(
@@ -38,7 +48,7 @@ export async function ${exportName}(
38
48
  next: NextFunction,
39
49
  ) {
40
50
  try {
41
- res.locals.data = await core.${op}(buildContext(req, res))
51
+ res.locals.data = await core.${coreFnName(op)}(buildContext(req, res))
42
52
  next()
43
53
  } catch (error: unknown) {
44
54
  next(mapError(error))
@@ -3,5 +3,8 @@ export const capitalize = (str: string) =>
3
3
 
4
4
  export function toCamelCase(str: string) {
5
5
  if (!str) return str
6
- return str.charAt(0).toLowerCase() + str.slice(1)
6
+ return str
7
+ .split('_')
8
+ .map((part, i) => i === 0 ? part.toLowerCase() : capitalize(part))
9
+ .join('')
7
10
  }