@starlightcms/js-sdk 0.9.0 → 0.10.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 (115) hide show
  1. package/dist/cjs/client.d.ts +41 -2
  2. package/dist/cjs/client.d.ts.map +1 -1
  3. package/dist/cjs/client.js +39 -0
  4. package/dist/cjs/client.js.map +1 -1
  5. package/dist/cjs/errors.d.ts +12 -0
  6. package/dist/cjs/errors.d.ts.map +1 -1
  7. package/dist/cjs/errors.js +7 -0
  8. package/dist/cjs/errors.js.map +1 -1
  9. package/dist/cjs/index.d.ts +21 -1
  10. package/dist/cjs/index.d.ts.map +1 -1
  11. package/dist/cjs/index.js +20 -0
  12. package/dist/cjs/index.js.map +1 -1
  13. package/dist/cjs/instances/Collection/index.d.ts +2 -2
  14. package/dist/cjs/instances/Collection/index.d.ts.map +1 -1
  15. package/dist/cjs/instances/Collection/index.js.map +1 -1
  16. package/dist/cjs/instances/Collection/types.d.ts +49 -5
  17. package/dist/cjs/instances/Collection/types.d.ts.map +1 -1
  18. package/dist/cjs/instances/Collection/types.js.map +1 -1
  19. package/dist/cjs/instances/Model/index.d.ts +3 -3
  20. package/dist/cjs/instances/Model/index.d.ts.map +1 -1
  21. package/dist/cjs/instances/Model/index.js.map +1 -1
  22. package/dist/cjs/instances/Model/types.d.ts +3 -3
  23. package/dist/cjs/instances/Model/types.js.map +1 -1
  24. package/dist/cjs/selectors/Collection/index.d.ts +3 -3
  25. package/dist/cjs/selectors/Collection/index.js.map +1 -1
  26. package/dist/cjs/selectors/Collection/types.d.ts +2 -2
  27. package/dist/cjs/selectors/Collection/types.d.ts.map +1 -1
  28. package/dist/cjs/selectors/Collection/types.js.map +1 -1
  29. package/dist/cjs/selectors/Model/index.d.ts +3 -3
  30. package/dist/cjs/selectors/Model/index.js.map +1 -1
  31. package/dist/cjs/selectors/Model/types.d.ts +3 -3
  32. package/dist/cjs/selectors/Model/types.js.map +1 -1
  33. package/dist/cjs/selectors/ModelCategory/index.d.ts +3 -3
  34. package/dist/cjs/selectors/ModelCategory/index.js.map +1 -1
  35. package/dist/cjs/selectors/ModelCategory/types.d.ts +1 -1
  36. package/dist/cjs/selectors/ModelCategory/types.js.map +1 -1
  37. package/dist/cjs/types/entities.d.ts +158 -0
  38. package/dist/cjs/types/entities.d.ts.map +1 -1
  39. package/dist/cjs/types/entities.js.map +1 -1
  40. package/dist/cjs/types/fields.d.ts +63 -0
  41. package/dist/cjs/types/fields.d.ts.map +1 -1
  42. package/dist/cjs/types/fields.js.map +1 -1
  43. package/dist/cjs/types/index.d.ts +424 -11
  44. package/dist/cjs/types/index.d.ts.map +1 -1
  45. package/dist/cjs/types/index.js +2 -0
  46. package/dist/cjs/types/index.js.map +1 -1
  47. package/dist/cjs/types/instances.d.ts +4 -0
  48. package/dist/cjs/types/instances.d.ts.map +1 -0
  49. package/dist/cjs/types/instances.js +3 -0
  50. package/dist/cjs/types/instances.js.map +1 -0
  51. package/dist/cjs/types/selectors.d.ts +8 -0
  52. package/dist/cjs/types/selectors.d.ts.map +1 -0
  53. package/dist/cjs/types/selectors.js +3 -0
  54. package/dist/cjs/types/selectors.js.map +1 -0
  55. package/dist/cjs/types/visual.d.ts +69 -0
  56. package/dist/cjs/types/visual.d.ts.map +1 -1
  57. package/dist/cjs/types/visual.js.map +1 -1
  58. package/dist/esm/client.d.ts +41 -2
  59. package/dist/esm/client.d.ts.map +1 -1
  60. package/dist/esm/client.js +39 -0
  61. package/dist/esm/client.js.map +1 -1
  62. package/dist/esm/errors.d.ts +12 -0
  63. package/dist/esm/errors.d.ts.map +1 -1
  64. package/dist/esm/errors.js +7 -0
  65. package/dist/esm/errors.js.map +1 -1
  66. package/dist/esm/index.d.ts +21 -1
  67. package/dist/esm/index.d.ts.map +1 -1
  68. package/dist/esm/index.js +20 -0
  69. package/dist/esm/index.js.map +1 -1
  70. package/dist/esm/instances/Collection/index.d.ts +2 -2
  71. package/dist/esm/instances/Collection/index.d.ts.map +1 -1
  72. package/dist/esm/instances/Collection/index.js.map +1 -1
  73. package/dist/esm/instances/Collection/types.d.ts +49 -5
  74. package/dist/esm/instances/Collection/types.d.ts.map +1 -1
  75. package/dist/esm/instances/Collection/types.js.map +1 -1
  76. package/dist/esm/instances/Model/index.d.ts +3 -3
  77. package/dist/esm/instances/Model/index.d.ts.map +1 -1
  78. package/dist/esm/instances/Model/index.js.map +1 -1
  79. package/dist/esm/instances/Model/types.d.ts +3 -3
  80. package/dist/esm/instances/Model/types.js.map +1 -1
  81. package/dist/esm/selectors/Collection/index.d.ts +3 -3
  82. package/dist/esm/selectors/Collection/index.js.map +1 -1
  83. package/dist/esm/selectors/Collection/types.d.ts +2 -2
  84. package/dist/esm/selectors/Collection/types.d.ts.map +1 -1
  85. package/dist/esm/selectors/Collection/types.js.map +1 -1
  86. package/dist/esm/selectors/Model/index.d.ts +3 -3
  87. package/dist/esm/selectors/Model/index.js.map +1 -1
  88. package/dist/esm/selectors/Model/types.d.ts +3 -3
  89. package/dist/esm/selectors/Model/types.js.map +1 -1
  90. package/dist/esm/selectors/ModelCategory/index.d.ts +3 -3
  91. package/dist/esm/selectors/ModelCategory/index.js.map +1 -1
  92. package/dist/esm/selectors/ModelCategory/types.d.ts +1 -1
  93. package/dist/esm/selectors/ModelCategory/types.js.map +1 -1
  94. package/dist/esm/types/entities.d.ts +158 -0
  95. package/dist/esm/types/entities.d.ts.map +1 -1
  96. package/dist/esm/types/entities.js.map +1 -1
  97. package/dist/esm/types/fields.d.ts +63 -0
  98. package/dist/esm/types/fields.d.ts.map +1 -1
  99. package/dist/esm/types/fields.js.map +1 -1
  100. package/dist/esm/types/index.d.ts +424 -11
  101. package/dist/esm/types/index.d.ts.map +1 -1
  102. package/dist/esm/types/index.js +2 -0
  103. package/dist/esm/types/index.js.map +1 -1
  104. package/dist/esm/types/instances.d.ts +4 -0
  105. package/dist/esm/types/instances.d.ts.map +1 -0
  106. package/dist/esm/types/instances.js +2 -0
  107. package/dist/esm/types/instances.js.map +1 -0
  108. package/dist/esm/types/selectors.d.ts +8 -0
  109. package/dist/esm/types/selectors.d.ts.map +1 -0
  110. package/dist/esm/types/selectors.js +2 -0
  111. package/dist/esm/types/selectors.js.map +1 -0
  112. package/dist/esm/types/visual.d.ts +69 -0
  113. package/dist/esm/types/visual.d.ts.map +1 -1
  114. package/dist/esm/types/visual.js.map +1 -1
  115. package/package.json +1 -1
@@ -1,58 +1,471 @@
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
+ */
18
+ export declare type BaseUrl = 'https://query.starlight.sh/v2' | string;
19
+ /**
20
+ * @group Client
21
+ */
13
22
  export declare type StarlightConfig = {
14
23
  workspace?: string;
15
24
  baseUrl?: BaseUrl;
16
25
  debug?: boolean;
17
26
  };
27
+ /**
28
+ * The Starlight client is the main entry point for any requests you might want
29
+ * to make to Starlight's APIs.
30
+ *
31
+ * There's two ways of interacting with a client: using the
32
+ * {@apilink default | default client} exported by the SDK or creating a new
33
+ * client instance using the
34
+ * {@apilink makeStarlightClient | makeStarlightClient function}. Follow the
35
+ * provided links to learn how to use each method.
36
+ *
37
+ * Either way you choose to interact, all clients expose the same methods and
38
+ * accessors that provide ways to request data. These methods and accessors
39
+ * return Selector or Instance objects, which are documented in the sections
40
+ * of the same name found in this API's sidebar.
41
+ *
42
+ * @group Client
43
+ */
18
44
  export interface StarlightClient<D extends WorkspaceModelDefinition = DefaultModelDefinition> {
45
+ /**
46
+ * Updates the client configuration. See {@link StarlightConfig} to see all
47
+ * the available options.
48
+ *
49
+ * If you want to use the {@apilink default | default SDK client}, you need to
50
+ * set its workspace using this method in your application. You should run
51
+ * this method only once, and as soon as possible in your application
52
+ * lifecycle. For instance, when using React:
53
+ *
54
+ * ```js
55
+ * // src/index.js
56
+ * import { createRoot } from "react-dom/client"
57
+ * import Starlight from '@starlightcms/js-sdk'
58
+ * import MyApp from './MyApp.js'
59
+ *
60
+ * // We only need to run this once. In this case, we're
61
+ * // running it before initializing our React app.
62
+ * Starlight.configure({
63
+ * workspace: '1234567890'
64
+ * })
65
+ *
66
+ * const rootElement = document.getElementById("root")
67
+ * const root = createRoot(rootElement)
68
+ *
69
+ * root.render(<App />)
70
+ * ```
71
+ *
72
+ * @param config A configuration object. Required.
73
+ * @category Other Methods
74
+ */
19
75
  configure(config: StarlightConfig): void;
76
+ /**
77
+ * Logs a message (or any kind of data, really) into the console if the debug
78
+ * configuration is true. Uses `console.log` internally.
79
+ *
80
+ * This function's type definition is the same as the `console.log` function.
81
+ *
82
+ * @param message The data that will be logged.
83
+ * @param optionalParams Additional data to be logged or string substitutions.
84
+ * @see [MDN documentation on console.log](https://developer.mozilla.org/en-US/docs/web/api/console/log)
85
+ * @internal
86
+ */
20
87
  log(message?: unknown, ...optionalParams: unknown[]): void;
88
+ /**
89
+ * Returns the base API URL for requests, including the configured workspace.
90
+ * Doesn't include a trailing slash.
91
+ *
92
+ * @internal
93
+ */
21
94
  getBaseUrl(): string;
95
+ /**
96
+ * Returns a Promise that results in a response or throws an StarlightError.
97
+ * The response will be the parsed JSON data sent by the API.
98
+ *
99
+ * This method is used internally by all Selectors and Instances to request
100
+ * data to Starlight's Query API, but it can also be used standalone if
101
+ * desired.
102
+ *
103
+ * This method automatically prefixes the given path with the API URL, but it
104
+ * doesn't include a trailing slash, so be sure to include one at the start
105
+ * of your path.
106
+ *
107
+ * @param path The path to GET. Will be prefixed with the API URL. Must start
108
+ * with a forward slash (/).
109
+ * @param params An optional object of values that will be converted to a
110
+ * string and passed as GET params.
111
+ * @param options An optional configuration object passed to the fetch method.
112
+ * Check [MDN documentation on fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch)
113
+ * to see the available options.
114
+ * @typeParam T - The shape of the expected response on success. Client
115
+ * methods generally pass {@link StarlightItemResponse} or
116
+ * {@link StarlightListResponse} types here.
117
+ * @throws {@link StarlightError} on any errors.
118
+ * @category Other Methods
119
+ */
22
120
  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]>;
121
+ /**
122
+ * Returns a {@link DynamicModelSelector}, which is a {@link ModelSelector}
123
+ * with support for creating {@link ModelInstance}s using the dynamic syntax.
124
+ *
125
+ * This is an accessor, which means that it should be used just like a common
126
+ * object parameter. For instance:
127
+ *
128
+ * ```ts
129
+ * import Starlight from '@starlightcms/js-sdk'
130
+ *
131
+ * const response = await Starlight.models.list()
132
+ * ```
133
+ *
134
+ * See {@link DynamicModelSelector} for more info.
135
+ *
136
+ * @category Selector Accessors
137
+ */
138
+ get models(): DynamicModelSelector<D>;
139
+ /**
140
+ * Returns a {@link DynamicModelInstance}, which is a
141
+ * {@link ModelInstance} with support for creating
142
+ * {@link ModelCategoryInstance}s using the dynamic syntax. For instance:
143
+ *
144
+ * ```ts
145
+ * import Starlight from '@starlightcms/js-sdk'
146
+ *
147
+ * const response = await Starlight.model('posts').entries.list()
148
+ * ```
149
+ *
150
+ * See {@link DynamicModelInstance} for more info.
151
+ *
152
+ * @category Instance Methods
153
+ */
154
+ model<S extends keyof D>(slug: S): DynamicModelInstance<D[S]>;
155
+ /**
156
+ * Returns a {@link SingletonSelector}.
157
+ *
158
+ * This is an accessor, which means that it should be used just like a common
159
+ * object parameter. For instance:
160
+ *
161
+ * ```ts
162
+ * import Starlight from '@starlightcms/js-sdk'
163
+ *
164
+ * const response = await Starlight.singletons.list()
165
+ * ```
166
+ *
167
+ * See {@link SingletonSelector} for more info.
168
+ *
169
+ * @category Selector Accessors
170
+ */
25
171
  get singletons(): SingletonSelector;
26
- get collections(): ProxiedCollectionSelector;
27
- collection<T extends CollectionTypes = string>(slug: string | number): CollectionInstance<T>;
172
+ /**
173
+ * Returns a {@link DynamicCollectionSelector}, which is a
174
+ * {@link CollectionSelector} with support for creating
175
+ * {@link CollectionInstance}s using the dynamic syntax.
176
+ *
177
+ * This is an accessor, which means that it should be used just like a common
178
+ * object parameter. For instance:
179
+ *
180
+ * ```ts
181
+ * import Starlight from '@starlightcms/js-sdk'
182
+ *
183
+ * const response = await Starlight.collections.list()
184
+ * ```
185
+ *
186
+ * See {@link DynamicCollectionSelector} for more info.
187
+ *
188
+ * @category Selector Accessors
189
+ */
190
+ get collections(): DynamicCollectionSelector;
191
+ /**
192
+ * Returns a {@link CollectionInstance}. For instance:
193
+ *
194
+ * ```ts
195
+ * import Starlight from '@starlightcms/js-sdk'
196
+ *
197
+ * const response = await Starlight.collection('featured-posts').items()
198
+ * ```
199
+ *
200
+ * See {@link CollectionInstance} for more info.
201
+ *
202
+ * @category Instance Methods
203
+ */
204
+ collection<T extends CollectionEntityTypes>(slug: string | number): CollectionInstance<T>;
205
+ /**
206
+ * Returns a {@link MediaSelector}.
207
+ *
208
+ * This is an accessor, which means that it should be used just like a common
209
+ * object parameter. For instance:
210
+ *
211
+ * ```ts
212
+ * import Starlight from '@starlightcms/js-sdk'
213
+ *
214
+ * const response = await Starlight.media.list()
215
+ * ```
216
+ *
217
+ * See {@link MediaSelector} for more info.
218
+ *
219
+ * @category Selector Accessors
220
+ */
28
221
  get media(): MediaSelector;
222
+ /**
223
+ * Returns a {@link SearchSelector}.
224
+ *
225
+ * This is an accessor, which means that it should be used just like a common
226
+ * object parameter. For instance:
227
+ *
228
+ * ```ts
229
+ * import Starlight from '@starlightcms/js-sdk'
230
+ *
231
+ * const response = await Starlight.search.entries()
232
+ * ```
233
+ *
234
+ * See {@link SearchSelector} for more info.
235
+ *
236
+ * @category Selector Accessors
237
+ */
29
238
  get search(): SearchSelector;
30
239
  }
31
- export declare type ProxiedStarlightClient<T extends WorkspaceModelDefinition> = StarlightClient<T> & {
32
- [K in keyof T]: ProxiedModelInstance<T[K]>;
240
+ /**
241
+ * This type adds support for the dynamic syntax to the StarlightClient
242
+ * interface, which allows users to create {@link ModelInstance}s dynamically.
243
+ * See {@link StarlightClient} to learn which methods it provides.
244
+ *
245
+ * This allows TypeScript to correctly type all models defined by the user
246
+ * in the DefaultModelDefinition type, aside from letting the user using any
247
+ * "unknown" model slug, which is provided by the WorkspaceModelDefinition type.
248
+ *
249
+ * This type is only aware of the DefaultModelDefinition type because the
250
+ * StarlightClient uses it by default when no model definition type is passed.
251
+ *
252
+ * @group Client
253
+ */
254
+ export declare type DynamicStarlightClient<T extends WorkspaceModelDefinition> = StarlightClient<T> & {
255
+ [K in keyof T]: DynamicModelInstance<T[K]>;
33
256
  };
257
+ /**
258
+ * This interface represents an API response that returns a single entity, like
259
+ * a single {@link Entry} or a single {@link MediaObject}, for instance.
260
+ *
261
+ * It contains only one field: `data`. This field type is generic and
262
+ * depends on the kind of request that was made to the API.
263
+ *
264
+ * All SDK request methods that returna single entity
265
+ * will return this interface.
266
+ *
267
+ * @group Client
268
+ */
34
269
  export interface StarlightItemResponse<T> {
270
+ /**
271
+ * The entity returned by the API request. Its type depends on which request
272
+ * was made. SDK methods will generally type this parameter automatically.
273
+ */
35
274
  data: T;
36
275
  }
276
+ /**
277
+ * This interface represents an API response that returns a list of entities,
278
+ * like a list of {@apilink Entry | Entries} or a list of items from a
279
+ * {@link Collection}.
280
+ *
281
+ * It contains a `data` parameter, which is an array of items with a generic
282
+ * type that depends on the kind of request that was made, and two metadata
283
+ * objects: `links` and `meta`. Metadata is useful for pagination.
284
+ *
285
+ * All SDK request methods that return a list of entities will return this
286
+ * interface.
287
+ *
288
+ * @group Client
289
+ */
37
290
  export interface StarlightListResponse<T> {
291
+ /**
292
+ * The list of entities returned by the API request. Its type depends on which
293
+ * request was made. SDK methods will generally type
294
+ * this parameter automatically.
295
+ */
38
296
  data: T[];
297
+ /**
298
+ * An object containing useful links for easier pagination. All links points
299
+ * to the same list requested, but with a varying `page` parameter.
300
+ */
39
301
  links: {
302
+ /**
303
+ * A link for the first page of the list.
304
+ */
40
305
  first: string;
306
+ /**
307
+ * A link for the last page of the list.
308
+ */
41
309
  last: string;
310
+ /**
311
+ * A link to the previous page of the list, if there's any.
312
+ */
42
313
  prev?: string;
314
+ /**
315
+ * A link to the next page of the list, if there's any.
316
+ */
43
317
  next?: string;
44
318
  };
319
+ /**
320
+ * An object with useful metadata related to the current list. It can be used
321
+ * in applications to create pagination logic and interfaces.
322
+ *
323
+ * `from` and `to` are indexes indicating which items start and finish the
324
+ * current page of the list. For instance, in a list with 100 items with 15
325
+ * items per page, on the first page, `from` and `to` will be `1` and `15`
326
+ * respectively.
327
+ */
45
328
  meta: {
329
+ /**
330
+ * The number of the current page.
331
+ */
46
332
  current_page: number;
333
+ /**
334
+ * The number of the last page for the current list.
335
+ */
47
336
  last_page: number;
337
+ /**
338
+ * The index of the first item on this page out of all list items.
339
+ */
48
340
  from: number;
341
+ /**
342
+ * The index of the last item on this page out of all list items.
343
+ */
49
344
  to: number;
345
+ /**
346
+ * The number of items per page.
347
+ */
50
348
  per_page: number;
349
+ /**
350
+ * The total number of items in the current list.
351
+ */
51
352
  total: number;
52
353
  };
53
354
  }
355
+ /**
356
+ * The DefaultModelDefinition type is used to correctly type Entry data when
357
+ * requesting it using a StarlightClient.
358
+ *
359
+ * Without using a DefaultModelDefinition, Entry data will be typed as a
360
+ * "generic" JS object which can hold any kind of data:
361
+ *
362
+ * ```ts
363
+ * import Starlight from '@starlightcms/js-sdk'
364
+ *
365
+ * // response type will be StarlightItemResponse<Entry> on request success.
366
+ * const response = await Starlight.posts.entries.get('hello-world')
367
+ *
368
+ * // helloWorld type is Entry<Record<string, unknown>>. This means that
369
+ * // `data` can hold anything, which is not type-safe.
370
+ * const helloWorld = response.data
371
+ * ```
372
+ *
373
+ * One way of safely adding type information to Entry objects is by passing a
374
+ * data definition type to the EntrySelector when requesting something:
375
+ *
376
+ * ```ts
377
+ * import Starlight, { VisualField, MediaField } from '@starlightcms/js-sdk'
378
+ *
379
+ * type PostFields = {
380
+ * featured_image: MediaField
381
+ * content: VisualField
382
+ * }
383
+ *
384
+ * // response type will now be StarlightItemResponse<Entry<PostsFields>>.
385
+ * const response = await Starlight.posts.entries<PostFields>.get('hello-world')
386
+ *
387
+ * // Now, helloWorld type is Entry<PostsFields>.
388
+ * const helloWorld = response.data
389
+ *
390
+ * // Which means we can safely access its data, and IDEs will
391
+ * // auto-complete the data field name below:
392
+ * console.log(helloWorld.data.featured_image)
393
+ * ```
394
+ *
395
+ * Note that we used "Fields" to define our data shape. We recommend using these
396
+ * types, which are exported by this SDK, because they map to the field types
397
+ * available in the Starlight admin when creating models, and should simplify
398
+ * the type definition process. All available Field types are documented in the
399
+ * {@apilink BooleanField | Data Fields section of this API}.
400
+ *
401
+ * However, passing model definition types around your application is not ideal,
402
+ * and actually unnecessary. Using the DefaultModelDefinition type, all model
403
+ * definitions can be automatically inferred.
404
+ *
405
+ * To get started, you need to create a
406
+ * [type declaration file](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html)
407
+ * in which you'll define all your types. You can name it anything and place it
408
+ * anywhere inside your project, but we recommend naming it `starlight.d.ts` and
409
+ * placing it in the root folder of your source code, so it can be easily
410
+ * imported later in your application if you ever need to reference these types.
411
+ *
412
+ * In this file, you can place all your model type definitions (including type
413
+ * definitions for Singleton data, if you want!). Finally, you just need to
414
+ * add a "module definition block" that will tell the SDK which types you expect
415
+ * to receive when requesting models.
416
+ *
417
+ * Here's a complete exemple defining two models, Posts and Magazines:
418
+ *
419
+ * ```ts
420
+ * import { StringField, VisualField, MediaField } from '@starlightcms/js-sdk'
421
+ *
422
+ * type PostFields = {
423
+ * featured_image: MediaField
424
+ * content: VisualField
425
+ * }
426
+ *
427
+ * type MagazineFields = {
428
+ * cover_image: MediaField
429
+ * content: VisualField
430
+ * issue_number: StringField
431
+ * issue_year: StringField
432
+ * }
433
+ *
434
+ * declare module '@starlightcms/js-sdk' {
435
+ * export interface DefaultModelDefinition {
436
+ * // Notice that each key in this interface is a Model slug!
437
+ * posts: PostFields
438
+ * magazines: MagazineFields
439
+ * }
440
+ * }
441
+ * ```
442
+ *
443
+ * After creating this file, types should be automatically inferred without the
444
+ * need to pass these types around:
445
+ *
446
+ * ```ts
447
+ * import Starlight from '@starlightcms/js-sdk'
448
+ *
449
+ * // response type will be StarlightItemResponse<Entry<PostsFields>>,
450
+ * // which was implicitly inferred by the SDK!
451
+ * const response = await Starlight.posts.entries.get('hello-world')
452
+ *
453
+ * // helloWorld type is Entry<PostsFields>
454
+ * const helloWorld = response.data
455
+ *
456
+ * // Auto-complete will work just as before when we explicitly type the Entry!
457
+ * console.log(helloWorld.data.featured_image)
458
+ * ```
459
+ *
460
+ * @group Client
461
+ */
54
462
  export interface DefaultModelDefinition extends WorkspaceModelDefinition {
55
463
  }
464
+ /**
465
+ * This type is only used as a base for the DefaultModelDefinition type.
466
+ *
467
+ * @internal
468
+ */
56
469
  export interface WorkspaceModelDefinition {
57
470
  [slug: string]: SerializedData;
58
471
  }
@@ -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,oBAAo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AE,CAAA;IACT;;;OAGG;IACH,KAAK,EAAE;QACL;;WAEG;QACH,KAAK,EAAE,MAAM,CAAA;QACb;;WAEG;QACH,IAAI,EAAE,MAAM,CAAA;QACZ;;WAEG;QACH,IAAI,CAAC,EAAE,MAAM,CAAA;QACb;;WAEG;QACH,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;IACD;;;;;;;;OAQG;IACH,IAAI,EAAE;QACJ;;WAEG;QACH,YAAY,EAAE,MAAM,CAAA;QACpB;;WAEG;QACH,SAAS,EAAE,MAAM,CAAA;QACjB;;WAEG;QACH,IAAI,EAAE,MAAM,CAAA;QACZ;;WAEG;QACH,EAAE,EAAE,MAAM,CAAA;QACV;;WAEG;QACH,QAAQ,EAAE,MAAM,CAAA;QAChB;;WAEG;QACH,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0GG;AAEH,MAAM,WAAW,sBAAuB,SAAQ,wBAAwB;CAAG;AAE3E;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAAA;CAC/B"}
@@ -1,4 +1,6 @@
1
1
  export * from './fields';
2
2
  export * from './entities';
3
3
  export * from './visual';
4
+ export * from './instances';
5
+ export * from './selectors';
4
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AASA,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA","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,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA","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 */\nexport type BaseUrl = 'https://query.starlight.sh/v2' | string\n\n/**\n * @group Client\n */\nexport type StarlightConfig = {\n workspace?: string\n baseUrl?: BaseUrl\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(<App />)\n * ```\n *\n * @param config A configuration object. Required.\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 an 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 {@link ModelInstance}s 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 * {@link ModelCategoryInstance}s 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 * {@link CollectionInstance}s 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 * @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 {@link ModelInstance}s dynamically.\n * See {@link StarlightClient} to learn which methods it provides.\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"]}
@@ -0,0 +1,4 @@
1
+ export { CollectionInstance } from '../instances/Collection';
2
+ export { DynamicModelInstance, ModelInstance } from '../instances/Model';
3
+ export { ModelCategoryInstance } 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,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# 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 { CollectionInstance } from '../instances/Collection'\nexport { DynamicModelInstance, ModelInstance } from '../instances/Model'\nexport { ModelCategoryInstance } from '../instances/ModelCategory'\n"]}
@@ -0,0 +1,8 @@
1
+ export { ModelCategorySelector, DynamicModelCategorySelector, } from '../selectors/ModelCategory';
2
+ export { ModelSelector, DynamicModelSelector } from '../selectors/Model';
3
+ export { CollectionSelector, DynamicCollectionSelector, } from '../selectors/Collection';
4
+ export { EntrySelector } from '../selectors/Entry';
5
+ export { MediaSelector } from '../selectors/Media';
6
+ export { SearchSelector } from '../selectors/Search';
7
+ export { SingletonSelector } from '../selectors/Singleton';
8
+ //# sourceMappingURL=selectors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../../src/types/selectors.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AACxE,OAAO,EACL,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=selectors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.js","sourceRoot":"","sources":["../../../src/types/selectors.ts"],"names":[],"mappings":"","sourcesContent":["// Selector types are exported here so they are visible in the API docs.\nexport {\n ModelCategorySelector,\n DynamicModelCategorySelector,\n} from '../selectors/ModelCategory'\nexport { ModelSelector, DynamicModelSelector } from '../selectors/Model'\nexport {\n CollectionSelector,\n DynamicCollectionSelector,\n} from '../selectors/Collection'\nexport { EntrySelector } from '../selectors/Entry'\nexport { MediaSelector } from '../selectors/Media'\nexport { SearchSelector } from '../selectors/Search'\nexport { SingletonSelector } from '../selectors/Singleton'\n"]}