@stackbit/sdk
Version:
57 lines (44 loc) • 1.84 kB
text/typescript
/**
* This file extends the Stackbit schema with an "unknown" field type.
* The "unknown" field type is used in intermediate steps when generating a new
* schema from content files
*/
import {
Field,
FieldType,
FieldCommonProps,
FieldObject,
FieldObjectProps,
FieldModelProps,
FieldList,
FieldListProps,
FieldStyle,
FieldListItems
} from '@stackbit/types';
export type FieldWithUnknown = Exclude<Field, FieldObject | FieldStyle | FieldList> | FieldUnknown | FieldObjectWithUnknown | FieldListWithUnknown;
export type FieldUnknown = FieldCommonProps & FieldUnknownProps;
export type FieldObjectWithUnknown = FieldCommonProps & FieldObjectPropsWithUnknown;
export type FieldListWithUnknown = FieldCommonProps & FieldListPropsWithUnknown;
export type FieldTypeWithUnknown = 'unknown' | FieldType;
export interface FieldUnknownProps {
type: 'unknown';
}
export type FieldObjectPropsWithUnknown = Omit<FieldObjectProps, 'fields'> & {
fields: FieldWithUnknown[];
};
export type FieldListPropsWithUnknown = Omit<FieldListProps, 'items'> & {
items: FieldListItemsWithUnknown;
};
export type FieldListItemsWithUnknown = Exclude<FieldListItems, FieldObjectProps> | FieldUnknownProps | FieldObjectPropsWithUnknown;
export function isObjectWithUnknownField(field: FieldWithUnknown): field is FieldObjectWithUnknown {
return field.type === 'object';
}
export function isListWithUnknownField(field: FieldWithUnknown): field is FieldListWithUnknown {
return field.type === 'list';
}
export function isObjectListItemsWithUnknown(items: FieldListItemsWithUnknown): items is FieldObjectPropsWithUnknown {
return items.type === 'object';
}
export function isModelListItemsWithUnknown(items: FieldListItemsWithUnknown): items is FieldModelProps {
return items.type === 'model';
}