@starlightcms/js-sdk 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/README.md +54 -0
  2. package/dist/cjs/client.d.ts +41 -2
  3. package/dist/cjs/client.d.ts.map +1 -1
  4. package/dist/cjs/client.js +39 -0
  5. package/dist/cjs/client.js.map +1 -1
  6. package/dist/cjs/errors.d.ts +35 -0
  7. package/dist/cjs/errors.d.ts.map +1 -1
  8. package/dist/cjs/errors.js +7 -0
  9. package/dist/cjs/errors.js.map +1 -1
  10. package/dist/cjs/index.d.ts +22 -1
  11. package/dist/cjs/index.d.ts.map +1 -1
  12. package/dist/cjs/index.js +21 -0
  13. package/dist/cjs/index.js.map +1 -1
  14. package/dist/cjs/instances/Collection/index.d.ts +4 -4
  15. package/dist/cjs/instances/Collection/index.d.ts.map +1 -1
  16. package/dist/cjs/instances/Collection/index.js.map +1 -1
  17. package/dist/cjs/instances/Collection/types.d.ts +68 -12
  18. package/dist/cjs/instances/Collection/types.d.ts.map +1 -1
  19. package/dist/cjs/instances/Collection/types.js +1 -0
  20. package/dist/cjs/instances/Collection/types.js.map +1 -1
  21. package/dist/cjs/instances/Model/index.d.ts +3 -3
  22. package/dist/cjs/instances/Model/index.d.ts.map +1 -1
  23. package/dist/cjs/instances/Model/index.js.map +1 -1
  24. package/dist/cjs/instances/Model/types.d.ts +86 -3
  25. package/dist/cjs/instances/Model/types.d.ts.map +1 -1
  26. package/dist/cjs/instances/Model/types.js.map +1 -1
  27. package/dist/cjs/instances/ModelCategory/index.d.ts +2 -2
  28. package/dist/cjs/instances/ModelCategory/index.d.ts.map +1 -1
  29. package/dist/cjs/instances/ModelCategory/index.js.map +1 -1
  30. package/dist/cjs/instances/ModelCategory/types.d.ts +62 -10
  31. package/dist/cjs/instances/ModelCategory/types.d.ts.map +1 -1
  32. package/dist/cjs/instances/ModelCategory/types.js.map +1 -1
  33. package/dist/cjs/selectors/Collection/index.d.ts +3 -3
  34. package/dist/cjs/selectors/Collection/index.d.ts.map +1 -1
  35. package/dist/cjs/selectors/Collection/index.js +1 -1
  36. package/dist/cjs/selectors/Collection/index.js.map +1 -1
  37. package/dist/cjs/selectors/Collection/types.d.ts +84 -9
  38. package/dist/cjs/selectors/Collection/types.d.ts.map +1 -1
  39. package/dist/cjs/selectors/Collection/types.js.map +1 -1
  40. package/dist/cjs/selectors/Entry/types.d.ts +105 -10
  41. package/dist/cjs/selectors/Entry/types.d.ts.map +1 -1
  42. package/dist/cjs/selectors/Entry/types.js.map +1 -1
  43. package/dist/cjs/selectors/Media/index.js +2 -2
  44. package/dist/cjs/selectors/Media/index.js.map +1 -1
  45. package/dist/cjs/selectors/Media/types.d.ts +35 -1
  46. package/dist/cjs/selectors/Media/types.d.ts.map +1 -1
  47. package/dist/cjs/selectors/Media/types.js.map +1 -1
  48. package/dist/cjs/selectors/Model/index.d.ts +3 -3
  49. package/dist/cjs/selectors/Model/index.js.map +1 -1
  50. package/dist/cjs/selectors/Model/types.d.ts +62 -3
  51. package/dist/cjs/selectors/Model/types.d.ts.map +1 -1
  52. package/dist/cjs/selectors/Model/types.js.map +1 -1
  53. package/dist/cjs/selectors/ModelCategory/index.d.ts +3 -3
  54. package/dist/cjs/selectors/ModelCategory/index.js +1 -1
  55. package/dist/cjs/selectors/ModelCategory/index.js.map +1 -1
  56. package/dist/cjs/selectors/ModelCategory/types.d.ts +50 -7
  57. package/dist/cjs/selectors/ModelCategory/types.d.ts.map +1 -1
  58. package/dist/cjs/selectors/ModelCategory/types.js.map +1 -1
  59. package/dist/cjs/selectors/Search/index.d.ts +2 -2
  60. package/dist/cjs/selectors/Search/index.d.ts.map +1 -1
  61. package/dist/cjs/selectors/Search/index.js +1 -1
  62. package/dist/cjs/selectors/Search/index.js.map +1 -1
  63. package/dist/cjs/selectors/Search/types.d.ts +80 -7
  64. package/dist/cjs/selectors/Search/types.d.ts.map +1 -1
  65. package/dist/cjs/selectors/Search/types.js.map +1 -1
  66. package/dist/cjs/selectors/Singleton/types.d.ts +49 -0
  67. package/dist/cjs/selectors/Singleton/types.d.ts.map +1 -1
  68. package/dist/cjs/selectors/Singleton/types.js.map +1 -1
  69. package/dist/cjs/types/entities.d.ts +241 -2
  70. package/dist/cjs/types/entities.d.ts.map +1 -1
  71. package/dist/cjs/types/entities.js.map +1 -1
  72. package/dist/cjs/types/fields.d.ts +63 -0
  73. package/dist/cjs/types/fields.d.ts.map +1 -1
  74. package/dist/cjs/types/fields.js.map +1 -1
  75. package/dist/cjs/types/index.d.ts +514 -11
  76. package/dist/cjs/types/index.d.ts.map +1 -1
  77. package/dist/cjs/types/index.js +2 -0
  78. package/dist/cjs/types/index.js.map +1 -1
  79. package/dist/cjs/types/instances.d.ts +4 -0
  80. package/dist/cjs/types/instances.d.ts.map +1 -0
  81. package/dist/cjs/types/instances.js +3 -0
  82. package/dist/cjs/types/instances.js.map +1 -0
  83. package/dist/cjs/types/selectors.d.ts +8 -0
  84. package/dist/cjs/types/selectors.d.ts.map +1 -0
  85. package/dist/cjs/types/selectors.js +3 -0
  86. package/dist/cjs/types/selectors.js.map +1 -0
  87. package/dist/cjs/types/visual.d.ts +69 -0
  88. package/dist/cjs/types/visual.d.ts.map +1 -1
  89. package/dist/cjs/types/visual.js.map +1 -1
  90. package/dist/esm/client.d.ts +41 -2
  91. package/dist/esm/client.d.ts.map +1 -1
  92. package/dist/esm/client.js +39 -0
  93. package/dist/esm/client.js.map +1 -1
  94. package/dist/esm/errors.d.ts +35 -0
  95. package/dist/esm/errors.d.ts.map +1 -1
  96. package/dist/esm/errors.js +7 -0
  97. package/dist/esm/errors.js.map +1 -1
  98. package/dist/esm/index.d.ts +22 -1
  99. package/dist/esm/index.d.ts.map +1 -1
  100. package/dist/esm/index.js +21 -0
  101. package/dist/esm/index.js.map +1 -1
  102. package/dist/esm/instances/Collection/index.d.ts +4 -4
  103. package/dist/esm/instances/Collection/index.d.ts.map +1 -1
  104. package/dist/esm/instances/Collection/index.js.map +1 -1
  105. package/dist/esm/instances/Collection/types.d.ts +68 -12
  106. package/dist/esm/instances/Collection/types.d.ts.map +1 -1
  107. package/dist/esm/instances/Collection/types.js +1 -0
  108. package/dist/esm/instances/Collection/types.js.map +1 -1
  109. package/dist/esm/instances/Model/index.d.ts +3 -3
  110. package/dist/esm/instances/Model/index.d.ts.map +1 -1
  111. package/dist/esm/instances/Model/index.js.map +1 -1
  112. package/dist/esm/instances/Model/types.d.ts +86 -3
  113. package/dist/esm/instances/Model/types.d.ts.map +1 -1
  114. package/dist/esm/instances/Model/types.js.map +1 -1
  115. package/dist/esm/instances/ModelCategory/index.d.ts +2 -2
  116. package/dist/esm/instances/ModelCategory/index.d.ts.map +1 -1
  117. package/dist/esm/instances/ModelCategory/index.js.map +1 -1
  118. package/dist/esm/instances/ModelCategory/types.d.ts +62 -10
  119. package/dist/esm/instances/ModelCategory/types.d.ts.map +1 -1
  120. package/dist/esm/instances/ModelCategory/types.js.map +1 -1
  121. package/dist/esm/selectors/Collection/index.d.ts +3 -3
  122. package/dist/esm/selectors/Collection/index.d.ts.map +1 -1
  123. package/dist/esm/selectors/Collection/index.js +1 -1
  124. package/dist/esm/selectors/Collection/index.js.map +1 -1
  125. package/dist/esm/selectors/Collection/types.d.ts +84 -9
  126. package/dist/esm/selectors/Collection/types.d.ts.map +1 -1
  127. package/dist/esm/selectors/Collection/types.js.map +1 -1
  128. package/dist/esm/selectors/Entry/types.d.ts +105 -10
  129. package/dist/esm/selectors/Entry/types.d.ts.map +1 -1
  130. package/dist/esm/selectors/Entry/types.js.map +1 -1
  131. package/dist/esm/selectors/Media/index.js +2 -2
  132. package/dist/esm/selectors/Media/index.js.map +1 -1
  133. package/dist/esm/selectors/Media/types.d.ts +35 -1
  134. package/dist/esm/selectors/Media/types.d.ts.map +1 -1
  135. package/dist/esm/selectors/Media/types.js.map +1 -1
  136. package/dist/esm/selectors/Model/index.d.ts +3 -3
  137. package/dist/esm/selectors/Model/index.js.map +1 -1
  138. package/dist/esm/selectors/Model/types.d.ts +62 -3
  139. package/dist/esm/selectors/Model/types.d.ts.map +1 -1
  140. package/dist/esm/selectors/Model/types.js.map +1 -1
  141. package/dist/esm/selectors/ModelCategory/index.d.ts +3 -3
  142. package/dist/esm/selectors/ModelCategory/index.js +1 -1
  143. package/dist/esm/selectors/ModelCategory/index.js.map +1 -1
  144. package/dist/esm/selectors/ModelCategory/types.d.ts +50 -7
  145. package/dist/esm/selectors/ModelCategory/types.d.ts.map +1 -1
  146. package/dist/esm/selectors/ModelCategory/types.js.map +1 -1
  147. package/dist/esm/selectors/Search/index.d.ts +2 -2
  148. package/dist/esm/selectors/Search/index.d.ts.map +1 -1
  149. package/dist/esm/selectors/Search/index.js +1 -1
  150. package/dist/esm/selectors/Search/index.js.map +1 -1
  151. package/dist/esm/selectors/Search/types.d.ts +80 -7
  152. package/dist/esm/selectors/Search/types.d.ts.map +1 -1
  153. package/dist/esm/selectors/Search/types.js.map +1 -1
  154. package/dist/esm/selectors/Singleton/types.d.ts +49 -0
  155. package/dist/esm/selectors/Singleton/types.d.ts.map +1 -1
  156. package/dist/esm/selectors/Singleton/types.js.map +1 -1
  157. package/dist/esm/types/entities.d.ts +241 -2
  158. package/dist/esm/types/entities.d.ts.map +1 -1
  159. package/dist/esm/types/entities.js.map +1 -1
  160. package/dist/esm/types/fields.d.ts +63 -0
  161. package/dist/esm/types/fields.d.ts.map +1 -1
  162. package/dist/esm/types/fields.js.map +1 -1
  163. package/dist/esm/types/index.d.ts +514 -11
  164. package/dist/esm/types/index.d.ts.map +1 -1
  165. package/dist/esm/types/index.js +2 -0
  166. package/dist/esm/types/index.js.map +1 -1
  167. package/dist/esm/types/instances.d.ts +4 -0
  168. package/dist/esm/types/instances.d.ts.map +1 -0
  169. package/dist/esm/types/instances.js +2 -0
  170. package/dist/esm/types/instances.js.map +1 -0
  171. package/dist/esm/types/selectors.d.ts +8 -0
  172. package/dist/esm/types/selectors.d.ts.map +1 -0
  173. package/dist/esm/types/selectors.js +2 -0
  174. package/dist/esm/types/selectors.js.map +1 -0
  175. package/dist/esm/types/visual.d.ts +69 -0
  176. package/dist/esm/types/visual.d.ts.map +1 -1
  177. package/dist/esm/types/visual.js.map +1 -1
  178. package/package.json +1 -1
@@ -1,59 +1,562 @@
1
- import { CollectionTypes, SerializedData } from './entities';
2
- import { ProxiedModelSelector } from '../selectors/Model';
3
- import { ProxiedModelInstance } from '../instances/Model';
1
+ import { CollectionEntityTypes, SerializedData } from './entities';
2
+ import { DynamicModelSelector } from '../selectors/Model';
3
+ import { DynamicModelInstance } from '../instances/Model';
4
4
  import { SingletonSelector } from '../selectors/Singleton';
5
- import { ProxiedCollectionSelector } from '../selectors/Collection';
5
+ import { DynamicCollectionSelector } from '../selectors/Collection';
6
6
  import { MediaSelector } from '../selectors/Media';
7
7
  import { SearchSelector } from '../selectors/Search';
8
8
  import { CollectionInstance } from '../instances/Collection';
9
9
  export * from './fields';
10
10
  export * from './entities';
11
11
  export * from './visual';
12
- declare type BaseUrl = 'https://query.starlight.sh/v2' | string;
12
+ export * from './instances';
13
+ export * from './selectors';
14
+ /**
15
+ * This is a utility type that allows any string to be used as a URL, but
16
+ * provides a default one which can be used by IDEs to provide auto-completion.
17
+ * The default URL points to version 2 of the Query API.
18
+ */
19
+ export declare type BaseUrl = 'https://query.starlight.sh/v2' | string;
20
+ /**
21
+ * The available options to configure a {@link StarlightClient}.
22
+ *
23
+ * `workspace` is required when creating new clients or configuring the
24
+ * {@apilink default | default client}.
25
+ * @group Client
26
+ */
13
27
  export declare type StarlightConfig = {
28
+ /**
29
+ * The ID of the workspace that the client should use to request data.
30
+ *
31
+ * Note: the current APIs only support using workspace IDs as identifiers,
32
+ * and **not** slugs. Slug support will be added in the future. You can find
33
+ * the workspace ID in the left-side menu on the Starlight interface or below
34
+ * the workspace name in the workspace list.
35
+ */
14
36
  workspace?: string;
37
+ /**
38
+ * The Starlight Query API URL, including the version, and without a trailing
39
+ * slash. Defaults to the production Query API URL.
40
+ *
41
+ * You only need to set this if you're not using Starlight's production APIs.
42
+ */
15
43
  baseUrl?: BaseUrl;
44
+ /**
45
+ * When true, logs all API requests in the console. Defaults to false.
46
+ */
16
47
  debug?: boolean;
17
48
  };
49
+ /**
50
+ * The Starlight client is the main entry point for any requests you might want
51
+ * to make to Starlight's APIs.
52
+ *
53
+ * There's two ways of interacting with a client: using the
54
+ * {@apilink default | default client} exported by the SDK or creating a new
55
+ * client instance using the
56
+ * {@apilink makeStarlightClient | makeStarlightClient function}. Follow the
57
+ * provided links to learn how to use each method.
58
+ *
59
+ * Either way you choose to interact, all clients expose the same methods and
60
+ * accessors that provide ways to request data. These methods and accessors
61
+ * return Selector or Instance objects, which are documented in the sections
62
+ * of the same name found in this API's sidebar.
63
+ *
64
+ * @group Client
65
+ */
18
66
  export interface StarlightClient<D extends WorkspaceModelDefinition = DefaultModelDefinition> {
67
+ /**
68
+ * Updates the client configuration. See {@link StarlightConfig} to see all
69
+ * the available options.
70
+ *
71
+ * If you want to use the {@apilink default | default SDK client}, you need to
72
+ * set its workspace using this method in your application. You should run
73
+ * this method only once, and as soon as possible in your application
74
+ * lifecycle. For instance, when using React:
75
+ *
76
+ * ```js
77
+ * // src/index.js
78
+ * import { createRoot } from "react-dom/client"
79
+ * import Starlight from '@starlightcms/js-sdk'
80
+ * import MyApp from './MyApp.js'
81
+ *
82
+ * // We only need to run this once. In this case, we're
83
+ * // running it before initializing our React app.
84
+ * Starlight.configure({
85
+ * workspace: '1234567890'
86
+ * })
87
+ *
88
+ * const rootElement = document.getElementById("root")
89
+ * const root = createRoot(rootElement)
90
+ *
91
+ * root.render(<MyApp />)
92
+ * ```
93
+ *
94
+ * @param config A configuration object. See {@link StarlightConfig} to view
95
+ * all available options.
96
+ * @category Other Methods
97
+ */
19
98
  configure(config: StarlightConfig): void;
99
+ /**
100
+ * Logs a message (or any kind of data, really) into the console if the debug
101
+ * configuration is true. Uses `console.log` internally.
102
+ *
103
+ * This function's type definition is the same as the `console.log` function.
104
+ *
105
+ * @param message The data that will be logged.
106
+ * @param optionalParams Additional data to be logged or string substitutions.
107
+ * @see [MDN documentation on console.log](https://developer.mozilla.org/en-US/docs/web/api/console/log)
108
+ * @internal
109
+ */
20
110
  log(message?: unknown, ...optionalParams: unknown[]): void;
111
+ /**
112
+ * Returns the base API URL for requests, including the configured workspace.
113
+ * Doesn't include a trailing slash.
114
+ *
115
+ * @internal
116
+ */
21
117
  getBaseUrl(): string;
118
+ /**
119
+ * Returns a Promise that results in a response or throws a StarlightError.
120
+ * The response will be the parsed JSON data sent by the API.
121
+ *
122
+ * This method is used internally by all Selectors and Instances to request
123
+ * data to Starlight's Query API, but it can also be used standalone if
124
+ * desired.
125
+ *
126
+ * This method automatically prefixes the given path with the API URL, but it
127
+ * doesn't include a trailing slash, so be sure to include one at the start
128
+ * of your path.
129
+ *
130
+ * @param path The path to GET. Will be prefixed with the API URL. Must start
131
+ * with a forward slash (/).
132
+ * @param params An optional object of values that will be converted to a
133
+ * string and passed as GET params.
134
+ * @param options An optional configuration object passed to the fetch method.
135
+ * Check [MDN documentation on fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch)
136
+ * to see the available options.
137
+ * @typeParam T - The shape of the expected response on success. Client
138
+ * methods generally pass {@link StarlightItemResponse} or
139
+ * {@link StarlightListResponse} types here.
140
+ * @throws {@link StarlightError} on any errors.
141
+ * @category Other Methods
142
+ */
22
143
  get<T = Record<string, unknown>>(path: string, params?: Record<string, string | number | boolean | undefined>, options?: RequestInit): Promise<T>;
23
- get models(): ProxiedModelSelector<D>;
24
- model<S extends keyof D>(slug: S): ProxiedModelInstance<D[S]>;
144
+ /**
145
+ * Returns a {@link DynamicModelSelector}, which is a {@link ModelSelector}
146
+ * with support for creating {@apilink ModelInstance | ModelInstances} using the dynamic syntax.
147
+ *
148
+ * This is an accessor, which means that it should be used just like a common
149
+ * object parameter. For instance:
150
+ *
151
+ * ```ts
152
+ * import Starlight from '@starlightcms/js-sdk'
153
+ *
154
+ * const response = await Starlight.models.list()
155
+ * ```
156
+ *
157
+ * See {@link DynamicModelSelector} for more info.
158
+ *
159
+ * @category Selector Accessors
160
+ */
161
+ get models(): DynamicModelSelector<D>;
162
+ /**
163
+ * Returns a {@link DynamicModelInstance}, which is a
164
+ * {@link ModelInstance} with support for creating
165
+ * {@apilink ModelCategoryInstance | ModelCategoryInstances} using the dynamic syntax. For instance:
166
+ *
167
+ * ```ts
168
+ * import Starlight from '@starlightcms/js-sdk'
169
+ *
170
+ * const response = await Starlight.model('posts').entries.list()
171
+ * ```
172
+ *
173
+ * See {@link DynamicModelInstance} for more info.
174
+ *
175
+ * @category Instance Methods
176
+ */
177
+ model<S extends keyof D>(slug: S): DynamicModelInstance<D[S]>;
178
+ /**
179
+ * Returns a {@link SingletonSelector}.
180
+ *
181
+ * This is an accessor, which means that it should be used just like a common
182
+ * object parameter. For instance:
183
+ *
184
+ * ```ts
185
+ * import Starlight from '@starlightcms/js-sdk'
186
+ *
187
+ * const response = await Starlight.singletons.list()
188
+ * ```
189
+ *
190
+ * See {@link SingletonSelector} for more info.
191
+ *
192
+ * @category Selector Accessors
193
+ */
25
194
  get singletons(): SingletonSelector;
26
- get collections(): ProxiedCollectionSelector;
27
- collection<T extends CollectionTypes = string>(slug: string | number): CollectionInstance<T>;
195
+ /**
196
+ * Returns a {@link DynamicCollectionSelector}, which is a
197
+ * {@link CollectionSelector} with support for creating
198
+ * {@apilink CollectionInstance | CollectionInstances} using the dynamic syntax.
199
+ *
200
+ * This is an accessor, which means that it should be used just like a common
201
+ * object parameter. For instance:
202
+ *
203
+ * ```ts
204
+ * import Starlight from '@starlightcms/js-sdk'
205
+ *
206
+ * const response = await Starlight.collections.list()
207
+ * ```
208
+ *
209
+ * See {@link DynamicCollectionSelector} for more info.
210
+ *
211
+ * @category Selector Accessors
212
+ */
213
+ get collections(): DynamicCollectionSelector;
214
+ /**
215
+ * Returns a {@link CollectionInstance}. For instance:
216
+ *
217
+ * ```ts
218
+ * import Starlight from '@starlightcms/js-sdk'
219
+ *
220
+ * const response = await Starlight.collection('featured-posts').items()
221
+ * ```
222
+ *
223
+ * See {@link CollectionInstance} for more info.
224
+ *
225
+ * @example Typing the returned CollectionInstance.
226
+ * ```ts
227
+ * import Starlight, { MediaObject } from '@starlightcms/js-sdk'
228
+ *
229
+ * const response = await Starlight.collection<MediaObject>('carousel-images').items()
230
+ * ```
231
+ *
232
+ * @typeParam T - The type of entity this Collection holds. You can pass this
233
+ * type parameter to correctly type the response of the
234
+ * {@apilink CollectionInstance.items} method.
235
+ * @category Instance Methods
236
+ */
237
+ collection<T extends CollectionEntityTypes>(slug: string | number): CollectionInstance<T>;
238
+ /**
239
+ * Returns a {@link MediaSelector}.
240
+ *
241
+ * This is an accessor, which means that it should be used just like a common
242
+ * object parameter. For instance:
243
+ *
244
+ * ```ts
245
+ * import Starlight from '@starlightcms/js-sdk'
246
+ *
247
+ * const response = await Starlight.media.list()
248
+ * ```
249
+ *
250
+ * See {@link MediaSelector} for more info.
251
+ *
252
+ * @category Selector Accessors
253
+ */
28
254
  get media(): MediaSelector;
255
+ /**
256
+ * Returns a {@link SearchSelector}.
257
+ *
258
+ * This is an accessor, which means that it should be used just like a common
259
+ * object parameter. For instance:
260
+ *
261
+ * ```ts
262
+ * import Starlight from '@starlightcms/js-sdk'
263
+ *
264
+ * const response = await Starlight.search.entries()
265
+ * ```
266
+ *
267
+ * See {@link SearchSelector} for more info.
268
+ *
269
+ * @category Selector Accessors
270
+ */
29
271
  get search(): SearchSelector;
30
272
  }
31
- export declare type ProxiedStarlightClient<T extends WorkspaceModelDefinition> = StarlightClient<T> & {
32
- [K in keyof T]: ProxiedModelInstance<T[K]>;
273
+ /**
274
+ * This type adds support for the dynamic syntax to the StarlightClient
275
+ * interface, which allows users to create
276
+ * {@apilink DynamicModelInstance| DynamicModelInstances} dynamically.
277
+ * See {@link StarlightClient} to learn which methods it provides. Also see
278
+ * {@doclink requests-and-responses#dynamic-syntax | Dynamic Instances}
279
+ * documentation to learn more about the dynamic syntax.
280
+ *
281
+ *
282
+ * This allows TypeScript to correctly type all models defined by the user
283
+ * in the DefaultModelDefinition type, aside from letting the user using any
284
+ * "unknown" model slug, which is provided by the WorkspaceModelDefinition type.
285
+ *
286
+ * This type is only aware of the DefaultModelDefinition type because the
287
+ * StarlightClient uses it by default when no model definition type is passed.
288
+ *
289
+ * @group Client
290
+ */
291
+ export declare type DynamicStarlightClient<T extends WorkspaceModelDefinition> = StarlightClient<T> & {
292
+ [K in keyof T]: DynamicModelInstance<T[K]>;
33
293
  };
294
+ /**
295
+ * This interface represents an API response that returns a single entity, like
296
+ * a single {@link Entry} or a single {@link MediaObject}, for instance.
297
+ *
298
+ * It contains only one field: `data`. This field type is generic and
299
+ * depends on the kind of request that was made to the API.
300
+ *
301
+ * All SDK request methods that returna single entity
302
+ * will return this interface.
303
+ *
304
+ * @group Client
305
+ */
34
306
  export interface StarlightItemResponse<T> {
307
+ /**
308
+ * The entity returned by the API request. Its type depends on which request
309
+ * was made. SDK methods will generally type this parameter automatically.
310
+ */
35
311
  data: T;
36
312
  }
313
+ /**
314
+ * This interface represents an API response that returns a list of entities,
315
+ * like a list of {@apilink Entry | Entries} or a list of items from a
316
+ * {@link Collection}.
317
+ *
318
+ * It contains a `data` parameter, which is an array of items with a generic
319
+ * type that depends on the kind of request that was made, and two metadata
320
+ * objects: `links` and `meta`. Metadata is useful for pagination.
321
+ *
322
+ * All SDK request methods that return a list of entities will return this
323
+ * interface.
324
+ *
325
+ * @group Client
326
+ */
37
327
  export interface StarlightListResponse<T> {
328
+ /**
329
+ * The list of entities returned by the API request. Its type depends on which
330
+ * request was made. SDK methods will generally type
331
+ * this parameter automatically.
332
+ */
38
333
  data: T[];
334
+ /**
335
+ * An object containing useful links for easier pagination. All links points
336
+ * to the same list requested, but with a varying `page` parameter.
337
+ */
39
338
  links: {
339
+ /**
340
+ * A link for the first page of the list.
341
+ */
40
342
  first: string;
343
+ /**
344
+ * A link for the last page of the list.
345
+ */
41
346
  last: string;
347
+ /**
348
+ * A link to the previous page of the list, if there's any.
349
+ */
42
350
  prev?: string;
351
+ /**
352
+ * A link to the next page of the list, if there's any.
353
+ */
43
354
  next?: string;
44
355
  };
356
+ /**
357
+ * An object with useful metadata related to the current list. It can be used
358
+ * in applications to create pagination logic and interfaces.
359
+ *
360
+ * `from` and `to` are indexes indicating which items start and finish the
361
+ * current page of the list. For instance, in a list with 100 items with 15
362
+ * items per page, on the first page, `from` and `to` will be `1` and `15`
363
+ * respectively.
364
+ */
45
365
  meta: {
366
+ /**
367
+ * The number of the current page.
368
+ */
46
369
  current_page: number;
370
+ /**
371
+ * The number of the last page for the current list.
372
+ */
47
373
  last_page: number;
374
+ /**
375
+ * The index of the first item on this page out of all list items.
376
+ */
48
377
  from: number;
378
+ /**
379
+ * The index of the last item on this page out of all list items.
380
+ */
49
381
  to: number;
382
+ /**
383
+ * The number of items per page.
384
+ */
50
385
  per_page: number;
386
+ /**
387
+ * The total number of items in the current list.
388
+ */
51
389
  total: number;
52
390
  };
53
391
  }
392
+ /**
393
+ * The DefaultModelDefinition type is used to correctly type Entry data when
394
+ * requesting it using a StarlightClient.
395
+ *
396
+ * Without using a DefaultModelDefinition, Entry data will be typed as a
397
+ * "generic" JS object which can hold any kind of data:
398
+ *
399
+ * ```ts
400
+ * import Starlight from '@starlightcms/js-sdk'
401
+ *
402
+ * // response type will be StarlightItemResponse<Entry> on request success.
403
+ * const response = await Starlight.posts.entries.get('hello-world')
404
+ *
405
+ * // helloWorld type is Entry<Record<string, unknown>>. This means that
406
+ * // `data` can hold anything, which is not type-safe.
407
+ * const helloWorld = response.data
408
+ * ```
409
+ *
410
+ * One way of safely adding type information to Entry objects is by passing a
411
+ * data definition type to the EntrySelector when requesting something:
412
+ *
413
+ * ```ts
414
+ * import Starlight, { VisualField, MediaField } from '@starlightcms/js-sdk'
415
+ *
416
+ * type PostFields = {
417
+ * featured_image: MediaField
418
+ * content: VisualField
419
+ * }
420
+ *
421
+ * // response type will now be StarlightItemResponse<Entry<PostsFields>>.
422
+ * const response = await Starlight.posts.entries<PostFields>.get('hello-world')
423
+ *
424
+ * // Now, helloWorld type is Entry<PostsFields>.
425
+ * const helloWorld = response.data
426
+ *
427
+ * // Which means we can safely access its data, and IDEs will
428
+ * // auto-complete the data field name below:
429
+ * console.log(helloWorld.data.featured_image)
430
+ * ```
431
+ *
432
+ * Note that we used "Fields" to define our data shape. We recommend using these
433
+ * types, which are exported by this SDK, because they map to the field types
434
+ * available in the Starlight admin when creating models, and should simplify
435
+ * the type definition process. All available Field types are documented in the
436
+ * {@apilink BooleanField | Data Fields section of this API}.
437
+ *
438
+ * However, passing model definition types around your application is not ideal,
439
+ * and actually unnecessary. Using the DefaultModelDefinition type, all model
440
+ * definitions can be automatically inferred.
441
+ *
442
+ * To get started, you need to create a
443
+ * [type declaration file](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html)
444
+ * in which you'll define all your types. You can name it anything and place it
445
+ * anywhere inside your project, but we recommend naming it `starlight.d.ts` and
446
+ * placing it in the root folder of your source code, so it can be easily
447
+ * imported later in your application if you ever need to reference these types.
448
+ *
449
+ * In this file, you can place all your model type definitions (including type
450
+ * definitions for Singleton data, if you want!). Finally, you just need to
451
+ * add a "module definition block" that will tell the SDK which types you expect
452
+ * to receive when requesting models.
453
+ *
454
+ * Here's a complete exemple defining two models, Posts and Magazines:
455
+ *
456
+ * ```ts
457
+ * import { StringField, VisualField, MediaField } from '@starlightcms/js-sdk'
458
+ *
459
+ * type PostFields = {
460
+ * featured_image: MediaField
461
+ * content: VisualField
462
+ * }
463
+ *
464
+ * type MagazineFields = {
465
+ * cover_image: MediaField
466
+ * content: VisualField
467
+ * issue_number: StringField
468
+ * issue_year: StringField
469
+ * }
470
+ *
471
+ * declare module '@starlightcms/js-sdk' {
472
+ * export interface DefaultModelDefinition {
473
+ * // Notice that each key in this interface is a Model slug!
474
+ * posts: PostFields
475
+ * magazines: MagazineFields
476
+ * }
477
+ * }
478
+ * ```
479
+ *
480
+ * After creating this file, types should be automatically inferred without the
481
+ * need to pass these types around:
482
+ *
483
+ * ```ts
484
+ * import Starlight from '@starlightcms/js-sdk'
485
+ *
486
+ * // response type will be StarlightItemResponse<Entry<PostsFields>>,
487
+ * // which was implicitly inferred by the SDK!
488
+ * const response = await Starlight.posts.entries.get('hello-world')
489
+ *
490
+ * // helloWorld type is Entry<PostsFields>
491
+ * const helloWorld = response.data
492
+ *
493
+ * // Auto-complete will work just as before when we explicitly type the Entry!
494
+ * console.log(helloWorld.data.featured_image)
495
+ * ```
496
+ *
497
+ * @group Client
498
+ */
54
499
  export interface DefaultModelDefinition extends WorkspaceModelDefinition {
55
500
  }
501
+ /**
502
+ * This type is only used as a base for the DefaultModelDefinition type.
503
+ *
504
+ * @internal
505
+ */
56
506
  export interface WorkspaceModelDefinition {
57
507
  [slug: string]: SerializedData;
58
508
  }
509
+ /**
510
+ * Request parameters used by most SDK `list()` methods.
511
+ *
512
+ * @group Request Parameters
513
+ */
514
+ export interface BaseRequestParameters {
515
+ /**
516
+ * The page requested.
517
+ */
518
+ page?: number;
519
+ /**
520
+ * The limit of items per page.
521
+ */
522
+ limit?: number;
523
+ /**
524
+ * A search query string.
525
+ *
526
+ * For instance, searching for "out" will match both "check out!" and
527
+ * "about us". Search is not case-sensitive.
528
+ */
529
+ query?: string;
530
+ }
531
+ /**
532
+ * Request parameters used by most SDK methods that support advanced querying.
533
+ *
534
+ * @group Request Parameters
535
+ */
536
+ export interface QueryableRequestParameters {
537
+ /**
538
+ * A search query string that matches a specific word within boundaries.
539
+ * Search is not case-sensitive.
540
+ *
541
+ * For instance, searching for "phone" will match "This is my phone!"
542
+ * but won't match "This is my telephone!".
543
+ */
544
+ 'query:word'?: string;
545
+ /**
546
+ * A comma-separated list of fields to look up on when searching using
547
+ * `query` or `query:word`. If undefined, all text fields will be searched on,
548
+ * including Visual Editor fields. Search is not case-sensitive.
549
+ *
550
+ * For instance, to limit search on the "content" and "summary" fields of a
551
+ * model, pass `'content,summary'`.
552
+ */
553
+ fields?: string;
554
+ /**
555
+ * If defined, removes the given item from the list. Useful to create "related
556
+ * posts" lists.
557
+ *
558
+ * Note: this field only accepts IDs, and not slugs. Only one ID is allowed.
559
+ */
560
+ except?: number;
561
+ }
59
562
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAA;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AAExB,aAAK,OAAO,GAAG,+BAA+B,GAAG,MAAM,CAAA;AAEvD,oBAAY,eAAe,GAAG;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,MAAM,WAAW,eAAe,CAC9B,CAAC,SAAS,wBAAwB,GAAG,sBAAsB;IAE3D,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAAA;IAExC,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IAE1D,UAAU,IAAI,MAAM,CAAA;IAEpB,GAAG,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wBAAwB;IACvC,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAAA;CAC/B;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;GAIG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB"}
@@ -17,4 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./fields"), exports);
18
18
  __exportStar(require("./entities"), exports);
19
19
  __exportStar(require("./visual"), exports);
20
+ __exportStar(require("./instances"), exports);
21
+ __exportStar(require("./selectors"), exports);
20
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AASA,2CAAwB;AACxB,6CAA0B;AAC1B,2CAAwB","sourcesContent":["import { CollectionTypes, SerializedData } from './entities'\nimport { ProxiedModelSelector } from '../selectors/Model'\nimport { ProxiedModelInstance } from '../instances/Model'\nimport { SingletonSelector } from '../selectors/Singleton'\nimport { ProxiedCollectionSelector } from '../selectors/Collection'\nimport { MediaSelector } from '../selectors/Media'\nimport { SearchSelector } from '../selectors/Search'\nimport { CollectionInstance } from '../instances/Collection'\n\nexport * from './fields'\nexport * from './entities'\nexport * from './visual'\n\ntype BaseUrl = 'https://query.starlight.sh/v2' | string\n\nexport type StarlightConfig = {\n workspace?: string\n baseUrl?: BaseUrl\n debug?: boolean\n}\n\nexport interface StarlightClient<\n D extends WorkspaceModelDefinition = DefaultModelDefinition\n> {\n configure(config: StarlightConfig): void\n\n log(message?: unknown, ...optionalParams: unknown[]): void\n\n getBaseUrl(): string\n\n get<T = Record<string, unknown>>(\n path: string,\n params?: Record<string, string | number | boolean | undefined>,\n options?: RequestInit\n ): Promise<T>\n\n get models(): ProxiedModelSelector<D>\n\n model<S extends keyof D>(slug: S): ProxiedModelInstance<D[S]>\n\n get singletons(): SingletonSelector\n\n get collections(): ProxiedCollectionSelector\n\n collection<T extends CollectionTypes = string>(\n slug: string | number\n ): CollectionInstance<T>\n\n get media(): MediaSelector\n\n get search(): SearchSelector\n}\n\nexport type ProxiedStarlightClient<T extends WorkspaceModelDefinition> =\n StarlightClient<T> & {\n [K in keyof T]: ProxiedModelInstance<T[K]>\n }\n\nexport interface StarlightItemResponse<T> {\n data: T\n}\n\nexport interface StarlightListResponse<T> {\n data: T[]\n links: {\n first: string\n last: string\n prev?: string\n next?: string\n }\n meta: {\n current_page: number\n last_page: number\n from: number\n to: number\n per_page: number\n total: number\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface DefaultModelDefinition extends WorkspaceModelDefinition {}\n\nexport interface WorkspaceModelDefinition {\n [slug: string]: SerializedData\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AASA,2CAAwB;AACxB,6CAA0B;AAC1B,2CAAwB;AACxB,8CAA2B;AAC3B,8CAA2B","sourcesContent":["import { CollectionEntityTypes, SerializedData } from './entities'\nimport { DynamicModelSelector } from '../selectors/Model'\nimport { DynamicModelInstance } from '../instances/Model'\nimport { SingletonSelector } from '../selectors/Singleton'\nimport { DynamicCollectionSelector } from '../selectors/Collection'\nimport { MediaSelector } from '../selectors/Media'\nimport { SearchSelector } from '../selectors/Search'\nimport { CollectionInstance } from '../instances/Collection'\n\nexport * from './fields'\nexport * from './entities'\nexport * from './visual'\nexport * from './instances'\nexport * from './selectors'\n\n/**\n * This is a utility type that allows any string to be used as a URL, but\n * provides a default one which can be used by IDEs to provide auto-completion.\n * The default URL points to version 2 of the Query API.\n */\nexport type BaseUrl = 'https://query.starlight.sh/v2' | string\n\n/**\n * The available options to configure a {@link StarlightClient}.\n *\n * `workspace` is required when creating new clients or configuring the\n * {@apilink default | default client}.\n * @group Client\n */\nexport type StarlightConfig = {\n /**\n * The ID of the workspace that the client should use to request data.\n *\n * Note: the current APIs only support using workspace IDs as identifiers,\n * and **not** slugs. Slug support will be added in the future. You can find\n * the workspace ID in the left-side menu on the Starlight interface or below\n * the workspace name in the workspace list.\n */\n workspace?: string\n /**\n * The Starlight Query API URL, including the version, and without a trailing\n * slash. Defaults to the production Query API URL.\n *\n * You only need to set this if you're not using Starlight's production APIs.\n */\n baseUrl?: BaseUrl\n /**\n * When true, logs all API requests in the console. Defaults to false.\n */\n debug?: boolean\n}\n\n/**\n * The Starlight client is the main entry point for any requests you might want\n * to make to Starlight's APIs.\n *\n * There's two ways of interacting with a client: using the\n * {@apilink default | default client} exported by the SDK or creating a new\n * client instance using the\n * {@apilink makeStarlightClient | makeStarlightClient function}. Follow the\n * provided links to learn how to use each method.\n *\n * Either way you choose to interact, all clients expose the same methods and\n * accessors that provide ways to request data. These methods and accessors\n * return Selector or Instance objects, which are documented in the sections\n * of the same name found in this API's sidebar.\n *\n * @group Client\n */\nexport interface StarlightClient<\n D extends WorkspaceModelDefinition = DefaultModelDefinition\n> {\n /**\n * Updates the client configuration. See {@link StarlightConfig} to see all\n * the available options.\n *\n * If you want to use the {@apilink default | default SDK client}, you need to\n * set its workspace using this method in your application. You should run\n * this method only once, and as soon as possible in your application\n * lifecycle. For instance, when using React:\n *\n * ```js\n * // src/index.js\n * import { createRoot } from \"react-dom/client\"\n * import Starlight from '@starlightcms/js-sdk'\n * import MyApp from './MyApp.js'\n *\n * // We only need to run this once. In this case, we're\n * // running it before initializing our React app.\n * Starlight.configure({\n * workspace: '1234567890'\n * })\n *\n * const rootElement = document.getElementById(\"root\")\n * const root = createRoot(rootElement)\n *\n * root.render(<MyApp />)\n * ```\n *\n * @param config A configuration object. See {@link StarlightConfig} to view\n * all available options.\n * @category Other Methods\n */\n configure(config: StarlightConfig): void\n\n /**\n * Logs a message (or any kind of data, really) into the console if the debug\n * configuration is true. Uses `console.log` internally.\n *\n * This function's type definition is the same as the `console.log` function.\n *\n * @param message The data that will be logged.\n * @param optionalParams Additional data to be logged or string substitutions.\n * @see [MDN documentation on console.log](https://developer.mozilla.org/en-US/docs/web/api/console/log)\n * @internal\n */\n log(message?: unknown, ...optionalParams: unknown[]): void\n\n /**\n * Returns the base API URL for requests, including the configured workspace.\n * Doesn't include a trailing slash.\n *\n * @internal\n */\n getBaseUrl(): string\n\n /**\n * Returns a Promise that results in a response or throws a StarlightError.\n * The response will be the parsed JSON data sent by the API.\n *\n * This method is used internally by all Selectors and Instances to request\n * data to Starlight's Query API, but it can also be used standalone if\n * desired.\n *\n * This method automatically prefixes the given path with the API URL, but it\n * doesn't include a trailing slash, so be sure to include one at the start\n * of your path.\n *\n * @param path The path to GET. Will be prefixed with the API URL. Must start\n * with a forward slash (/).\n * @param params An optional object of values that will be converted to a\n * string and passed as GET params.\n * @param options An optional configuration object passed to the fetch method.\n * Check [MDN documentation on fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch)\n * to see the available options.\n * @typeParam T - The shape of the expected response on success. Client\n * methods generally pass {@link StarlightItemResponse} or\n * {@link StarlightListResponse} types here.\n * @throws {@link StarlightError} on any errors.\n * @category Other Methods\n */\n get<T = Record<string, unknown>>(\n path: string,\n params?: Record<string, string | number | boolean | undefined>,\n options?: RequestInit\n ): Promise<T>\n\n /**\n * Returns a {@link DynamicModelSelector}, which is a {@link ModelSelector}\n * with support for creating {@apilink ModelInstance | ModelInstances} using the dynamic syntax.\n *\n * This is an accessor, which means that it should be used just like a common\n * object parameter. For instance:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.models.list()\n * ```\n *\n * See {@link DynamicModelSelector} for more info.\n *\n * @category Selector Accessors\n */\n get models(): DynamicModelSelector<D>\n\n /**\n * Returns a {@link DynamicModelInstance}, which is a\n * {@link ModelInstance} with support for creating\n * {@apilink ModelCategoryInstance | ModelCategoryInstances} using the dynamic syntax. For instance:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.model('posts').entries.list()\n * ```\n *\n * See {@link DynamicModelInstance} for more info.\n *\n * @category Instance Methods\n */\n model<S extends keyof D>(slug: S): DynamicModelInstance<D[S]>\n\n /**\n * Returns a {@link SingletonSelector}.\n *\n * This is an accessor, which means that it should be used just like a common\n * object parameter. For instance:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.singletons.list()\n * ```\n *\n * See {@link SingletonSelector} for more info.\n *\n * @category Selector Accessors\n */\n get singletons(): SingletonSelector\n\n /**\n * Returns a {@link DynamicCollectionSelector}, which is a\n * {@link CollectionSelector} with support for creating\n * {@apilink CollectionInstance | CollectionInstances} using the dynamic syntax.\n *\n * This is an accessor, which means that it should be used just like a common\n * object parameter. For instance:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.collections.list()\n * ```\n *\n * See {@link DynamicCollectionSelector} for more info.\n *\n * @category Selector Accessors\n */\n get collections(): DynamicCollectionSelector\n\n /**\n * Returns a {@link CollectionInstance}. For instance:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.collection('featured-posts').items()\n * ```\n *\n * See {@link CollectionInstance} for more info.\n *\n * @example Typing the returned CollectionInstance.\n * ```ts\n * import Starlight, { MediaObject } from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.collection<MediaObject>('carousel-images').items()\n * ```\n *\n * @typeParam T - The type of entity this Collection holds. You can pass this\n * type parameter to correctly type the response of the\n * {@apilink CollectionInstance.items} method.\n * @category Instance Methods\n */\n collection<T extends CollectionEntityTypes>(\n slug: string | number\n ): CollectionInstance<T>\n\n /**\n * Returns a {@link MediaSelector}.\n *\n * This is an accessor, which means that it should be used just like a common\n * object parameter. For instance:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.media.list()\n * ```\n *\n * See {@link MediaSelector} for more info.\n *\n * @category Selector Accessors\n */\n get media(): MediaSelector\n\n /**\n * Returns a {@link SearchSelector}.\n *\n * This is an accessor, which means that it should be used just like a common\n * object parameter. For instance:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.search.entries()\n * ```\n *\n * See {@link SearchSelector} for more info.\n *\n * @category Selector Accessors\n */\n get search(): SearchSelector\n}\n\n/**\n * This type adds support for the dynamic syntax to the StarlightClient\n * interface, which allows users to create\n * {@apilink DynamicModelInstance| DynamicModelInstances} dynamically.\n * See {@link StarlightClient} to learn which methods it provides. Also see\n * {@doclink requests-and-responses#dynamic-syntax | Dynamic Instances}\n * documentation to learn more about the dynamic syntax.\n *\n *\n * This allows TypeScript to correctly type all models defined by the user\n * in the DefaultModelDefinition type, aside from letting the user using any\n * \"unknown\" model slug, which is provided by the WorkspaceModelDefinition type.\n *\n * This type is only aware of the DefaultModelDefinition type because the\n * StarlightClient uses it by default when no model definition type is passed.\n *\n * @group Client\n */\nexport type DynamicStarlightClient<T extends WorkspaceModelDefinition> =\n StarlightClient<T> & {\n [K in keyof T]: DynamicModelInstance<T[K]>\n }\n\n/**\n * This interface represents an API response that returns a single entity, like\n * a single {@link Entry} or a single {@link MediaObject}, for instance.\n *\n * It contains only one field: `data`. This field type is generic and\n * depends on the kind of request that was made to the API.\n *\n * All SDK request methods that returna single entity\n * will return this interface.\n *\n * @group Client\n */\nexport interface StarlightItemResponse<T> {\n /**\n * The entity returned by the API request. Its type depends on which request\n * was made. SDK methods will generally type this parameter automatically.\n */\n data: T\n}\n\n/**\n * This interface represents an API response that returns a list of entities,\n * like a list of {@apilink Entry | Entries} or a list of items from a\n * {@link Collection}.\n *\n * It contains a `data` parameter, which is an array of items with a generic\n * type that depends on the kind of request that was made, and two metadata\n * objects: `links` and `meta`. Metadata is useful for pagination.\n *\n * All SDK request methods that return a list of entities will return this\n * interface.\n *\n * @group Client\n */\nexport interface StarlightListResponse<T> {\n /**\n * The list of entities returned by the API request. Its type depends on which\n * request was made. SDK methods will generally type\n * this parameter automatically.\n */\n data: T[]\n /**\n * An object containing useful links for easier pagination. All links points\n * to the same list requested, but with a varying `page` parameter.\n */\n links: {\n /**\n * A link for the first page of the list.\n */\n first: string\n /**\n * A link for the last page of the list.\n */\n last: string\n /**\n * A link to the previous page of the list, if there's any.\n */\n prev?: string\n /**\n * A link to the next page of the list, if there's any.\n */\n next?: string\n }\n /**\n * An object with useful metadata related to the current list. It can be used\n * in applications to create pagination logic and interfaces.\n *\n * `from` and `to` are indexes indicating which items start and finish the\n * current page of the list. For instance, in a list with 100 items with 15\n * items per page, on the first page, `from` and `to` will be `1` and `15`\n * respectively.\n */\n meta: {\n /**\n * The number of the current page.\n */\n current_page: number\n /**\n * The number of the last page for the current list.\n */\n last_page: number\n /**\n * The index of the first item on this page out of all list items.\n */\n from: number\n /**\n * The index of the last item on this page out of all list items.\n */\n to: number\n /**\n * The number of items per page.\n */\n per_page: number\n /**\n * The total number of items in the current list.\n */\n total: number\n }\n}\n\n/**\n * The DefaultModelDefinition type is used to correctly type Entry data when\n * requesting it using a StarlightClient.\n *\n * Without using a DefaultModelDefinition, Entry data will be typed as a\n * \"generic\" JS object which can hold any kind of data:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * // response type will be StarlightItemResponse<Entry> on request success.\n * const response = await Starlight.posts.entries.get('hello-world')\n *\n * // helloWorld type is Entry<Record<string, unknown>>. This means that\n * // `data` can hold anything, which is not type-safe.\n * const helloWorld = response.data\n * ```\n *\n * One way of safely adding type information to Entry objects is by passing a\n * data definition type to the EntrySelector when requesting something:\n *\n * ```ts\n * import Starlight, { VisualField, MediaField } from '@starlightcms/js-sdk'\n *\n * type PostFields = {\n * featured_image: MediaField\n * content: VisualField\n * }\n *\n * // response type will now be StarlightItemResponse<Entry<PostsFields>>.\n * const response = await Starlight.posts.entries<PostFields>.get('hello-world')\n *\n * // Now, helloWorld type is Entry<PostsFields>.\n * const helloWorld = response.data\n *\n * // Which means we can safely access its data, and IDEs will\n * // auto-complete the data field name below:\n * console.log(helloWorld.data.featured_image)\n * ```\n *\n * Note that we used \"Fields\" to define our data shape. We recommend using these\n * types, which are exported by this SDK, because they map to the field types\n * available in the Starlight admin when creating models, and should simplify\n * the type definition process. All available Field types are documented in the\n * {@apilink BooleanField | Data Fields section of this API}.\n *\n * However, passing model definition types around your application is not ideal,\n * and actually unnecessary. Using the DefaultModelDefinition type, all model\n * definitions can be automatically inferred.\n *\n * To get started, you need to create a\n * [type declaration file](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html)\n * in which you'll define all your types. You can name it anything and place it\n * anywhere inside your project, but we recommend naming it `starlight.d.ts` and\n * placing it in the root folder of your source code, so it can be easily\n * imported later in your application if you ever need to reference these types.\n *\n * In this file, you can place all your model type definitions (including type\n * definitions for Singleton data, if you want!). Finally, you just need to\n * add a \"module definition block\" that will tell the SDK which types you expect\n * to receive when requesting models.\n *\n * Here's a complete exemple defining two models, Posts and Magazines:\n *\n * ```ts\n * import { StringField, VisualField, MediaField } from '@starlightcms/js-sdk'\n *\n * type PostFields = {\n * featured_image: MediaField\n * content: VisualField\n * }\n *\n * type MagazineFields = {\n * cover_image: MediaField\n * content: VisualField\n * issue_number: StringField\n * issue_year: StringField\n * }\n *\n * declare module '@starlightcms/js-sdk' {\n * export interface DefaultModelDefinition {\n * // Notice that each key in this interface is a Model slug!\n * posts: PostFields\n * magazines: MagazineFields\n * }\n * }\n * ```\n *\n * After creating this file, types should be automatically inferred without the\n * need to pass these types around:\n *\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * // response type will be StarlightItemResponse<Entry<PostsFields>>,\n * // which was implicitly inferred by the SDK!\n * const response = await Starlight.posts.entries.get('hello-world')\n *\n * // helloWorld type is Entry<PostsFields>\n * const helloWorld = response.data\n *\n * // Auto-complete will work just as before when we explicitly type the Entry!\n * console.log(helloWorld.data.featured_image)\n * ```\n *\n * @group Client\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface DefaultModelDefinition extends WorkspaceModelDefinition {}\n\n/**\n * This type is only used as a base for the DefaultModelDefinition type.\n *\n * @internal\n */\nexport interface WorkspaceModelDefinition {\n [slug: string]: SerializedData\n}\n\n/**\n * Request parameters used by most SDK `list()` methods.\n *\n * @group Request Parameters\n */\nexport interface BaseRequestParameters {\n /**\n * The page requested.\n */\n page?: number\n /**\n * The limit of items per page.\n */\n limit?: number\n /**\n * A search query string.\n *\n * For instance, searching for \"out\" will match both \"check out!\" and\n * \"about us\". Search is not case-sensitive.\n */\n query?: string\n}\n\n/**\n * Request parameters used by most SDK methods that support advanced querying.\n *\n * @group Request Parameters\n */\nexport interface QueryableRequestParameters {\n /**\n * A search query string that matches a specific word within boundaries.\n * Search is not case-sensitive.\n *\n * For instance, searching for \"phone\" will match \"This is my phone!\"\n * but won't match \"This is my telephone!\".\n */\n 'query:word'?: string\n /**\n * A comma-separated list of fields to look up on when searching using\n * `query` or `query:word`. If undefined, all text fields will be searched on,\n * including Visual Editor fields. Search is not case-sensitive.\n *\n * For instance, to limit search on the \"content\" and \"summary\" fields of a\n * model, pass `'content,summary'`.\n */\n fields?: string\n /**\n * If defined, removes the given item from the list. Useful to create \"related\n * posts\" lists.\n *\n * Note: this field only accepts IDs, and not slugs. Only one ID is allowed.\n */\n except?: number\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export { CollectionInstance, ListCollectionItemsParams, } from '../instances/Collection';
2
+ export { DynamicModelInstance, ModelInstance } from '../instances/Model';
3
+ export { ModelCategoryInstance, ModelCategoryEntryListParams, } from '../instances/ModelCategory';
4
+ //# sourceMappingURL=instances.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instances.d.ts","sourceRoot":"","sources":["../../../src/types/instances.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACxE,OAAO,EACL,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,4BAA4B,CAAA"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=instances.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instances.js","sourceRoot":"","sources":["../../../src/types/instances.ts"],"names":[],"mappings":"","sourcesContent":["// Instance types are exported here so they are visible in the API docs.\nexport {\n CollectionInstance,\n ListCollectionItemsParams,\n} from '../instances/Collection'\nexport { DynamicModelInstance, ModelInstance } from '../instances/Model'\nexport {\n ModelCategoryInstance,\n ModelCategoryEntryListParams,\n} from '../instances/ModelCategory'\n"]}