@starlightcms/js-sdk
Index
API Entities
Client
Data Fields
Errors
Functions
Instances
Request Parameters
Selectors
Type Aliases
Instances
Internal Types
Selectors
Visual Data Blocks
Client
DynamicStarlightClient
Type parameters
- T: WorkspaceModelDefinition
StarlightConfig
The available options to configure a StarlightClient.
workspace
is required when creating new clients or configuring the
default client.
Type declaration
optionalbaseUrl?: BaseUrl
The Starlight Query API URL, including the version, and without a trailing slash. Defaults to the production Query API URL.
You only need to set this if you’re not using Starlight’s production APIs.
optionaldebug?: boolean
When true, logs all API requests in the console. Defaults to false.
optionalworkspace?: string
The ID of the workspace that the client should use to request data.
Note: the current APIs only support using workspace IDs as identifiers, and not slugs. Slug support will be added in the future. You can find the workspace ID in the left-side menu on the Starlight interface or below the workspace name in the workspace list.
constdefault
This is the default object exported by the SDK module, which is a pre-created StarlightClient. In the docs, this is called the “global SDK client”. If your application only requests data from a single Starlight workspace, using this client is easier than creating a new one using makeStarlightClient.
Using the default client is as easy as importing the SDK:
// "Starlight" below is the default client.
import Starlight from '@starlightcms/js-sdk'
const response = await Starlight.posts.entries.list()
You need to configure the default workspace before using it. See StarlightClient.configure to learn more.
Data Fields
BooleanField
Represents a Boolean Field returned by the API.
Field types are used to type Entry and Singleton objects when requesting them using some SDK methods. See DefaultModelDefinition for more info.
HtmlField
Represents a HTML Field returned by the API.
Field types are used to type Entry and Singleton objects when requesting them using some SDK methods. See DefaultModelDefinition for more info.
MediaField
Represents a Media Field returned by the API.
Field types are used to type Entry and Singleton objects when requesting them using some SDK methods. See DefaultModelDefinition for more info.
RelationField
Represents a Relation Field returned by the API.
Field types are used to type Entry and Singleton objects when requesting them using some SDK methods. See DefaultModelDefinition for more info.
Type parameters
- T
StringField
Represents a String Field returned by the API.
Field types are used to type Entry and Singleton objects when requesting them using some SDK methods. See DefaultModelDefinition for more info.
TextField
Represents a Text Field returned by the API.
Field types are used to type Entry and Singleton objects when requesting them using some SDK methods. See DefaultModelDefinition for more info.
VisualField
Represents a Visual Field returned by the API.
Field types are used to type Entry and Singleton objects when requesting them using some SDK methods. See DefaultModelDefinition for more info.
Other
BaseUrl
This is a utility type that allows any string to be used as a URL, but provides a default one which can be used by IDEs to provide auto-completion. The default URL points to version 2 of the Query API.
Instances
DynamicCollectionSelector
A Selector that provide all CollectionSelector methods and adds support for creating CollectionInstances using the dynamic syntax.
See CollectionSelector to view all available methods.
See Dynamic Instances documentation to learn more about the dynamic syntax.
DynamicModelCategorySelector
A Selector that provide all ModelCategorySelector methods and adds support for creating ModelCategoryInstances using the dynamic syntax.
See ModelCategorySelector to view all available methods. You can use a DynamicModelCategorySelector by accessing ModelInstance.categories.
See Dynamic Instances documentation to learn more about the dynamic syntax.
Type parameters
DynamicModelInstance
An Instance that provide all ModelInstance methods and adds support for creating ModelCategoryInstances using the dynamic syntax.
See ModelInstance to view all available methods.
See Dynamic Instances documentation to learn more about the dynamic syntax.
Type parameters
Internal Types
QueryableFields
Utility type that creates a string map of all fields of the given
SerializedData type with the field:
prefix. This syntax allows to filter
specific fields when listing Entries:
- Text fields can be filtered by a string query. This works just like
passing a
query
parameter, but it only applies to one field. - Boolean fields can be filtered by “true” or “false”.
If a request uses this type, it means that this syntax can be used in their parameters:
import Starlight from '@starlightcms/js-sdk'
const response = await Starlight.posts.entries.list({
// EntrySelector.list() supports the "field:foo" syntax:
'field:content': 'hello world',
'field:is_featured': true,
// EntrySelector.list() also support other parameters,
// which are passed in this object too:
page: 42,
limit: 20,
})
Type parameters
SerializedData
WithQueryableFieldsOnModelables
Utility type that return QueryableFields if the given type T is an Entry or a Singleton, but generates an empty object otherwise.
Fun fact: internally, Entries and Singletons have parent Models, which is why they are called “modelables” here.
Type parameters
- T
Selectors
DynamicModelSelector
A Selector that provide all ModelSelector methods and adds support for creating DynamicModelInstances using the dynamic syntax.
See ModelSelector to view all available methods.
See Dynamic Instances documentation to learn more about the dynamic syntax.
Type parameters
- T: WorkspaceModelDefinition
Visual Data Blocks
VideoBlock
Represents a Video block, which is used to render embed video elements.
Type declaration
optionalcaption?: string
html: string
service: SupportedServices
type: embed
url: string
videoId: string
width: BlockWidth
This type adds support for the dynamic syntax to the StarlightClient interface, which allows users to create DynamicModelInstances dynamically. See StarlightClient to learn which methods it provides. Also see Dynamic Instances documentation to learn more about the dynamic syntax.
This allows TypeScript to correctly type all models defined by the user in the DefaultModelDefinition type, aside from letting the user using any “unknown” model slug, which is provided by the WorkspaceModelDefinition type.
This type is only aware of the DefaultModelDefinition type because the StarlightClient uses it by default when no model definition type is passed.