@stackbit/types
Advanced tools
Comparing version
@@ -186,2 +186,3 @@ import type { ContentSourceInterface } from './content-source'; | ||
passthrough?: string[]; | ||
directRoutes?: Record<string, string>; | ||
watch?: { | ||
@@ -188,0 +189,0 @@ reinstallPackages?: string[]; |
@@ -5,16 +5,5 @@ import { FieldType, StyleProps } from './model-fields'; | ||
export declare type DocumentFieldLocalized = DocumentStringLikeFieldLocalized | DocumentNumberFieldLocalized | DocumentBooleanFieldLocalized | DocumentJsonFieldLocalized | DocumentStyleFieldLocalized | DocumentRichTextFieldLocalized | DocumentImageFieldLocalized | DocumentObjectFieldLocalized | DocumentModelFieldLocalized | DocumentReferenceFieldLocalized | DocumentCrossReferenceFieldLocalized | DocumentListFieldLocalized; | ||
export declare type DocumentFieldBaseProps = DistributeDocumentFieldBaseProps<DocumentField>; | ||
export declare type DocumentFieldSpecificProps = DistributeDocumentFieldSpecificProps<DocumentField>; | ||
export declare type DistributeDocumentFieldBaseProps<Type extends DocumentField> = Type extends DocumentField ? DocumentFieldBasePropsForType<Type> : never; | ||
export declare type DocumentFieldBasePropsForType<Type extends DocumentField> = Type extends { | ||
localized?: false; | ||
} ? Omit<Type, keyof DocumentFieldSpecificPropsForType<DocumentFieldForType<Type['type']>> | 'localized'> : never; | ||
export declare type DistributeDocumentFieldSpecificProps<Type extends DocumentField> = Type extends DocumentField ? DocumentFieldSpecificPropsForType<Type> : never; | ||
export declare type DocumentFieldSpecificPropsForType<Type extends DocumentField> = Type extends { | ||
localized: true; | ||
} ? Omit<Type['locales'][string], 'locale'> : never; | ||
export declare type DocumentFieldForType<Type extends FieldType> = FindDocumentFieldByType<DocumentField, Type>; | ||
export declare type DocumentFieldLocalizedForType<Type extends FieldType> = FindDocumentFieldByType<DocumentFieldLocalized, Type>; | ||
export declare type DocumentFieldNonLocalizedForType<Type extends FieldType> = FindDocumentFieldByType<DocumentFieldNonLocalized, Type>; | ||
export declare type FindDocumentFieldByType<Union extends { | ||
export declare type DocumentFieldBaseProps = DocumentFieldBasePropsForDocumentField<DocumentField>; | ||
export declare type DocumentFieldSpecificProps = DocumentFieldSpecificPropsForDocumentField<DocumentFieldLocalized>; | ||
export declare type ExtractByType<Union extends { | ||
type: FieldType; | ||
@@ -24,10 +13,20 @@ }, Type extends FieldType> = Union extends { | ||
} ? Union : never; | ||
export declare type DocumentFieldForType<Type extends FieldType> = ExtractByType<DocumentField, Type>; | ||
export declare type DocumentFieldNonLocalizedForType<Type extends FieldType> = ExtractByType<DocumentFieldNonLocalized, Type>; | ||
export declare type DocumentFieldLocalizedForType<Type extends FieldType> = ExtractByType<DocumentFieldLocalized, Type>; | ||
export declare type DocumentFieldBasePropsForType<Type extends FieldType> = ExtractByType<DocumentFieldBaseProps, Type>; | ||
export declare type DocumentFieldBasePropsForDocumentField<DocField extends DocumentField> = DocField extends { | ||
localized?: false; | ||
} ? Omit<DocField, keyof DocumentFieldSpecificPropsForDocumentField<DocumentFieldLocalizedForType<DocField['type']>> | 'localized'> : never; | ||
export declare type DocumentFieldSpecificPropsForDocumentField<DocField extends DocumentFieldLocalized> = DocField extends { | ||
locales: Record<string, infer Props>; | ||
} ? Omit<Props, 'locale'> : never; | ||
export declare type DocumentStringLikeFieldTypes = 'string' | 'url' | 'slug' | 'text' | 'markdown' | 'html' | 'enum' | 'date' | 'datetime' | 'color' | 'file'; | ||
export declare type DocumentStringLikeField = DocumentStringLikeFieldForType<DocumentStringLikeFieldTypes>; | ||
export declare type DocumentStringLikeFieldNonLocalized = DocumentStringLikeFieldNonLocalizedForType<DocumentStringLikeFieldTypes>; | ||
export declare type DocumentStringLikeFieldLocalized = DocumentStringFieldLocalizedForType<DocumentStringLikeFieldTypes>; | ||
export declare type DocumentStringLikeFieldForType<Type> = Type extends DocumentStringLikeFieldTypes ? DocumentStringLikeFieldNonLocalizedBase<Type> | DocumentStringLikeFieldLocalizedBase<Type> : never; | ||
export declare type DocumentStringLikeFieldNonLocalizedForType<Type> = Type extends DocumentStringLikeFieldTypes ? DocumentStringLikeFieldNonLocalizedBase<Type> : never; | ||
export declare type DocumentStringFieldLocalizedForType<Type> = Type extends DocumentStringLikeFieldTypes ? DocumentStringLikeFieldLocalizedBase<Type> : never; | ||
export interface DocumentStringLikeFieldNonLocalizedBase<Type extends DocumentStringLikeFieldTypes> { | ||
export declare type DocumentStringLikeFieldNonLocalized = DistributeDocumentStringLikeFieldNonLocalized<DocumentStringLikeFieldTypes>; | ||
export declare type DocumentStringLikeFieldLocalized = DistributeDocumentStringFieldLocalized<DocumentStringLikeFieldTypes>; | ||
export declare type DocumentStringLikeFieldForType<Type> = Type extends DocumentStringLikeFieldTypes ? DocumentStringLikeFieldNonLocalizedForType<Type> | DocumentStringLikeFieldLocalizedForType<Type> : never; | ||
export declare type DistributeDocumentStringLikeFieldNonLocalized<Type> = Type extends DocumentStringLikeFieldTypes ? DocumentStringLikeFieldNonLocalizedForType<Type> : never; | ||
export declare type DistributeDocumentStringFieldLocalized<Type> = Type extends DocumentStringLikeFieldTypes ? DocumentStringLikeFieldLocalizedForType<Type> : never; | ||
export interface DocumentStringLikeFieldNonLocalizedForType<Type extends DocumentStringLikeFieldTypes> { | ||
type: Type; | ||
@@ -37,3 +36,3 @@ localized?: false; | ||
} | ||
export interface DocumentStringLikeFieldLocalizedBase<Type extends DocumentStringLikeFieldTypes> { | ||
export interface DocumentStringLikeFieldLocalizedForType<Type extends DocumentStringLikeFieldTypes> { | ||
type: Type; | ||
@@ -40,0 +39,0 @@ localized: true; |
@@ -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; | ||
@@ -44,0 +44,0 @@ export declare type FieldEnum = FieldCommonProps & FieldEnumProps; |
@@ -1,2 +0,2 @@ | ||
import type { FieldType } from './model-fields'; | ||
import type { FieldType, Field, FieldForType } from './model-fields'; | ||
import type { StackbitConfig } from './config'; | ||
@@ -46,3 +46,6 @@ import type { AssetFileField, AssetFileFieldLocalized } from './content-source-document'; | ||
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.2.0-types-alpha.0", | ||
"version": "0.2.0", | ||
"description": "Types for Stackbit config and Content Source Interface", | ||
@@ -42,3 +42,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "6b865750fa5f9d3f4f7393e4a7e05e89576465fb" | ||
"gitHead": "fe959112061432c1ef5981a0e7f15b1c75b788ed" | ||
} |
@@ -211,2 +211,3 @@ import type { ContentSourceInterface } from './content-source'; | ||
passthrough?: string[]; | ||
directRoutes?: Record<string, string>; | ||
watch?: { | ||
@@ -213,0 +214,0 @@ reinstallPackages?: string[]; |
@@ -45,37 +45,33 @@ import { FieldType, StyleProps } from './model-fields'; | ||
export type DocumentFieldBaseProps = DistributeDocumentFieldBaseProps<DocumentField>; | ||
export type DocumentFieldSpecificProps = DistributeDocumentFieldSpecificProps<DocumentField>; | ||
// utility types | ||
export type DocumentFieldBaseProps = DocumentFieldBasePropsForDocumentField<DocumentField>; | ||
export type DocumentFieldSpecificProps = DocumentFieldSpecificPropsForDocumentField<DocumentFieldLocalized>; | ||
export type DistributeDocumentFieldBaseProps<Type extends DocumentField> = Type extends DocumentField | ||
? DocumentFieldBasePropsForType<Type> | ||
export type ExtractByType<Union extends { type: FieldType }, Type extends FieldType> = Union extends { | ||
type: Type; | ||
} | ||
? Union | ||
: never; | ||
export type DocumentFieldForType<Type extends FieldType> = ExtractByType<DocumentField, Type>; | ||
export type DocumentFieldNonLocalizedForType<Type extends FieldType> = ExtractByType<DocumentFieldNonLocalized, Type>; | ||
export type DocumentFieldLocalizedForType<Type extends FieldType> = ExtractByType<DocumentFieldLocalized, Type>; | ||
export type DocumentFieldBasePropsForType<Type extends FieldType> = ExtractByType<DocumentFieldBaseProps, Type>; | ||
export type DocumentFieldBasePropsForType<Type extends DocumentField> = Type extends { localized?: false } | ||
? Omit<Type, keyof DocumentFieldSpecificPropsForType<DocumentFieldForType<Type['type']>> | 'localized'> | ||
export type DocumentFieldBasePropsForDocumentField<DocField extends DocumentField> = DocField extends { | ||
localized?: false; | ||
} | ||
? Omit< | ||
DocField, | ||
| keyof DocumentFieldSpecificPropsForDocumentField<DocumentFieldLocalizedForType<DocField['type']>> | ||
| 'localized' | ||
> | ||
: never; | ||
export type DistributeDocumentFieldSpecificProps<Type extends DocumentField> = Type extends DocumentField | ||
? DocumentFieldSpecificPropsForType<Type> | ||
: never; | ||
export type DocumentFieldSpecificPropsForType<Type extends DocumentField> = Type extends { localized: true } | ||
? Omit<Type['locales'][string], 'locale'> | ||
: never; | ||
export type DocumentFieldForType<Type extends FieldType> = FindDocumentFieldByType<DocumentField, Type>; | ||
export type DocumentFieldLocalizedForType<Type extends FieldType> = FindDocumentFieldByType< | ||
DocumentFieldLocalized, | ||
Type | ||
>; | ||
export type DocumentFieldNonLocalizedForType<Type extends FieldType> = FindDocumentFieldByType< | ||
DocumentFieldNonLocalized, | ||
Type | ||
>; | ||
export type FindDocumentFieldByType<Union extends { type: FieldType }, Type extends FieldType> = Union extends { | ||
type: Type; | ||
export type DocumentFieldSpecificPropsForDocumentField<DocField extends DocumentFieldLocalized> = DocField extends { | ||
locales: Record<string, infer Props>; | ||
} | ||
? Union | ||
? Omit<Props, 'locale'> | ||
: never; | ||
// string like | ||
export type DocumentStringLikeFieldTypes = | ||
@@ -97,16 +93,16 @@ | 'string' | ||
export type DocumentStringLikeFieldNonLocalized = | ||
DocumentStringLikeFieldNonLocalizedForType<DocumentStringLikeFieldTypes>; | ||
export type DocumentStringLikeFieldLocalized = DocumentStringFieldLocalizedForType<DocumentStringLikeFieldTypes>; | ||
DistributeDocumentStringLikeFieldNonLocalized<DocumentStringLikeFieldTypes>; | ||
export type DocumentStringLikeFieldLocalized = DistributeDocumentStringFieldLocalized<DocumentStringLikeFieldTypes>; | ||
export type DocumentStringLikeFieldForType<Type> = Type extends DocumentStringLikeFieldTypes | ||
? DocumentStringLikeFieldNonLocalizedBase<Type> | DocumentStringLikeFieldLocalizedBase<Type> | ||
? DocumentStringLikeFieldNonLocalizedForType<Type> | DocumentStringLikeFieldLocalizedForType<Type> | ||
: never; | ||
export type DocumentStringLikeFieldNonLocalizedForType<Type> = Type extends DocumentStringLikeFieldTypes | ||
? DocumentStringLikeFieldNonLocalizedBase<Type> | ||
export type DistributeDocumentStringLikeFieldNonLocalized<Type> = Type extends DocumentStringLikeFieldTypes | ||
? DocumentStringLikeFieldNonLocalizedForType<Type> | ||
: never; | ||
export type DocumentStringFieldLocalizedForType<Type> = Type extends DocumentStringLikeFieldTypes | ||
? DocumentStringLikeFieldLocalizedBase<Type> | ||
export type DistributeDocumentStringFieldLocalized<Type> = Type extends DocumentStringLikeFieldTypes | ||
? DocumentStringLikeFieldLocalizedForType<Type> | ||
: never; | ||
export interface DocumentStringLikeFieldNonLocalizedBase<Type extends DocumentStringLikeFieldTypes> { | ||
export interface DocumentStringLikeFieldNonLocalizedForType<Type extends DocumentStringLikeFieldTypes> { | ||
type: Type; | ||
@@ -117,3 +113,3 @@ localized?: false; | ||
export interface DocumentStringLikeFieldLocalizedBase<Type extends DocumentStringLikeFieldTypes> { | ||
export interface DocumentStringLikeFieldLocalizedForType<Type extends DocumentStringLikeFieldTypes> { | ||
type: Type; | ||
@@ -130,2 +126,3 @@ localized: true; | ||
// number | ||
export type DocumentNumberField = DocumentNumberFieldNonLocalized | DocumentNumberFieldLocalized; | ||
@@ -151,2 +148,3 @@ | ||
// boolean | ||
export type DocumentBooleanField = DocumentBooleanFieldNonLocalized | DocumentBooleanFieldLocalized; | ||
@@ -172,4 +170,4 @@ | ||
// style | ||
export type DocumentStyleField = DocumentStyleFieldNonLocalized | DocumentStyleFieldLocalized; | ||
export type DocumentStyleFieldValue = Record<string, Partial<Record<StyleProps, any>>>; | ||
@@ -195,2 +193,3 @@ | ||
// json | ||
export type DocumentJsonField = DocumentJsonFieldNonLocalized | DocumentJsonFieldLocalized; | ||
@@ -218,2 +217,3 @@ | ||
// richText | ||
// TODO: richText value should be well defined according to Stackbit's internal rich-text format | ||
@@ -242,2 +242,3 @@ export type DocumentRichTextFieldValue = any; | ||
// image | ||
export type DocumentImageField = DocumentImageFieldNonLocalized | DocumentImageFieldLocalized; | ||
@@ -273,2 +274,3 @@ | ||
// object | ||
export type DocumentObjectField = DocumentObjectFieldNonLocalized | DocumentObjectFieldLocalized; | ||
@@ -294,2 +296,3 @@ | ||
// model | ||
export type DocumentModelField = DocumentModelFieldNonLocalized | DocumentModelFieldLocalized; | ||
@@ -317,2 +320,3 @@ | ||
// reference | ||
export type DocumentReferenceField = DocumentReferenceFieldNonLocalized | DocumentReferenceFieldLocalized; | ||
@@ -340,2 +344,3 @@ | ||
// cross-reference | ||
export type DocumentCrossReferenceField = | ||
@@ -369,2 +374,3 @@ | DocumentCrossReferenceFieldNonLocalized | ||
// list | ||
export type DocumentListField = DocumentListFieldNonLocalized | DocumentListFieldLocalized; | ||
@@ -371,0 +377,0 @@ export type DocumentListFieldItems = Exclude<DocumentFieldNonLocalized, DocumentListFieldNonLocalized>; |
@@ -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 | FieldEnumPaletteColorsProps; | ||
export type FieldEnumProps = | ||
| FieldEnumDropdownProps | ||
| FieldEnumThumbnailsProps | ||
| FieldEnumPaletteProps | ||
| FieldEnumPaletteColorsProps; | ||
@@ -115,0 +119,0 @@ export interface FieldEnumDropdownProps { |
@@ -1,2 +0,2 @@ | ||
import type { FieldType } from './model-fields'; | ||
import type { FieldType, Field, FieldForType } from './model-fields'; | ||
import type { StackbitConfig } from './config'; | ||
@@ -79,4 +79,25 @@ import type { AssetFileField, AssetFileFieldLocalized } from './content-source-document'; | ||
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
131682
-2.74%62
-7.46%2717
-2.55%