Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/tired-tires-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@keystone-6/core": major
"@keystone-6/fields-document": patch
"@keystone-6/cloudinary": patch
---

Removes `jsonFieldTypePolyfilledForSQLite` since Prisma now supports the Json scalar for SQLite
8 changes: 4 additions & 4 deletions examples/cloudinary/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ generator client {
}

model Post {
id String @id @default(cuid())
title String @default("")
content String @default("")
banner String?
id String @id @default(cuid())
title String @default("")
content String @default("")
banner Json?
}
3 changes: 3 additions & 0 deletions examples/default-values/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type Task {
label: String
priority: TaskPriorityType
isComplete: Boolean
additionalData: JSON
assignedTo: Person
finishBy: DateTime
viewCount: BigInt
Expand Down Expand Up @@ -129,6 +130,7 @@ input TaskUpdateInput {
label: String
priority: TaskPriorityType
isComplete: Boolean
additionalData: JSON
assignedTo: PersonRelateToOneForUpdateInput
finishBy: DateTime
viewCount: BigInt
Expand All @@ -149,6 +151,7 @@ input TaskCreateInput {
label: String
priority: TaskPriorityType
isComplete: Boolean
additionalData: JSON
assignedTo: PersonRelateToOneForCreateInput
finishBy: DateTime
viewCount: BigInt
Expand Down
17 changes: 9 additions & 8 deletions examples/default-values/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ generator client {
}

model Task {
id String @id @default(cuid())
label String @default("")
priority String?
isComplete Boolean @default(false)
assignedTo Person? @relation("Task_assignedTo", fields: [assignedToId], references: [id])
assignedToId String? @map("assignedTo")
finishBy DateTime?
viewCount BigInt? @default(0)
id String @id @default(cuid())
label String @default("")
priority String?
isComplete Boolean @default(false)
additionalData Json?
assignedTo Person? @relation("Task_assignedTo", fields: [assignedToId], references: [id])
assignedToId String? @map("assignedTo")
finishBy DateTime?
viewCount BigInt? @default(0)

@@index([assignedToId])
}
Expand Down
22 changes: 19 additions & 3 deletions examples/default-values/schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import type { Lists } from '.keystone/types'
import { list } from '@keystone-6/core'
import { bigInt, checkbox, relationship, text, timestamp } from '@keystone-6/core/fields'
import { select } from '@keystone-6/core/fields'
import { allowAll } from '@keystone-6/core/access'
import type { Lists } from '.keystone/types'
import {
bigInt,
checkbox,
json,
relationship,
select,
text,
timestamp,
} from '@keystone-6/core/fields'

export const lists = {
Task: list({
Expand Down Expand Up @@ -34,6 +41,15 @@ export const lists = {
// static default: when a task is first created, it is incomplete
isComplete: checkbox({ defaultValue: false }),

// static default: may stringify in Prisma schema
additionalData: json({
defaultValue: {
conditions: [],
location: null,
notification: 'bongo',
},
}),

assignedTo: relationship({
ref: 'Person.tasks',
many: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ model Post {
id String @id @default(cuid())
title String @default("")
slug String @unique @default("")
content String @default("[{\"type\":\"paragraph\",\"children\":[{\"text\":\"\"}]}]")
content Json
publishDate DateTime? @default(now())
author User? @relation("Post_author", fields: [authorId], references: [id])
authorId String? @map("author")
Expand Down
4 changes: 2 additions & 2 deletions examples/document-field/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ model Post {
title String @default("")
slug String @unique @default("")
status String?
content String @default("[{\"type\":\"paragraph\",\"children\":[{\"text\":\"\"}]}]")
content Json
publishDate DateTime?
author Author? @relation("Post_author", fields: [authorId], references: [id])
authorId String? @map("author")
Expand All @@ -30,5 +30,5 @@ model Author {
name String @default("")
email String @unique @default("")
posts Post[] @relation("Post_author")
bio String @default("[{\"type\":\"paragraph\",\"children\":[{\"text\":\"\"}]}]")
bio Json
}
2 changes: 1 addition & 1 deletion examples/framework-nextjs-app-directory/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ generator client {
model User {
id String @id @default(cuid())
name String @default("")
about String @default("[{\"type\":\"paragraph\",\"children\":[{\"text\":\"\"}]}]")
about Json
createdAt DateTime? @default(now())
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ model Post {
id String @id @default(cuid())
title String @default("")
slug String @unique @default("")
content String @default("[{\"type\":\"paragraph\",\"children\":[{\"text\":\"\"}]}]")
content Json
publishDate DateTime? @default(now())
author User? @relation("Post_author", fields: [authorId], references: [id])
authorId String? @map("author")
Expand Down
4 changes: 2 additions & 2 deletions examples/relationships/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ model Post {
categoryId String? @map("category")
tags Tag[] @relation("Post_tags")
related Post[] @relation("Post_related")
recommendations String @default("[]")
bundles String @default("[]")
recommendations Json
bundles Json
from_Post_related Post[] @relation("Post_related")

@@index([categoryId])
Expand Down
4 changes: 2 additions & 2 deletions examples/structure-field/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ generator client {
}

model Homepage {
id Int @id
metadata String @default("{\"featuredPosts\":[]}")
id Int @id
metadata Json
}

model Post {
Expand Down
2 changes: 1 addition & 1 deletion examples/usecase-blog/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ model Author {
model Post {
id String @id @default(cuid())
title String @default("")
content String @default("[{\"type\":\"paragraph\",\"children\":[{\"text\":\"\"}]}]")
content Json
author Author? @relation("Post_author", fields: [authorId], references: [id])
authorId String? @map("author")
tags Tag[] @relation("Post_tags")
Expand Down
124 changes: 62 additions & 62 deletions packages/cloudinary/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { randomBytes } from 'node:crypto'
import { g } from '@keystone-6/core'
import type { GArg, InferValueFromArg } from '@keystone-6/core/graphql-ts'
import type {
CommonFieldConfig,
BaseFieldTypeInfo,
BaseListTypeInfo,
CommonFieldConfig,
FieldTypeFunc,
BaseFieldTypeInfo,
} from '@keystone-6/core/types'
import { jsonFieldTypePolyfilledForSQLite } from '@keystone-6/core/types'
import { g } from '@keystone-6/core'
import { fieldType } from '@keystone-6/core/types'

import type Cloudinary from 'cloudinary'
import { v2 as cloudinary } from 'cloudinary'
import type { GArg, InferValueFromArg } from '@keystone-6/core/graphql-ts'
import { randomBytes } from 'node:crypto'

type StoredFile = {
id: string
Expand Down Expand Up @@ -167,62 +168,61 @@ export function cloudinaryImage<ListTypeInfo extends BaseListTypeInfo>({
}
}

return jsonFieldTypePolyfilledForSQLite(
meta.provider,
{
...config,
__ksTelemetryFieldTypeName: '@keystone-6/cloudinary',
input: {
create: { arg: inputArg, resolve: resolveInput },
update: { arg: inputArg, resolve: resolveInput },
},
output: g.field({
type: outputType,
resolve({ value }) {
if (value === null) return null
const val = value as any
return {
width: val?._meta.width,
height: val?._meta.width,
filesize: val?._meta.bytes,
publicUrl: val?._meta?.secure_url ?? null,
publicUrlTransformed: ({
transformation,
}: {
transformation: InferValueFromArg<GArg<typeof CloudinaryImageFormat>>
}) => {
if (!val._meta) return null

const { prettyName, ...rest } = transformation ?? {}

// no formatting options provided, return the publicUrl field
if (!Object.keys(rest).length) return val?._meta?.secure_url ?? null

const { public_id, format } = val._meta

// ref https://github.com/cloudinary/cloudinary_npm/blob/439586eac73cee7f2803cf19f885e98f237183b3/src/utils.coffee#L472
return cloudinary.url(public_id, {
type: 'upload',
format,
secure: true, // the default as of version 2
url_suffix: prettyName,
transformation,
cloud_name: cloudinaryConfig.cloudName,

// SDK analytics defaults to true in version 2 (ref https://github.com/cloudinary/cloudinary_npm/commit/d2510eb677e553a45bc7e363b35d2c20b4c4b144#diff-9aa82f0ed674e050695a7422b1cd56d43ce47e6953688a16a003bf49c3481622)
// we default to false for the least surprise, keeping this upgrade as a patch
urlAnalytics: false,
})
},
...val,
}
},
}),
views: '@keystone-6/cloudinary/views',
return fieldType({
kind: 'scalar',
mode: 'optional',
scalar: 'Json',
map: config.db?.map,
})({
...config,
__ksTelemetryFieldTypeName: '@keystone-6/cloudinary',
input: {
create: { arg: inputArg, resolve: resolveInput },
update: { arg: inputArg, resolve: resolveInput },
},
{
map: config.db?.map,
}
)
output: g.field({
type: outputType,
resolve({ value }) {
if (value === null) return null
const val = value as any
return {
width: val?._meta.width,
height: val?._meta.width,
filesize: val?._meta.bytes,
publicUrl: val?._meta?.secure_url ?? null,
publicUrlTransformed: ({
transformation,
}: {
transformation: InferValueFromArg<GArg<typeof CloudinaryImageFormat>>
}) => {
if (!val._meta) return null

const { prettyName, ...rest } = transformation ?? {}

// no formatting options provided, return the publicUrl field
if (!Object.keys(rest).length) return val?._meta?.secure_url ?? null

const { public_id, format } = val._meta

// ref https://github.com/cloudinary/cloudinary_npm/blob/439586eac73cee7f2803cf19f885e98f237183b3/src/utils.coffee#L472
return cloudinary.url(public_id, {
type: 'upload',
format,
secure: true, // the default as of version 2
url_suffix: prettyName,
transformation,
cloud_name: cloudinaryConfig.cloudName,

// SDK analytics defaults to true in version 2 (ref https://github.com/cloudinary/cloudinary_npm/commit/d2510eb677e553a45bc7e363b35d2c20b4c4b144#diff-9aa82f0ed674e050695a7422b1cd56d43ce47e6953688a16a003bf49c3481622)
// we default to false for the least surprise, keeping this upgrade as a patch
urlAnalytics: false,
})
},
...val,
}
},
}),
views: '@keystone-6/cloudinary/views',
})
}
}
Loading