@stackbit/types
Version:
Types for Stackbit config and Content Source Interface
75 lines • 2.9 kB
TypeScript
export type Simplify<T> = {
[K in keyof T]: T[K];
};
export type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
export type PartialBy<Type, Key extends keyof Type> = Omit<Type, Key> & Partial<Pick<Type, Key>>;
export type RequiredBy<Type, Key extends keyof Type> = Omit<Type, Key> & Required<Pick<Type, Key>>;
/**
* This object contains the data required to create a new document. It may
* include properties with values to populate primitive fields, nested objects,
* and arrays, as well as special "instruction" properties to link to existing
* documents or recursively create new documents that are then linked to the
* parent document.
*
* Unlike model fields or document fields, this object has a simplified structure
* and doesn't require specifying field types. The properties of the object are
* directly mapped to the document fields by name, and the property values are
* used "as-is" to populate the document's primitive fields. More complex field
* types use special "instruction" properties that define how these fields should
* be created.
*
* For example, to create a document with a nested object inside one of its
* 'model' fields, the property value should be an object containing a special
* `$$type` property with the model name of the nested object, along with
* additional properties representing the fields for the new nested object.
*
* ```
* {
* title: 'Homepage',
* section: {
* $$type: 'hero_section',
* heading: 'Welcome'
* }
* }
* ```
*
* Similarly, to create a document that references another new document within
* one of its 'reference' fields, the property value should be an object
* containing a `$$type` property with the model name for the new document,
* and additional properties representing the fields for the referenced document.
*
* To create a document with 'image' or 'reference' fields that link to existing
* entities, the property value should be an object containing a `$$ref` property
* that specifies the ID of the linked entity.
*
* ```
* {
* title: 'New post!',
* author: {
* $$ref: 'author_id',
* }
* }
* ```
*
* When a document is created from this object, any missing fields will be
* assigned their default values as defined by the document's model. If the model
* doesn't specify a default value, the document's field will remain empty.
* If a model field has a default value but the new document needs the field to
* be empty, set the property value to null.
*
* @example
* {
* title: 'Hello world',
* object: {
* foo: true,
* bar: 10
* },
* author: { $$ref: 'author_id' },
* components: [
* { $$type: 'HeroSection', title: 'Welcome' },
* { $$type: 'FeatureSection' }
* ]
* }
*/
export type ContentObjectSpecification = Record<string, any>;
//# sourceMappingURL=utility-types.d.ts.map