Skip to content

Commit 1425c9c

Browse files
committed
Remove jsonFieldTypePolyfilledForSQLite since Prisma now supports the Json scalar for SQLite
1 parent d4e5787 commit 1425c9c

File tree

8 files changed

+261
-431
lines changed

8 files changed

+261
-431
lines changed

.changeset/tired-tires-look.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@keystone-6/core": major
3+
"@keystone-6/fields-document": patch
4+
"@keystone-6/cloudinary": patch
5+
---
6+
7+
Removes `jsonFieldTypePolyfilledForSQLite` since Prisma now supports the Json scalar for SQLite

packages/cloudinary/src/index.ts

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { randomBytes } from 'node:crypto'
22
import type { CommonFieldConfig, BaseListTypeInfo, FieldTypeFunc } from '@keystone-6/core/types'
3-
import { jsonFieldTypePolyfilledForSQLite } from '@keystone-6/core/types'
3+
import { fieldType } from '@keystone-6/core/types'
44
import { g } from '@keystone-6/core'
55
import type Cloudinary from 'cloudinary'
66
import { v2 as cloudinary } from 'cloudinary'
@@ -160,62 +160,61 @@ export function cloudinaryImage<ListTypeInfo extends BaseListTypeInfo>({
160160
}
161161
}
162162

163-
return jsonFieldTypePolyfilledForSQLite(
164-
meta.provider,
165-
{
166-
...config,
167-
__ksTelemetryFieldTypeName: '@keystone-6/cloudinary',
168-
input: {
169-
create: { arg: inputArg, resolve: resolveInput },
170-
update: { arg: inputArg, resolve: resolveInput },
171-
},
172-
output: g.field({
173-
type: outputType,
174-
resolve({ value }) {
175-
if (value === null) return null
176-
const val = value as any
177-
return {
178-
width: val?._meta.width,
179-
height: val?._meta.width,
180-
filesize: val?._meta.bytes,
181-
publicUrl: val?._meta?.secure_url ?? null,
182-
publicUrlTransformed: ({
183-
transformation,
184-
}: {
185-
transformation: InferValueFromArg<GArg<typeof CloudinaryImageFormat>>
186-
}) => {
187-
if (!val._meta) return null
188-
189-
const { prettyName, ...rest } = transformation ?? {}
190-
191-
// no formatting options provided, return the publicUrl field
192-
if (!Object.keys(rest).length) return val?._meta?.secure_url ?? null
193-
194-
const { public_id, format } = val._meta
195-
196-
// ref https://github.com/cloudinary/cloudinary_npm/blob/439586eac73cee7f2803cf19f885e98f237183b3/src/utils.coffee#L472
197-
return cloudinary.url(public_id, {
198-
type: 'upload',
199-
format,
200-
secure: true, // the default as of version 2
201-
url_suffix: prettyName,
202-
transformation,
203-
cloud_name: cloudinaryConfig.cloudName,
204-
205-
// SDK analytics defaults to true in version 2 (ref https://github.com/cloudinary/cloudinary_npm/commit/d2510eb677e553a45bc7e363b35d2c20b4c4b144#diff-9aa82f0ed674e050695a7422b1cd56d43ce47e6953688a16a003bf49c3481622)
206-
// we default to false for the least surprise, keeping this upgrade as a patch
207-
urlAnalytics: false,
208-
})
209-
},
210-
...val,
211-
}
212-
},
213-
}),
214-
views: '@keystone-6/cloudinary/views',
163+
return fieldType({
164+
kind: 'scalar',
165+
mode: 'optional',
166+
scalar: 'Json',
167+
map: config.db?.map,
168+
})({
169+
...config,
170+
__ksTelemetryFieldTypeName: '@keystone-6/cloudinary',
171+
input: {
172+
create: { arg: inputArg, resolve: resolveInput },
173+
update: { arg: inputArg, resolve: resolveInput },
215174
},
216-
{
217-
map: config.db?.map,
218-
}
219-
)
175+
output: g.field({
176+
type: outputType,
177+
resolve({ value }) {
178+
if (value === null) return null
179+
const val = value as any
180+
return {
181+
width: val?._meta.width,
182+
height: val?._meta.width,
183+
filesize: val?._meta.bytes,
184+
publicUrl: val?._meta?.secure_url ?? null,
185+
publicUrlTransformed: ({
186+
transformation,
187+
}: {
188+
transformation: InferValueFromArg<GArg<typeof CloudinaryImageFormat>>
189+
}) => {
190+
if (!val._meta) return null
191+
192+
const { prettyName, ...rest } = transformation ?? {}
193+
194+
// no formatting options provided, return the publicUrl field
195+
if (!Object.keys(rest).length) return val?._meta?.secure_url ?? null
196+
197+
const { public_id, format } = val._meta
198+
199+
// ref https://github.com/cloudinary/cloudinary_npm/blob/439586eac73cee7f2803cf19f885e98f237183b3/src/utils.coffee#L472
200+
return cloudinary.url(public_id, {
201+
type: 'upload',
202+
format,
203+
secure: true, // the default as of version 2
204+
url_suffix: prettyName,
205+
transformation,
206+
cloud_name: cloudinaryConfig.cloudName,
207+
208+
// SDK analytics defaults to true in version 2 (ref https://github.com/cloudinary/cloudinary_npm/commit/d2510eb677e553a45bc7e363b35d2c20b4c4b144#diff-9aa82f0ed674e050695a7422b1cd56d43ce47e6953688a16a003bf49c3481622)
209+
// we default to false for the least surprise, keeping this upgrade as a patch
210+
urlAnalytics: false,
211+
})
212+
},
213+
...val,
214+
}
215+
},
216+
}),
217+
views: '@keystone-6/cloudinary/views',
218+
})
220219
}
221220
}

packages/core/src/fields/types/json/index.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
type JSONValue,
44
type FieldTypeFunc,
55
type CommonFieldConfig,
6-
jsonFieldTypePolyfilledForSQLite,
6+
fieldType,
77
} from '../../../types'
88
import { g } from '../../..'
99

@@ -23,31 +23,30 @@ export const json =
2323
throw Error("isIndexed: 'unique' is not a supported option for field type json")
2424
}
2525

26-
return jsonFieldTypePolyfilledForSQLite(
27-
meta.provider,
28-
{
29-
...config,
30-
__ksTelemetryFieldTypeName: '@keystone-6/json',
31-
input: {
32-
create: {
33-
arg: g.arg({ type: g.JSON }),
34-
resolve(val) {
35-
return val === undefined ? defaultValue : val
36-
},
26+
return fieldType({
27+
kind: 'scalar',
28+
mode: 'optional',
29+
scalar: 'Json',
30+
default:
31+
defaultValue === null
32+
? undefined
33+
: { kind: 'literal', value: JSON.stringify(defaultValue) },
34+
map: config.db?.map,
35+
extendPrismaSchema: config.db?.extendPrismaSchema,
36+
})({
37+
...config,
38+
__ksTelemetryFieldTypeName: '@keystone-6/json',
39+
input: {
40+
create: {
41+
arg: g.arg({ type: g.JSON }),
42+
resolve(val) {
43+
return val === undefined ? defaultValue : val
3744
},
38-
update: { arg: g.arg({ type: g.JSON }) },
3945
},
40-
output: g.field({ type: g.JSON }),
41-
views: '@keystone-6/core/fields/types/json/views',
42-
getAdminMeta: () => ({ defaultValue }),
46+
update: { arg: g.arg({ type: g.JSON }) },
4347
},
44-
{
45-
default:
46-
defaultValue === null
47-
? undefined
48-
: { kind: 'literal', value: JSON.stringify(defaultValue) },
49-
map: config.db?.map,
50-
extendPrismaSchema: config.db?.extendPrismaSchema,
51-
}
52-
)
48+
output: g.field({ type: g.JSON }),
49+
views: '@keystone-6/core/fields/types/json/views',
50+
getAdminMeta: () => ({ defaultValue }),
51+
})
5352
}

packages/core/src/fields/types/multiselect/index.ts

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
type FieldTypeFunc,
66
type CommonFieldConfig,
77
type FieldData,
8-
jsonFieldTypePolyfilledForSQLite,
8+
fieldType,
99
} from '../../../types'
1010
import { g } from '../../..'
1111
import { makeValidateHook } from '../../non-null-graphql'
@@ -102,44 +102,42 @@ export function multiselect<ListTypeInfo extends BaseListTypeInfo>(
102102
}
103103
)
104104

105-
return jsonFieldTypePolyfilledForSQLite(
106-
meta.provider,
107-
{
108-
...config,
109-
ui,
110-
__ksTelemetryFieldTypeName: '@keystone-6/multiselect',
111-
hooks: {
112-
...config.hooks,
113-
validate,
114-
},
115-
views: '@keystone-6/core/fields/types/multiselect/views',
116-
getAdminMeta: () => ({
117-
options: transformedConfig.options,
118-
type: config.type ?? 'string',
119-
displayMode: displayMode,
120-
defaultValue: [],
121-
}),
122-
input: {
123-
create: { arg: g.arg({ type }), resolve: resolveCreate },
124-
update: { arg: g.arg({ type }), resolve: resolveUpdate },
125-
},
126-
output: g.field({
127-
type: type,
128-
resolve({ value }) {
129-
return value as any
130-
},
131-
}),
105+
return fieldType({
106+
kind: 'scalar',
107+
scalar: 'Json',
108+
mode,
109+
map: config?.db?.map,
110+
extendPrismaSchema: config.db?.extendPrismaSchema,
111+
default: {
112+
kind: 'literal',
113+
value: JSON.stringify(defaultValue ?? null),
114+
},
115+
})({
116+
...config,
117+
ui,
118+
__ksTelemetryFieldTypeName: '@keystone-6/multiselect',
119+
hooks: {
120+
...config.hooks,
121+
validate,
122+
},
123+
views: '@keystone-6/core/fields/types/multiselect/views',
124+
getAdminMeta: () => ({
125+
options: transformedConfig.options,
126+
type: config.type ?? 'string',
127+
displayMode: displayMode,
128+
defaultValue: [],
129+
}),
130+
input: {
131+
create: { arg: g.arg({ type }), resolve: resolveCreate },
132+
update: { arg: g.arg({ type }), resolve: resolveUpdate },
132133
},
133-
{
134-
mode,
135-
map: config?.db?.map,
136-
extendPrismaSchema: config.db?.extendPrismaSchema,
137-
default: {
138-
kind: 'literal',
139-
value: JSON.stringify(defaultValue ?? null),
134+
output: g.field({
135+
type: type,
136+
resolve({ value }) {
137+
return value as any
140138
},
141-
}
142-
)
139+
}),
140+
})
143141
}
144142
}
145143

packages/core/src/types/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ export * from './session'
55
export * from './admin-meta'
66
export * from './context'
77
export * from './next-fields'
8-
export { jsonFieldTypePolyfilledForSQLite } from './json-field-type-polyfill-for-sqlite'
98
export * from './type-info'

0 commit comments

Comments
 (0)