1- import type { KeystoneContext , BaseItem } from '../../../types'
2- import type { ResolvedDBField } from '../resolve-relationships'
3- import type { InitialisedList } from '../initialise-lists'
41import {
2+ type BaseItem ,
3+ type KeystoneContext
4+ } from '../../../types'
5+ import {
6+ type ResolvedDBField
7+ } from '../resolve-relationships'
8+ import {
9+ type InitialisedList
10+ } from '../initialise-lists'
11+ import {
12+ type IdType ,
513 promiseAllRejectWithAllErrors ,
614 getDBFieldKeyForFieldOnMultiField ,
7- type IdType ,
8- getPrismaNamespace ,
915} from '../utils'
10- import { type InputFilter , resolveUniqueWhereInput , type UniqueInputFilter } from '../where-inputs'
16+ import {
17+ type InputFilter ,
18+ type UniqueInputFilter ,
19+ resolveUniqueWhereInput ,
20+ } from '../where-inputs'
1121import {
1222 accessDeniedError ,
1323 extensionError ,
@@ -82,8 +92,10 @@ export async function createOne (
8292 const operationAccess = await getOperationAccess ( list , context , 'create' )
8393 if ( ! operationAccess ) throw accessDeniedError ( cannotForItem ( 'create' , list ) )
8494
95+ // operation
8596 const { item, afterOperation } = await createSingle ( createInput , list , context )
8697
98+ // after operation
8799 await afterOperation ( item )
88100
89101 return item
@@ -100,8 +112,12 @@ export async function createMany (
100112 // throw for each attempt
101113 if ( ! operationAccess ) throw accessDeniedError ( cannotForItem ( 'create' , list ) )
102114
115+ // operation
103116 const { item, afterOperation } = await createSingle ( { data } , list , context )
117+
118+ // after operation
104119 await afterOperation ( item )
120+
105121 return item
106122 } )
107123}
@@ -137,13 +153,15 @@ async function updateSingle (
137153 item
138154 )
139155
156+ // operation
140157 const updatedItem = await context . prisma [ list . listKey ] . update ( {
141158 where : { id : item . id } ,
142159 data,
143160 } )
144161
145162 // after operation
146163 await afterOperation ( updatedItem )
164+
147165 return updatedItem
148166}
149167
@@ -390,8 +408,7 @@ function transformInnerDBField (
390408 value : unknown
391409) {
392410 if ( dbField . kind === 'scalar' && dbField . scalar === 'Json' && value === null ) {
393- const Prisma = getPrismaNamespace ( context )
394- return Prisma . DbNull
411+ return context . __internal . prisma . DbNull
395412 }
396413 return value
397414}
@@ -402,18 +419,25 @@ function transformForPrismaClient (
402419 context : KeystoneContext
403420) {
404421 return Object . fromEntries (
405- Object . entries ( data ) . flatMap ( ( [ fieldKey , value ] ) => {
406- const { dbField } = fields [ fieldKey ]
407- if ( dbField . kind === 'multi' ) {
408- return Object . entries ( value ) . map ( ( [ innerFieldKey , fieldValue ] ) => {
409- return [
410- getDBFieldKeyForFieldOnMultiField ( fieldKey , innerFieldKey ) ,
411- transformInnerDBField ( dbField . fields [ innerFieldKey ] , context , fieldValue ) ,
412- ]
413- } )
414- }
422+ [ ...function * ( ) {
423+ for ( const fieldKey in data ) {
424+ const value = data [ fieldKey ]
425+ const { dbField } = fields [ fieldKey ]
426+
427+ if ( dbField . kind === 'multi' ) {
428+ for ( const innerFieldKey in value ) {
429+ const innerFieldValue = value [ innerFieldKey ]
430+ yield [
431+ getDBFieldKeyForFieldOnMultiField ( fieldKey , innerFieldKey ) ,
432+ transformInnerDBField ( dbField . fields [ innerFieldKey ] , context , innerFieldValue ) ,
433+ ]
434+ }
435+
436+ continue
437+ }
415438
416- return [ [ fieldKey , transformInnerDBField ( dbField , context , value ) ] ]
417- } )
439+ yield [ fieldKey , transformInnerDBField ( dbField , context , value ) ]
440+ }
441+ } ( ) ]
418442 )
419443}
0 commit comments