@stackbit/types
Advanced tools
Comparing version 0.1.11-gitcms.0 to 0.1.11-gitcms.1
@@ -186,2 +186,3 @@ import type { ContentSourceInterface } from './content-source'; | ||
passthrough?: string[]; | ||
directRoutes?: Record<string, string>; | ||
watch?: { | ||
@@ -188,0 +189,0 @@ reinstallPackages?: string[]; |
@@ -0,1 +1,2 @@ | ||
import type { FieldType } from './model-fields'; | ||
/** | ||
@@ -13,2 +14,5 @@ * Front-end frameworks supported by Stackbit without any additional | ||
export declare const CMS_NAMES: readonly ["git", "contentful", "sanity", "forestry", "netlifycms"]; | ||
export declare const FIELD_TYPE: { | ||
[Type in FieldType as Type extends 'cross-reference' ? 'crossReference' : Type]: Type; | ||
}; | ||
export declare const FIELD_TYPES: readonly ["string", "url", "slug", "text", "markdown", "html", "number", "boolean", "enum", "date", "datetime", "color", "image", "file", "json", "richText", "object", "model", "reference", "cross-reference", "style", "list"]; | ||
@@ -15,0 +19,0 @@ export declare const STYLE_PROPS: readonly ["objectFit", "objectPosition", "flexDirection", "justifyContent", "justifyItems", "justifySelf", "alignContent", "alignItems", "alignSelf", "padding", "margin", "width", "height", "fontFamily", "fontSize", "fontStyle", "fontWeight", "textAlign", "textColor", "textDecoration", "backgroundColor", "backgroundPosition", "backgroundSize", "borderRadius", "borderWidth", "borderColor", "borderStyle", "boxShadow", "opacity"]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RICH_TEXT_HINT_MAX_LENGTH = exports.RICH_TEXT_MARK_TYPES = exports.RICH_TEXT_NODE_TYPES = exports.STYLE_PROPS_VALUES = exports.STYLE_PROPS = exports.FIELD_TYPES = exports.CMS_NAMES = exports.SSG_NAMES = void 0; | ||
exports.RICH_TEXT_HINT_MAX_LENGTH = exports.RICH_TEXT_MARK_TYPES = exports.RICH_TEXT_NODE_TYPES = exports.STYLE_PROPS_VALUES = exports.STYLE_PROPS = exports.FIELD_TYPES = exports.FIELD_TYPE = exports.CMS_NAMES = exports.SSG_NAMES = void 0; | ||
/** | ||
@@ -29,2 +29,26 @@ * Front-end frameworks supported by Stackbit without any additional | ||
exports.CMS_NAMES = ['git', 'contentful', 'sanity', 'forestry', 'netlifycms']; | ||
exports.FIELD_TYPE = { | ||
string: 'string', | ||
url: 'url', | ||
slug: 'slug', | ||
text: 'text', | ||
markdown: 'markdown', | ||
html: 'html', | ||
number: 'number', | ||
boolean: 'boolean', | ||
enum: 'enum', | ||
date: 'date', | ||
datetime: 'datetime', | ||
color: 'color', | ||
image: 'image', | ||
file: 'file', | ||
json: 'json', | ||
richText: 'richText', | ||
object: 'object', | ||
model: 'model', | ||
reference: 'reference', | ||
crossReference: 'cross-reference', | ||
style: 'style', | ||
list: 'list' | ||
}; | ||
exports.FIELD_TYPES = [ | ||
@@ -31,0 +55,0 @@ 'string', |
@@ -1,3 +0,4 @@ | ||
import type { FieldType } from './model-fields'; | ||
import type { Simplify } from './utils'; | ||
import { DocumentField, DocumentStringLikeFieldForType } from './content-source-document-fields'; | ||
export declare type TypeDocument = 'document'; | ||
export declare type DocumentStatus = 'added' | 'modified' | 'published' | 'deleted'; | ||
export interface Document<DocumentContext = unknown> { | ||
@@ -21,2 +22,3 @@ type: TypeDocument; | ||
}; | ||
export declare type TypeAsset = 'asset'; | ||
export interface Asset<AssetContext = unknown> { | ||
@@ -35,140 +37,23 @@ type: TypeAsset; | ||
} | ||
export declare type TypeDocument = 'document'; | ||
export declare type TypeAsset = 'asset'; | ||
export declare type DocumentStatus = 'added' | 'modified' | 'published' | 'deleted'; | ||
export declare type AssetFields = { | ||
title: DocumentValueFieldForType<'string'>; | ||
title: DocumentStringLikeFieldForType<'string'>; | ||
file: AssetFileField; | ||
}; | ||
export declare type DocumentField = DocumentValueField | DocumentObjectField | DocumentModelField | DocumentReferenceField | DocumentListField | DocumentRichTextField | DocumentImageField; | ||
export declare type DocumentFieldLocalized = DocumentValueFieldLocalized | DocumentObjectFieldLocalized | DocumentModelFieldLocalized | DocumentReferenceFieldLocalized | DocumentListFieldLocalized | DocumentRichTextFieldLocalized | DocumentImageFieldLocalized; | ||
export declare type DocumentFieldNonLocalized = DocumentValueFieldNonLocalized | DocumentObjectFieldNonLocalized | DocumentModelFieldNonLocalized | DocumentReferenceFieldNonLocalized | DocumentListFieldNonLocalized | DocumentRichTextFieldNonLocalized | DocumentImageFieldNonLocalized; | ||
export declare type DocumentFieldBaseProps = DocumentValueFieldBaseProps | DocumentObjectFieldBase | DocumentModelFieldBase | DocumentReferenceFieldBase | DocumentListFieldBase | DocumentRichTextFieldBase | DocumentImageFieldBase; | ||
export declare type DocumentFieldSpecificProps = DocumentValueFieldProps | DocumentObjectFieldProps | DocumentModelFieldProps | DocumentReferenceFieldProps | DocumentListFieldProps | DocumentRichTextFieldProps | DocumentImageFieldProps; | ||
declare type FindByType<Union extends { | ||
type: FieldType; | ||
}, Type extends FieldType> = Union extends { | ||
type: Type; | ||
} ? Union : never; | ||
export declare type DocumentFieldForType<Type extends FieldType> = FindByType<DocumentField, Type>; | ||
export declare type DocumentFieldLocalizedForType<Type extends FieldType> = FindByType<DocumentFieldLocalized, Type>; | ||
export declare type DocumentFieldNonLocalizedForType<Type extends FieldType> = FindByType<DocumentFieldNonLocalized, Type>; | ||
export declare type DocumentFieldBasePropsForType<Type extends FieldType> = FindByType<DocumentFieldBaseProps, Type>; | ||
export declare type DocumentFieldSpecificPropsForType<Type extends FieldType> = Simplify<Omit<DocumentFieldNonLocalizedForType<Type>, keyof DocumentFieldBasePropsForType<Type> | 'locale' | 'localized'>>; | ||
export declare type DocumentFieldTypeLocalized<BaseFieldProps, LocalizedFieldProps> = Simplify<BaseFieldProps & { | ||
localized: true; | ||
locales: Record<string, { | ||
locale: string; | ||
} & LocalizedFieldProps>; | ||
}>; | ||
export declare type DocumentFieldTypeNonLocalized<BaseFieldProps, LocalizedFieldProps> = Simplify<BaseFieldProps & LocalizedFieldProps & { | ||
localized?: false; | ||
}>; | ||
export declare type DocumentValueFieldType = Exclude<FieldType, 'object' | 'model' | 'reference' | 'richText' | 'list' | 'image'>; | ||
/** | ||
* Document field with any type except 'object' | 'model' | 'reference' | 'richText' | 'list' | ||
*/ | ||
export declare type DocumentValueField = DocumentValueFieldForType<DocumentValueFieldType>; | ||
export declare type DocumentValueFieldForType<Type> = Type extends DocumentValueFieldType ? DocumentValueFieldLocalizedForType<Type> | DocumentValueFieldNonLocalizedForType<Type> : never; | ||
export declare type DocumentValueFieldLocalized = DocumentValueFieldLocalizedForType<DocumentValueFieldType>; | ||
export declare type DocumentValueFieldLocalizedForType<Type> = Type extends DocumentValueFieldType ? DocumentFieldTypeLocalized<DocumentValueFieldBase<Type>, DocumentValueFieldProps> : never; | ||
export declare type DocumentValueFieldNonLocalized = DocumentValueFieldNonLocalizedForType<DocumentValueFieldType>; | ||
export declare type DocumentValueFieldNonLocalizedForType<Type> = Type extends DocumentValueFieldType ? DocumentFieldTypeNonLocalized<DocumentValueFieldBase<Type>, DocumentValueFieldProps> : never; | ||
export declare type DocumentValueFieldBaseProps = DocumentValueFieldBasePropsForType<DocumentValueFieldType>; | ||
export declare type DocumentValueFieldBasePropsForType<Type> = Type extends DocumentValueFieldType ? DocumentValueFieldBase<Type> : never; | ||
export declare type DocumentValueFieldBase<Type extends DocumentValueFieldType> = { | ||
type: Type; | ||
}; | ||
export declare type DocumentValueFieldProps = { | ||
value: any; | ||
}; | ||
/** | ||
* Document "object" field | ||
*/ | ||
export declare type DocumentObjectField = DocumentObjectFieldLocalized | DocumentObjectFieldNonLocalized; | ||
export declare type DocumentObjectFieldLocalized = DocumentFieldTypeLocalized<DocumentObjectFieldBase, DocumentObjectFieldProps>; | ||
export declare type DocumentObjectFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentObjectFieldBase, DocumentObjectFieldProps>; | ||
export declare type DocumentObjectFieldBase = { | ||
type: 'object'; | ||
}; | ||
export declare type DocumentObjectFieldProps = { | ||
fields: Record<string, DocumentField>; | ||
}; | ||
/** | ||
* Document "model" field | ||
*/ | ||
export declare type DocumentModelField = DocumentModelFieldLocalized | DocumentModelFieldNonLocalized; | ||
export declare type DocumentModelFieldLocalized = DocumentFieldTypeLocalized<DocumentModelFieldBase, DocumentModelFieldProps>; | ||
export declare type DocumentModelFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentModelFieldBase, DocumentModelFieldProps>; | ||
export declare type DocumentModelFieldBase = { | ||
type: 'model'; | ||
}; | ||
export declare type DocumentModelFieldProps = { | ||
modelName: string; | ||
fields: Record<string, DocumentField>; | ||
}; | ||
/** | ||
* Document "reference" field | ||
*/ | ||
export declare type DocumentReferenceField = DocumentReferenceFieldLocalized | DocumentReferenceFieldNonLocalized; | ||
export declare type DocumentReferenceFieldLocalized = DocumentFieldTypeLocalized<DocumentReferenceFieldBase, DocumentReferenceFieldProps>; | ||
export declare type DocumentReferenceFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentReferenceFieldBase, DocumentReferenceFieldProps>; | ||
export declare type DocumentReferenceFieldBase = { | ||
type: 'reference'; | ||
refType: 'document' | 'asset'; | ||
}; | ||
export declare type DocumentReferenceFieldProps = { | ||
refId: string; | ||
}; | ||
/** | ||
* Document "richText" field | ||
*/ | ||
export declare type DocumentRichTextField = DocumentRichTextFieldLocalized | DocumentRichTextFieldNonLocalized; | ||
export declare type DocumentRichTextFieldLocalized = DocumentFieldTypeLocalized<DocumentRichTextFieldBase, DocumentRichTextFieldProps>; | ||
export declare type DocumentRichTextFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentRichTextFieldBase, DocumentRichTextFieldProps>; | ||
export declare type DocumentRichTextFieldBase = { | ||
type: 'richText'; | ||
}; | ||
export declare type DocumentRichTextFieldProps = { | ||
hint?: string; | ||
value: any; | ||
}; | ||
/** | ||
* Document "list" field | ||
*/ | ||
export declare type DocumentListField = DocumentListFieldLocalized | DocumentListFieldNonLocalized; | ||
export declare type DocumentListFieldLocalized = DocumentFieldTypeLocalized<DocumentListFieldBase, DocumentListFieldProps>; | ||
export declare type DocumentListFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentListFieldBase, DocumentListFieldProps>; | ||
export declare type DocumentListFieldBase = { | ||
type: 'list'; | ||
}; | ||
export declare type DocumentListFieldItems = Exclude<DocumentFieldNonLocalized, DocumentListFieldNonLocalized>; | ||
export declare type DocumentListFieldProps = { | ||
items: DocumentListFieldItems[]; | ||
}; | ||
/** | ||
* Document "image" field | ||
*/ | ||
export declare type DocumentImageField = DocumentImageFieldLocalized | DocumentImageFieldNonLocalized; | ||
export declare type DocumentImageFieldLocalized = DocumentFieldTypeLocalized<DocumentImageFieldBase, DocumentImageFieldProps>; | ||
export declare type DocumentImageFieldNonLocalized = DocumentFieldTypeNonLocalized<DocumentImageFieldBase, DocumentImageFieldProps>; | ||
export declare type DocumentImageFieldBase = { | ||
type: 'image'; | ||
}; | ||
export declare type DocumentImageFieldProps = { | ||
fields: { | ||
title: DocumentValueFieldForType<'string'>; | ||
url: DocumentValueFieldForType<'string'>; | ||
}; | ||
}; | ||
/** | ||
* Asset "assetFile" field | ||
*/ | ||
export declare type AssetFileField = AssetFileFieldLocalized | AssetFileFieldNonLocalized; | ||
export declare type AssetFileFieldLocalized = DocumentFieldTypeLocalized<AssetFileFieldBase, AssetFileFieldProps>; | ||
export declare type AssetFileFieldNonLocalized = DocumentFieldTypeNonLocalized<AssetFileFieldBase, AssetFileFieldProps>; | ||
export interface AssetFileFieldNonLocalized extends AssetFileFieldBase, AssetFileFieldProps { | ||
localized?: false; | ||
} | ||
export interface AssetFileFieldLocalized extends AssetFileFieldBase { | ||
localized: true; | ||
locales: Record<string, { | ||
locale: string; | ||
} & AssetFileFieldProps>; | ||
} | ||
export declare type AssetFileFieldBase = { | ||
type: 'assetFile'; | ||
}; | ||
export declare type AssetFileFieldProps = { | ||
export interface AssetFileFieldProps { | ||
url: string; | ||
@@ -178,8 +63,7 @@ fileName?: string; | ||
size?: number; | ||
dimensions: { | ||
dimensions?: { | ||
width?: number; | ||
height?: number; | ||
}; | ||
}; | ||
export {}; | ||
} | ||
//# sourceMappingURL=content-source-document.d.ts.map |
@@ -115,6 +115,8 @@ /// <reference types="node" /> | ||
}; | ||
export interface RunServiceInterface { | ||
command: (command: string, args: string[], cwd?: string, shell?: boolean) => Promise<RunResult>; | ||
} | ||
export interface GitFileObject { | ||
export declare type CommandRunner = (command: string, args?: string[], options?: { | ||
cwd?: string; | ||
shell?: boolean; | ||
env?: NodeJS.ProcessEnv; | ||
}) => Promise<RunResult>; | ||
export interface GitFileCommitDescriptor { | ||
filePath: string; | ||
@@ -131,6 +133,9 @@ description: string; | ||
commitHash: string; | ||
changes: [DocumentStatus, string][]; | ||
changes: { | ||
status: DocumentStatus; | ||
filePath: string; | ||
}[]; | ||
} | ||
export interface GitServiceInterface { | ||
commitAndPush: (author: GitAuthor, files: GitFileObject[]) => Promise<void>; | ||
commitAndPush: (author: GitAuthor, files: GitFileCommitDescriptor[]) => Promise<void>; | ||
publish(author: GitAuthor, filePaths?: string[]): Promise<void>; | ||
@@ -140,9 +145,2 @@ commitLog(): Promise<GitCommitLogEntry[]>; | ||
} | ||
export interface ContentSourceServices { | ||
git: GitServiceInterface; | ||
run: RunServiceInterface; | ||
} | ||
export interface ContentSourceDelegate { | ||
services: ContentSourceServices; | ||
} | ||
export interface InitOptions { | ||
@@ -155,3 +153,4 @@ logger: Logger; | ||
devAppRestartNeeded?: () => void; | ||
delegate: ContentSourceDelegate; | ||
git: GitServiceInterface; | ||
runCommand: CommandRunner; | ||
} | ||
@@ -158,0 +157,0 @@ export declare type UserCommandSpawner = (options: SpawnUserCommandOptions) => ChildProcessWithoutNullStreams; |
@@ -8,2 +8,3 @@ export * from './config'; | ||
export * from './content-source-document'; | ||
export * from './content-source-document-fields'; | ||
export * from './content-source-operation'; | ||
@@ -10,0 +11,0 @@ export * from './utils'; |
@@ -24,2 +24,3 @@ "use strict"; | ||
__exportStar(require("./content-source-document"), exports); | ||
__exportStar(require("./content-source-document-fields"), exports); | ||
__exportStar(require("./content-source-operation"), exports); | ||
@@ -26,0 +27,0 @@ __exportStar(require("./utils"), exports); |
@@ -33,3 +33,3 @@ /** | ||
export declare type FieldSpecificProps = FieldBasicProps | FieldEnumProps | FieldImageProps | FieldNumberProps | FieldObjectProps | FieldModelProps | FieldReferenceProps | FieldCrossReferenceProps | FieldStyleProps | FieldListProps; | ||
declare type FindByType<Union extends { | ||
declare type ExtractByType<Union extends { | ||
type: FieldType; | ||
@@ -39,5 +39,5 @@ }, Type extends FieldType> = Union extends { | ||
} ? Union : never; | ||
export declare type FieldForType<Type extends FieldType> = FindByType<Field, Type>; | ||
export declare type FieldSpecificPropsForType<Type extends FieldType> = FindByType<FieldSpecificProps, Type>; | ||
export declare type FieldSpecificPropsForField<T extends Field> = FindByType<FieldSpecificProps, T['type']>; | ||
export declare type FieldForType<Type extends FieldType> = ExtractByType<Field, Type>; | ||
export declare type FieldSpecificPropsForType<Type extends FieldType> = ExtractByType<FieldSpecificProps, Type>; | ||
export declare type FieldSpecificPropsForField<Type extends Field> = ExtractByType<FieldSpecificProps, Type['type']>; | ||
export declare type FieldBasic = FieldCommonProps & FieldBasicProps; | ||
@@ -72,3 +72,3 @@ export declare type FieldEnum = FieldCommonProps & FieldEnumProps; | ||
} | ||
export declare type FieldEnumProps = FieldEnumDropdownProps | FieldEnumThumbnailsProps | FieldEnumPaletteProps; | ||
export declare type FieldEnumProps = FieldEnumDropdownProps | FieldEnumThumbnailsProps | FieldEnumPaletteProps | FieldEnumPaletteColorsProps; | ||
export interface FieldEnumDropdownProps { | ||
@@ -89,2 +89,7 @@ type: 'enum'; | ||
} | ||
export interface FieldEnumPaletteColorsProps { | ||
type: 'enum'; | ||
controlType: 'palette-colors'; | ||
options: FieldEnumOptionPaletteColors[]; | ||
} | ||
export declare type FieldEnumOptionValue = string | number; | ||
@@ -96,3 +101,3 @@ export interface FieldEnumOptionObject { | ||
export interface FieldEnumOptionThumbnails extends FieldEnumOptionObject { | ||
thumbnail?: string; | ||
thumbnail: string; | ||
} | ||
@@ -104,2 +109,5 @@ export interface FieldEnumOptionPalette extends FieldEnumOptionObject { | ||
} | ||
export interface FieldEnumOptionPaletteColors extends FieldEnumOptionObject { | ||
colors: string[]; | ||
} | ||
export interface FieldImageProps { | ||
@@ -106,0 +114,0 @@ type: 'image'; |
@@ -1,4 +0,5 @@ | ||
import type { FieldType } from './model-fields'; | ||
import type { FieldType, Field, FieldForType } from './model-fields'; | ||
import type { StackbitConfig } from './config'; | ||
import type { AssetFileField, AssetFileFieldLocalized, DocumentField, DocumentFieldForType, DocumentFieldLocalized, DocumentFieldNonLocalizedForType } from './content-source-document'; | ||
import type { AssetFileField, AssetFileFieldLocalized } from './content-source-document'; | ||
import type { DocumentField, DocumentFieldForType, DocumentFieldLocalized, DocumentFieldNonLocalizedForType } from './content-source-document-fields'; | ||
export declare type Simplify<T> = { | ||
@@ -45,3 +46,6 @@ [K in keyof T]: T[K]; | ||
export declare function getLocalizedFieldForLocale<Type extends FieldType>(field: DocumentFieldForType<Type>, locale?: string): DocumentFieldNonLocalizedForType<Type> | null; | ||
export declare function isOneOfFieldTypes<T extends FieldType>(fieldType: FieldType, fieldTypes: ReadonlyArray<T>): fieldType is T; | ||
export declare function isModelFieldOneOfFieldTypes<T extends FieldType>(modelField: Field, fieldTypes: ReadonlyArray<T>): modelField is FieldForType<T>; | ||
export declare function isDocumentFieldOneOfFieldTypes<T extends FieldType>(documentField: DocumentField, fieldTypes: ReadonlyArray<T>): documentField is DocumentFieldForType<T>; | ||
export declare function defineStackbitConfig(stackbitConfig: StackbitConfig): StackbitConfig; | ||
//# sourceMappingURL=utils.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defineStackbitConfig = exports.getLocalizedFieldForLocale = exports.isLocalizedField = void 0; | ||
exports.defineStackbitConfig = exports.isDocumentFieldOneOfFieldTypes = exports.isModelFieldOneOfFieldTypes = exports.isOneOfFieldTypes = exports.getLocalizedFieldForLocale = exports.isLocalizedField = void 0; | ||
function isLocalizedField(field) { | ||
@@ -64,2 +64,14 @@ return !!field.localized; | ||
exports.getLocalizedFieldForLocale = getLocalizedFieldForLocale; | ||
function isOneOfFieldTypes(fieldType, fieldTypes) { | ||
return fieldTypes.includes(fieldType); | ||
} | ||
exports.isOneOfFieldTypes = isOneOfFieldTypes; | ||
function isModelFieldOneOfFieldTypes(modelField, fieldTypes) { | ||
return fieldTypes.includes(modelField.type); | ||
} | ||
exports.isModelFieldOneOfFieldTypes = isModelFieldOneOfFieldTypes; | ||
function isDocumentFieldOneOfFieldTypes(documentField, fieldTypes) { | ||
return fieldTypes.includes(documentField.type); | ||
} | ||
exports.isDocumentFieldOneOfFieldTypes = isDocumentFieldOneOfFieldTypes; | ||
function defineStackbitConfig(stackbitConfig) { | ||
@@ -66,0 +78,0 @@ return stackbitConfig; |
{ | ||
"name": "@stackbit/types", | ||
"version": "0.1.11-gitcms.0", | ||
"version": "0.1.11-gitcms.1", | ||
"description": "Types for Stackbit config and Content Source Interface", | ||
@@ -42,3 +42,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "ea7067c13e7c4710dd2ef23bace3eb9f39990136" | ||
"gitHead": "cc44b1cce7680963b37e751cea5adf24627af1a7" | ||
} |
@@ -211,2 +211,3 @@ import type { ContentSourceInterface } from './content-source'; | ||
passthrough?: string[]; | ||
directRoutes?: Record<string, string>; | ||
watch?: { | ||
@@ -213,0 +214,0 @@ reinstallPackages?: string[]; |
@@ -0,1 +1,3 @@ | ||
import type { FieldType } from './model-fields'; | ||
/** | ||
@@ -28,2 +30,27 @@ * Front-end frameworks supported by Stackbit without any additional | ||
export const FIELD_TYPE: { [Type in FieldType as Type extends 'cross-reference' ? 'crossReference' : Type]: Type } = { | ||
string: 'string', | ||
url: 'url', | ||
slug: 'slug', | ||
text: 'text', | ||
markdown: 'markdown', | ||
html: 'html', | ||
number: 'number', | ||
boolean: 'boolean', | ||
enum: 'enum', | ||
date: 'date', | ||
datetime: 'datetime', | ||
color: 'color', | ||
image: 'image', | ||
file: 'file', | ||
json: 'json', | ||
richText: 'richText', | ||
object: 'object', | ||
model: 'model', | ||
reference: 'reference', | ||
crossReference: 'cross-reference', | ||
style: 'style', | ||
list: 'list' | ||
} as const; | ||
export const FIELD_TYPES = [ | ||
@@ -30,0 +57,0 @@ 'string', |
@@ -1,4 +0,5 @@ | ||
import type { FieldType } from './model-fields'; | ||
import type { Simplify } from './utils'; | ||
import { DocumentField, DocumentStringLikeFieldForType } from './content-source-document-fields'; | ||
export type TypeDocument = 'document'; | ||
export type DocumentStatus = 'added' | 'modified' | 'published' | 'deleted'; | ||
export interface Document<DocumentContext = unknown> { | ||
@@ -21,2 +22,3 @@ type: TypeDocument; | ||
export type TypeAsset = 'asset'; | ||
export interface Asset<AssetContext = unknown> { | ||
@@ -36,239 +38,31 @@ type: TypeAsset; | ||
export type TypeDocument = 'document'; | ||
export type TypeAsset = 'asset'; | ||
export type DocumentStatus = 'added' | 'modified' | 'published' | 'deleted'; | ||
export type AssetFields = { | ||
title: DocumentValueFieldForType<'string'>; | ||
title: DocumentStringLikeFieldForType<'string'>; | ||
file: AssetFileField; | ||
}; | ||
export type DocumentField = | ||
| DocumentValueField | ||
| DocumentObjectField | ||
| DocumentModelField | ||
| DocumentReferenceField | ||
| DocumentListField | ||
| DocumentRichTextField | ||
| DocumentImageField; | ||
export type DocumentFieldLocalized = | ||
| DocumentValueFieldLocalized | ||
| DocumentObjectFieldLocalized | ||
| DocumentModelFieldLocalized | ||
| DocumentReferenceFieldLocalized | ||
| DocumentListFieldLocalized | ||
| DocumentRichTextFieldLocalized | ||
| DocumentImageFieldLocalized; | ||
export type DocumentFieldNonLocalized = | ||
| DocumentValueFieldNonLocalized | ||
| DocumentObjectFieldNonLocalized | ||
| DocumentModelFieldNonLocalized | ||
| DocumentReferenceFieldNonLocalized | ||
| DocumentListFieldNonLocalized | ||
| DocumentRichTextFieldNonLocalized | ||
| DocumentImageFieldNonLocalized; | ||
export type DocumentFieldBaseProps = | ||
| DocumentValueFieldBaseProps | ||
| DocumentObjectFieldBase | ||
| DocumentModelFieldBase | ||
| DocumentReferenceFieldBase | ||
| DocumentListFieldBase | ||
| DocumentRichTextFieldBase | ||
| DocumentImageFieldBase; | ||
export type DocumentFieldSpecificProps = | ||
| DocumentValueFieldProps | ||
| DocumentObjectFieldProps | ||
| DocumentModelFieldProps | ||
| DocumentReferenceFieldProps | ||
| DocumentListFieldProps | ||
| DocumentRichTextFieldProps | ||
| DocumentImageFieldProps; | ||
type FindByType<Union extends { type: FieldType }, Type extends FieldType> = Union extends { type: Type } | ||
? Union | ||
: never; | ||
export type DocumentFieldForType<Type extends FieldType> = FindByType<DocumentField, Type>; | ||
export type DocumentFieldLocalizedForType<Type extends FieldType> = FindByType<DocumentFieldLocalized, Type>; | ||
export type DocumentFieldNonLocalizedForType<Type extends FieldType> = FindByType<DocumentFieldNonLocalized, Type>; | ||
export type DocumentFieldBasePropsForType<Type extends FieldType> = FindByType<DocumentFieldBaseProps, Type>; | ||
export type DocumentFieldSpecificPropsForType<Type extends FieldType> = Simplify< | ||
Omit<DocumentFieldNonLocalizedForType<Type>, keyof DocumentFieldBasePropsForType<Type> | 'locale' | 'localized'> | ||
>; | ||
export type DocumentFieldTypeLocalized<BaseFieldProps, LocalizedFieldProps> = Simplify< | ||
BaseFieldProps & { | ||
localized: true; | ||
locales: Record<string, { locale: string } & LocalizedFieldProps>; | ||
} | ||
>; | ||
export type DocumentFieldTypeNonLocalized<BaseFieldProps, LocalizedFieldProps> = Simplify< | ||
BaseFieldProps & | ||
LocalizedFieldProps & { | ||
localized?: false; | ||
} | ||
>; | ||
// any field that is not 'object' | 'model' | 'reference' | 'richText' | 'list' | ||
export type DocumentValueFieldType = Exclude< | ||
FieldType, | ||
'object' | 'model' | 'reference' | 'richText' | 'list' | 'image' | ||
>; | ||
/** | ||
* Document field with any type except 'object' | 'model' | 'reference' | 'richText' | 'list' | ||
* Asset "assetFile" field | ||
*/ | ||
export type DocumentValueField = DocumentValueFieldForType<DocumentValueFieldType>; | ||
export type DocumentValueFieldForType<Type> = Type extends DocumentValueFieldType | ||
? DocumentValueFieldLocalizedForType<Type> | DocumentValueFieldNonLocalizedForType<Type> | ||
: never; | ||
export type AssetFileField = AssetFileFieldLocalized | AssetFileFieldNonLocalized; | ||
export type DocumentValueFieldLocalized = DocumentValueFieldLocalizedForType<DocumentValueFieldType>; | ||
export type DocumentValueFieldLocalizedForType<Type> = Type extends DocumentValueFieldType | ||
? DocumentFieldTypeLocalized<DocumentValueFieldBase<Type>, DocumentValueFieldProps> | ||
: never; | ||
export interface AssetFileFieldNonLocalized extends AssetFileFieldBase, AssetFileFieldProps { | ||
localized?: false; | ||
} | ||
export type DocumentValueFieldNonLocalized = DocumentValueFieldNonLocalizedForType<DocumentValueFieldType>; | ||
export type DocumentValueFieldNonLocalizedForType<Type> = Type extends DocumentValueFieldType | ||
? DocumentFieldTypeNonLocalized<DocumentValueFieldBase<Type>, DocumentValueFieldProps> | ||
: never; | ||
export interface AssetFileFieldLocalized extends AssetFileFieldBase { | ||
localized: true; | ||
locales: Record< | ||
string, | ||
{ | ||
locale: string; | ||
} & AssetFileFieldProps | ||
>; | ||
} | ||
export type DocumentValueFieldBaseProps = DocumentValueFieldBasePropsForType<DocumentValueFieldType>; | ||
export type DocumentValueFieldBasePropsForType<Type> = Type extends DocumentValueFieldType | ||
? DocumentValueFieldBase<Type> | ||
: never; | ||
export type DocumentValueFieldBase<Type extends DocumentValueFieldType> = { | ||
type: Type; | ||
}; | ||
export type DocumentValueFieldProps = { | ||
value: any; | ||
}; | ||
/** | ||
* Document "object" field | ||
*/ | ||
export type DocumentObjectField = DocumentObjectFieldLocalized | DocumentObjectFieldNonLocalized; | ||
export type DocumentObjectFieldLocalized = DocumentFieldTypeLocalized< | ||
DocumentObjectFieldBase, | ||
DocumentObjectFieldProps | ||
>; | ||
export type DocumentObjectFieldNonLocalized = DocumentFieldTypeNonLocalized< | ||
DocumentObjectFieldBase, | ||
DocumentObjectFieldProps | ||
>; | ||
export type DocumentObjectFieldBase = { | ||
type: 'object'; | ||
}; | ||
export type DocumentObjectFieldProps = { | ||
fields: Record<string, DocumentField>; | ||
}; | ||
/** | ||
* Document "model" field | ||
*/ | ||
export type DocumentModelField = DocumentModelFieldLocalized | DocumentModelFieldNonLocalized; | ||
export type DocumentModelFieldLocalized = DocumentFieldTypeLocalized<DocumentModelFieldBase, DocumentModelFieldProps>; | ||
export type DocumentModelFieldNonLocalized = DocumentFieldTypeNonLocalized< | ||
DocumentModelFieldBase, | ||
DocumentModelFieldProps | ||
>; | ||
export type DocumentModelFieldBase = { | ||
type: 'model'; | ||
}; | ||
export type DocumentModelFieldProps = { | ||
modelName: string; | ||
fields: Record<string, DocumentField>; | ||
}; | ||
/** | ||
* Document "reference" field | ||
*/ | ||
export type DocumentReferenceField = DocumentReferenceFieldLocalized | DocumentReferenceFieldNonLocalized; | ||
export type DocumentReferenceFieldLocalized = DocumentFieldTypeLocalized< | ||
DocumentReferenceFieldBase, | ||
DocumentReferenceFieldProps | ||
>; | ||
export type DocumentReferenceFieldNonLocalized = DocumentFieldTypeNonLocalized< | ||
DocumentReferenceFieldBase, | ||
DocumentReferenceFieldProps | ||
>; | ||
export type DocumentReferenceFieldBase = { | ||
type: 'reference'; | ||
refType: 'document' | 'asset'; | ||
}; | ||
export type DocumentReferenceFieldProps = { | ||
refId: string; | ||
}; | ||
/** | ||
* Document "richText" field | ||
*/ | ||
export type DocumentRichTextField = DocumentRichTextFieldLocalized | DocumentRichTextFieldNonLocalized; | ||
export type DocumentRichTextFieldLocalized = DocumentFieldTypeLocalized< | ||
DocumentRichTextFieldBase, | ||
DocumentRichTextFieldProps | ||
>; | ||
export type DocumentRichTextFieldNonLocalized = DocumentFieldTypeNonLocalized< | ||
DocumentRichTextFieldBase, | ||
DocumentRichTextFieldProps | ||
>; | ||
export type DocumentRichTextFieldBase = { | ||
type: 'richText'; | ||
}; | ||
export type DocumentRichTextFieldProps = { | ||
hint?: string; | ||
value: any; | ||
}; | ||
/** | ||
* Document "list" field | ||
*/ | ||
export type DocumentListField = DocumentListFieldLocalized | DocumentListFieldNonLocalized; | ||
export type DocumentListFieldLocalized = DocumentFieldTypeLocalized<DocumentListFieldBase, DocumentListFieldProps>; | ||
export type DocumentListFieldNonLocalized = DocumentFieldTypeNonLocalized< | ||
DocumentListFieldBase, | ||
DocumentListFieldProps | ||
>; | ||
export type DocumentListFieldBase = { | ||
type: 'list'; | ||
}; | ||
export type DocumentListFieldItems = Exclude<DocumentFieldNonLocalized, DocumentListFieldNonLocalized>; | ||
export type DocumentListFieldProps = { | ||
items: DocumentListFieldItems[]; | ||
}; | ||
/** | ||
* Document "image" field | ||
*/ | ||
export type DocumentImageField = DocumentImageFieldLocalized | DocumentImageFieldNonLocalized; | ||
export type DocumentImageFieldLocalized = DocumentFieldTypeLocalized<DocumentImageFieldBase, DocumentImageFieldProps>; | ||
export type DocumentImageFieldNonLocalized = DocumentFieldTypeNonLocalized< | ||
DocumentImageFieldBase, | ||
DocumentImageFieldProps | ||
>; | ||
export type DocumentImageFieldBase = { | ||
type: 'image'; | ||
}; | ||
export type DocumentImageFieldProps = { | ||
fields: { | ||
title: DocumentValueFieldForType<'string'>; | ||
url: DocumentValueFieldForType<'string'>; | ||
}; | ||
}; | ||
/** | ||
* Asset "assetFile" field | ||
*/ | ||
export type AssetFileField = AssetFileFieldLocalized | AssetFileFieldNonLocalized; | ||
export type AssetFileFieldLocalized = DocumentFieldTypeLocalized<AssetFileFieldBase, AssetFileFieldProps>; | ||
export type AssetFileFieldNonLocalized = DocumentFieldTypeNonLocalized<AssetFileFieldBase, AssetFileFieldProps>; | ||
export type AssetFileFieldBase = { | ||
type: 'assetFile'; | ||
}; | ||
export type AssetFileFieldProps = { | ||
export interface AssetFileFieldProps { | ||
url: string; | ||
@@ -278,6 +72,6 @@ fileName?: string; | ||
size?: number; | ||
dimensions: { | ||
dimensions?: { | ||
width?: number; | ||
height?: number; | ||
}; | ||
}; | ||
} |
@@ -32,6 +32,3 @@ import type { ChildProcessWithoutNullStreams } from 'child_process'; | ||
onWebhook?(data: { | ||
data: unknown; | ||
headers: Record<string, string>; | ||
}): void; | ||
onWebhook?(data: { data: unknown; headers: Record<string, string> }): void; | ||
@@ -113,9 +110,7 @@ onFilesChange?({ | ||
export type RunResult = { stdout: string, stderr: string; exitCode?: number; err?: Error }; | ||
export type RunResult = { stdout: string; stderr: string; exitCode?: number; err?: Error }; | ||
export interface RunServiceInterface { | ||
command: (command: string, args: string[], cwd?: string, shell?: boolean) => Promise<RunResult>; | ||
} | ||
export type CommandRunner = (command: string, args?: string[], options?: { cwd?: string; shell?: boolean; env?: NodeJS.ProcessEnv }) => Promise<RunResult>; | ||
export interface GitFileObject { | ||
export interface GitFileCommitDescriptor { | ||
filePath: string; | ||
@@ -134,7 +129,10 @@ description: string; | ||
commitHash: string; | ||
changes: [DocumentStatus, string][]; | ||
changes: { | ||
status: DocumentStatus; | ||
filePath: string; | ||
}[]; | ||
} | ||
export interface GitServiceInterface { | ||
commitAndPush: (author: GitAuthor, files: GitFileObject[]) => Promise<void>; | ||
commitAndPush: (author: GitAuthor, files: GitFileCommitDescriptor[]) => Promise<void>; | ||
publish(author: GitAuthor, filePaths?: string[]): Promise<void>; | ||
@@ -145,11 +143,2 @@ commitLog(): Promise<GitCommitLogEntry[]>; | ||
export interface ContentSourceServices { | ||
git: GitServiceInterface; | ||
run: RunServiceInterface; | ||
} | ||
export interface ContentSourceDelegate { | ||
services: ContentSourceServices; | ||
} | ||
export interface InitOptions { | ||
@@ -162,3 +151,4 @@ logger: Logger; | ||
devAppRestartNeeded?: () => void; | ||
delegate: ContentSourceDelegate; | ||
git: GitServiceInterface; | ||
runCommand: CommandRunner; | ||
} | ||
@@ -165,0 +155,0 @@ |
@@ -8,4 +8,5 @@ export * from './config'; | ||
export * from './content-source-document'; | ||
export * from './content-source-document-fields'; | ||
export * from './content-source-operation'; | ||
export * from './utils'; | ||
export * from './sidebar-button'; |
@@ -56,8 +56,8 @@ /** | ||
type FindByType<Union extends { type: FieldType }, Type extends FieldType> = Union extends { type: Type } | ||
type ExtractByType<Union extends { type: FieldType }, Type extends FieldType> = Union extends { type: Type } | ||
? Union | ||
: never; | ||
export type FieldForType<Type extends FieldType> = FindByType<Field, Type>; | ||
export type FieldSpecificPropsForType<Type extends FieldType> = FindByType<FieldSpecificProps, Type>; | ||
export type FieldSpecificPropsForField<T extends Field> = FindByType<FieldSpecificProps, T['type']>; | ||
export type FieldForType<Type extends FieldType> = ExtractByType<Field, Type>; | ||
export type FieldSpecificPropsForType<Type extends FieldType> = ExtractByType<FieldSpecificProps, Type>; | ||
export type FieldSpecificPropsForField<Type extends Field> = ExtractByType<FieldSpecificProps, Type['type']>; | ||
@@ -112,3 +112,7 @@ export type FieldBasic = FieldCommonProps & FieldBasicProps; | ||
export type FieldEnumProps = FieldEnumDropdownProps | FieldEnumThumbnailsProps | FieldEnumPaletteProps; | ||
export type FieldEnumProps = | ||
| FieldEnumDropdownProps | ||
| FieldEnumThumbnailsProps | ||
| FieldEnumPaletteProps | ||
| FieldEnumPaletteColorsProps; | ||
@@ -133,2 +137,8 @@ export interface FieldEnumDropdownProps { | ||
export interface FieldEnumPaletteColorsProps { | ||
type: 'enum'; | ||
controlType: 'palette-colors'; | ||
options: FieldEnumOptionPaletteColors[]; | ||
} | ||
export type FieldEnumOptionValue = string | number; | ||
@@ -142,3 +152,3 @@ | ||
export interface FieldEnumOptionThumbnails extends FieldEnumOptionObject { | ||
thumbnail?: string; | ||
thumbnail: string; | ||
} | ||
@@ -152,2 +162,6 @@ | ||
export interface FieldEnumOptionPaletteColors extends FieldEnumOptionObject { | ||
colors: string[]; | ||
} | ||
export interface FieldImageProps { | ||
@@ -154,0 +168,0 @@ type: 'image'; |
@@ -1,6 +0,5 @@ | ||
import type { FieldType } from './model-fields'; | ||
import type { FieldType, Field, FieldForType } from './model-fields'; | ||
import type { StackbitConfig } from './config'; | ||
import type { AssetFileField, AssetFileFieldLocalized } from './content-source-document'; | ||
import type { | ||
AssetFileField, | ||
AssetFileFieldLocalized, | ||
DocumentField, | ||
@@ -10,3 +9,3 @@ DocumentFieldForType, | ||
DocumentFieldNonLocalizedForType | ||
} from './content-source-document'; | ||
} from './content-source-document-fields'; | ||
@@ -72,6 +71,6 @@ export type Simplify<T> = { | ||
} | ||
return ({ | ||
return { | ||
...base, | ||
...localizedField | ||
} as unknown) as DocumentFieldNonLocalizedForType<Type>; | ||
} as unknown as DocumentFieldNonLocalizedForType<Type>; | ||
} else { | ||
@@ -82,4 +81,25 @@ return field; | ||
export function isOneOfFieldTypes<T extends FieldType>( | ||
fieldType: FieldType, | ||
fieldTypes: ReadonlyArray<T> | ||
): fieldType is T { | ||
return fieldTypes.includes(fieldType as T); | ||
} | ||
export function isModelFieldOneOfFieldTypes<T extends FieldType>( | ||
modelField: Field, | ||
fieldTypes: ReadonlyArray<T> | ||
): modelField is FieldForType<T> { | ||
return fieldTypes.includes(modelField.type as T); | ||
} | ||
export function isDocumentFieldOneOfFieldTypes<T extends FieldType>( | ||
documentField: DocumentField, | ||
fieldTypes: ReadonlyArray<T> | ||
): documentField is DocumentFieldForType<T> { | ||
return fieldTypes.includes(documentField.type as T); | ||
} | ||
export function defineStackbitConfig(stackbitConfig: StackbitConfig) { | ||
return stackbitConfig; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
134713
62
2777