-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move utils package into main package (#6368)
- Loading branch information
Showing
15 changed files
with
73 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@keystone-next/keystone': minor | ||
'@keystone-next/utils': major | ||
--- | ||
|
||
Moved `@keystone-next/utils` to `@keystone-next/keystone/fields/types/image/utils` for image ref related utilities and `@keystone-next/keystone/fields/types/file/utils` for file ref related utilities. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"main": "dist/keystone.cjs.js", | ||
"module": "dist/keystone.esm.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"main": "dist/keystone.cjs.js", | ||
"module": "dist/keystone.esm.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { AssetMode } from '@keystone-next/types'; | ||
|
||
const FILEREGEX = /^(local|keystone-cloud):file:([^\\\/:\n]+)/; | ||
|
||
export const getFileRef = (mode: AssetMode, name: string) => `${mode}:file:${name}`; | ||
export const parseFileRef = (ref: string) => { | ||
const match = ref.match(FILEREGEX); | ||
if (match) { | ||
const [, mode, filename] = match; | ||
return { | ||
mode: mode as AssetMode, | ||
filename: filename as string, | ||
}; | ||
} | ||
return undefined; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { AssetMode, ImageExtension } from '@keystone-next/types'; | ||
|
||
const IMAGEREGEX = /^(local|keystone-cloud):image:([^\\\/:\n]+)\.(gif|jpg|png|webp)$/; | ||
|
||
export const getImageRef = (mode: AssetMode, id: string, extension: ImageExtension) => | ||
`${mode}:image:${id}.${extension}`; | ||
|
||
export const SUPPORTED_IMAGE_EXTENSIONS = ['jpg', 'png', 'webp', 'gif']; | ||
|
||
export const parseImageRef = ( | ||
ref: string | ||
): { mode: AssetMode; id: string; extension: ImageExtension } | undefined => { | ||
const match = ref.match(IMAGEREGEX); | ||
if (match) { | ||
const [, mode, id, ext] = match; | ||
return { | ||
mode: mode as AssetMode, | ||
id, | ||
extension: ext as ImageExtension, | ||
}; | ||
} | ||
return undefined; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,5 @@ | ||
import { AssetMode, ImageExtension } from '@keystone-next/types'; | ||
throw new Error( | ||
'`@keystone-next/utils` has been moved to `@keystone-next/keystone/fields/types/image/utils` for image ref related utilities and `@keystone-next/keystone/fields/types/file/utils` for file ref related utilities, please import from there instead.' | ||
); | ||
|
||
const IMAGEREGEX = /^(local|keystone-cloud):image:([^\\\/:\n]+)\.(gif|jpg|png|webp)$/; | ||
const FILEREGEX = /^(local|keystone-cloud):file:([^\\\/:\n]+)/; | ||
|
||
export const getImageRef = (mode: AssetMode, id: string, extension: ImageExtension) => | ||
`${mode}:image:${id}.${extension}`; | ||
|
||
export const getFileRef = (mode: AssetMode, name: string) => `${mode}:file:${name}`; | ||
export const parseFileRef = (ref: string) => { | ||
const match = ref.match(FILEREGEX); | ||
if (match) { | ||
const [, mode, filename] = match; | ||
return { | ||
mode: mode as AssetMode, | ||
filename: filename as string, | ||
}; | ||
} | ||
return undefined; | ||
}; | ||
|
||
export const SUPPORTED_IMAGE_EXTENSIONS = ['jpg', 'png', 'webp', 'gif']; | ||
|
||
export const parseImageRef = ( | ||
ref: string | ||
): { mode: AssetMode; id: string; extension: ImageExtension } | undefined => { | ||
const match = ref.match(IMAGEREGEX); | ||
if (match) { | ||
const [, mode, id, ext] = match; | ||
return { | ||
mode: mode as AssetMode, | ||
id, | ||
extension: ext as ImageExtension, | ||
}; | ||
} | ||
return undefined; | ||
}; | ||
|
||
export const isLocalAsset = (mode: AssetMode) => mode === 'local'; | ||
|
||
export const isKeystoneCloudAsset = (mode: AssetMode) => mode === 'keystone-cloud'; | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters