@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.
- package/README.md +54 -0
- package/dist/cjs/client.d.ts +41 -2
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +39 -0
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/errors.d.ts +35 -0
- package/dist/cjs/errors.d.ts.map +1 -1
- package/dist/cjs/errors.js +7 -0
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/index.d.ts +22 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/instances/Collection/index.d.ts +4 -4
- package/dist/cjs/instances/Collection/index.d.ts.map +1 -1
- package/dist/cjs/instances/Collection/index.js.map +1 -1
- package/dist/cjs/instances/Collection/types.d.ts +68 -12
- package/dist/cjs/instances/Collection/types.d.ts.map +1 -1
- package/dist/cjs/instances/Collection/types.js +1 -0
- package/dist/cjs/instances/Collection/types.js.map +1 -1
- package/dist/cjs/instances/Model/index.d.ts +3 -3
- package/dist/cjs/instances/Model/index.d.ts.map +1 -1
- package/dist/cjs/instances/Model/index.js.map +1 -1
- package/dist/cjs/instances/Model/types.d.ts +86 -3
- package/dist/cjs/instances/Model/types.d.ts.map +1 -1
- package/dist/cjs/instances/Model/types.js.map +1 -1
- package/dist/cjs/instances/ModelCategory/index.d.ts +2 -2
- package/dist/cjs/instances/ModelCategory/index.d.ts.map +1 -1
- package/dist/cjs/instances/ModelCategory/index.js.map +1 -1
- package/dist/cjs/instances/ModelCategory/types.d.ts +62 -10
- package/dist/cjs/instances/ModelCategory/types.d.ts.map +1 -1
- package/dist/cjs/instances/ModelCategory/types.js.map +1 -1
- package/dist/cjs/selectors/Collection/index.d.ts +3 -3
- package/dist/cjs/selectors/Collection/index.d.ts.map +1 -1
- package/dist/cjs/selectors/Collection/index.js +1 -1
- package/dist/cjs/selectors/Collection/index.js.map +1 -1
- package/dist/cjs/selectors/Collection/types.d.ts +84 -9
- package/dist/cjs/selectors/Collection/types.d.ts.map +1 -1
- package/dist/cjs/selectors/Collection/types.js.map +1 -1
- package/dist/cjs/selectors/Entry/types.d.ts +105 -10
- package/dist/cjs/selectors/Entry/types.d.ts.map +1 -1
- package/dist/cjs/selectors/Entry/types.js.map +1 -1
- package/dist/cjs/selectors/Media/index.js +2 -2
- package/dist/cjs/selectors/Media/index.js.map +1 -1
- package/dist/cjs/selectors/Media/types.d.ts +35 -1
- package/dist/cjs/selectors/Media/types.d.ts.map +1 -1
- package/dist/cjs/selectors/Media/types.js.map +1 -1
- package/dist/cjs/selectors/Model/index.d.ts +3 -3
- package/dist/cjs/selectors/Model/index.js.map +1 -1
- package/dist/cjs/selectors/Model/types.d.ts +62 -3
- package/dist/cjs/selectors/Model/types.d.ts.map +1 -1
- package/dist/cjs/selectors/Model/types.js.map +1 -1
- package/dist/cjs/selectors/ModelCategory/index.d.ts +3 -3
- package/dist/cjs/selectors/ModelCategory/index.js +1 -1
- package/dist/cjs/selectors/ModelCategory/index.js.map +1 -1
- package/dist/cjs/selectors/ModelCategory/types.d.ts +50 -7
- package/dist/cjs/selectors/ModelCategory/types.d.ts.map +1 -1
- package/dist/cjs/selectors/ModelCategory/types.js.map +1 -1
- package/dist/cjs/selectors/Search/index.d.ts +2 -2
- package/dist/cjs/selectors/Search/index.d.ts.map +1 -1
- package/dist/cjs/selectors/Search/index.js +1 -1
- package/dist/cjs/selectors/Search/index.js.map +1 -1
- package/dist/cjs/selectors/Search/types.d.ts +80 -7
- package/dist/cjs/selectors/Search/types.d.ts.map +1 -1
- package/dist/cjs/selectors/Search/types.js.map +1 -1
- package/dist/cjs/selectors/Singleton/types.d.ts +49 -0
- package/dist/cjs/selectors/Singleton/types.d.ts.map +1 -1
- package/dist/cjs/selectors/Singleton/types.js.map +1 -1
- package/dist/cjs/types/entities.d.ts +241 -2
- package/dist/cjs/types/entities.d.ts.map +1 -1
- package/dist/cjs/types/entities.js.map +1 -1
- package/dist/cjs/types/fields.d.ts +63 -0
- package/dist/cjs/types/fields.d.ts.map +1 -1
- package/dist/cjs/types/fields.js.map +1 -1
- package/dist/cjs/types/index.d.ts +514 -11
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +2 -0
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/instances.d.ts +4 -0
- package/dist/cjs/types/instances.d.ts.map +1 -0
- package/dist/cjs/types/instances.js +3 -0
- package/dist/cjs/types/instances.js.map +1 -0
- package/dist/cjs/types/selectors.d.ts +8 -0
- package/dist/cjs/types/selectors.d.ts.map +1 -0
- package/dist/cjs/types/selectors.js +3 -0
- package/dist/cjs/types/selectors.js.map +1 -0
- package/dist/cjs/types/visual.d.ts +69 -0
- package/dist/cjs/types/visual.d.ts.map +1 -1
- package/dist/cjs/types/visual.js.map +1 -1
- package/dist/esm/client.d.ts +41 -2
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +39 -0
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/errors.d.ts +35 -0
- package/dist/esm/errors.d.ts.map +1 -1
- package/dist/esm/errors.js +7 -0
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/index.d.ts +22 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +21 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/instances/Collection/index.d.ts +4 -4
- package/dist/esm/instances/Collection/index.d.ts.map +1 -1
- package/dist/esm/instances/Collection/index.js.map +1 -1
- package/dist/esm/instances/Collection/types.d.ts +68 -12
- package/dist/esm/instances/Collection/types.d.ts.map +1 -1
- package/dist/esm/instances/Collection/types.js +1 -0
- package/dist/esm/instances/Collection/types.js.map +1 -1
- package/dist/esm/instances/Model/index.d.ts +3 -3
- package/dist/esm/instances/Model/index.d.ts.map +1 -1
- package/dist/esm/instances/Model/index.js.map +1 -1
- package/dist/esm/instances/Model/types.d.ts +86 -3
- package/dist/esm/instances/Model/types.d.ts.map +1 -1
- package/dist/esm/instances/Model/types.js.map +1 -1
- package/dist/esm/instances/ModelCategory/index.d.ts +2 -2
- package/dist/esm/instances/ModelCategory/index.d.ts.map +1 -1
- package/dist/esm/instances/ModelCategory/index.js.map +1 -1
- package/dist/esm/instances/ModelCategory/types.d.ts +62 -10
- package/dist/esm/instances/ModelCategory/types.d.ts.map +1 -1
- package/dist/esm/instances/ModelCategory/types.js.map +1 -1
- package/dist/esm/selectors/Collection/index.d.ts +3 -3
- package/dist/esm/selectors/Collection/index.d.ts.map +1 -1
- package/dist/esm/selectors/Collection/index.js +1 -1
- package/dist/esm/selectors/Collection/index.js.map +1 -1
- package/dist/esm/selectors/Collection/types.d.ts +84 -9
- package/dist/esm/selectors/Collection/types.d.ts.map +1 -1
- package/dist/esm/selectors/Collection/types.js.map +1 -1
- package/dist/esm/selectors/Entry/types.d.ts +105 -10
- package/dist/esm/selectors/Entry/types.d.ts.map +1 -1
- package/dist/esm/selectors/Entry/types.js.map +1 -1
- package/dist/esm/selectors/Media/index.js +2 -2
- package/dist/esm/selectors/Media/index.js.map +1 -1
- package/dist/esm/selectors/Media/types.d.ts +35 -1
- package/dist/esm/selectors/Media/types.d.ts.map +1 -1
- package/dist/esm/selectors/Media/types.js.map +1 -1
- package/dist/esm/selectors/Model/index.d.ts +3 -3
- package/dist/esm/selectors/Model/index.js.map +1 -1
- package/dist/esm/selectors/Model/types.d.ts +62 -3
- package/dist/esm/selectors/Model/types.d.ts.map +1 -1
- package/dist/esm/selectors/Model/types.js.map +1 -1
- package/dist/esm/selectors/ModelCategory/index.d.ts +3 -3
- package/dist/esm/selectors/ModelCategory/index.js +1 -1
- package/dist/esm/selectors/ModelCategory/index.js.map +1 -1
- package/dist/esm/selectors/ModelCategory/types.d.ts +50 -7
- package/dist/esm/selectors/ModelCategory/types.d.ts.map +1 -1
- package/dist/esm/selectors/ModelCategory/types.js.map +1 -1
- package/dist/esm/selectors/Search/index.d.ts +2 -2
- package/dist/esm/selectors/Search/index.d.ts.map +1 -1
- package/dist/esm/selectors/Search/index.js +1 -1
- package/dist/esm/selectors/Search/index.js.map +1 -1
- package/dist/esm/selectors/Search/types.d.ts +80 -7
- package/dist/esm/selectors/Search/types.d.ts.map +1 -1
- package/dist/esm/selectors/Search/types.js.map +1 -1
- package/dist/esm/selectors/Singleton/types.d.ts +49 -0
- package/dist/esm/selectors/Singleton/types.d.ts.map +1 -1
- package/dist/esm/selectors/Singleton/types.js.map +1 -1
- package/dist/esm/types/entities.d.ts +241 -2
- package/dist/esm/types/entities.d.ts.map +1 -1
- package/dist/esm/types/entities.js.map +1 -1
- package/dist/esm/types/fields.d.ts +63 -0
- package/dist/esm/types/fields.d.ts.map +1 -1
- package/dist/esm/types/fields.js.map +1 -1
- package/dist/esm/types/index.d.ts +514 -11
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/types/index.js +2 -0
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/instances.d.ts +4 -0
- package/dist/esm/types/instances.d.ts.map +1 -0
- package/dist/esm/types/instances.js +2 -0
- package/dist/esm/types/instances.js.map +1 -0
- package/dist/esm/types/selectors.d.ts +8 -0
- package/dist/esm/types/selectors.d.ts.map +1 -0
- package/dist/esm/types/selectors.js +2 -0
- package/dist/esm/types/selectors.js.map +1 -0
- package/dist/esm/types/visual.d.ts +69 -0
- package/dist/esm/types/visual.d.ts.map +1 -1
- package/dist/esm/types/visual.js.map +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<picture>
|
|
2
|
+
<source media="(prefers-color-scheme: dark)" srcset="/website/static/img/sdk-header-dark.svg">
|
|
3
|
+
<source media="(prefers-color-scheme: light)" srcset="/website/static/img/sdk-header.svg">
|
|
4
|
+
<img alt="Starlight JS SDK logo" src="/website/static/img/sdk-header.svg">
|
|
5
|
+
</picture>
|
|
6
|
+
|
|
7
|
+
# Starlight JavaScript SDK
|
|
8
|
+
|
|
9
|
+
This is the official Starlight SDK for websites and JavaScript applications, which makes integrating Starlight
|
|
10
|
+
content into your apps a real breeze.
|
|
11
|
+
|
|
12
|
+
You can read the usage guide and the API reference in [its documentation page](https://js.sdk.starlight.sh).
|
|
13
|
+
|
|
14
|
+
## Quick Start
|
|
15
|
+
|
|
16
|
+
To quickly start using the JS SDK, install it into your project:
|
|
17
|
+
|
|
18
|
+
```shell
|
|
19
|
+
npm install @starlightcms/js-sdk
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Then, import the SDK and configure which Starlight workspace it should request data from:
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import Starlight from '@starlightcms/js-sdk'
|
|
26
|
+
|
|
27
|
+
Starlight.configure({
|
|
28
|
+
workspace: '1234567890'
|
|
29
|
+
})
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
And, finally, start requesting data:
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
import Starlight from '@starlightcms/js-sdk'
|
|
36
|
+
|
|
37
|
+
// Listing all entries from the 'posts' model.
|
|
38
|
+
const response = Starlight.posts.entries.list()
|
|
39
|
+
|
|
40
|
+
// Getting content from the 'hello-world' entry.
|
|
41
|
+
const response = Starlight.posts.entries.get('hello-world')
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The SDK is capable of requesting a myriad of different content from your workspaces. Check out
|
|
45
|
+
[the documentation](https://js.sdk.starlight.sh/docs/intro) to learn more.
|
|
46
|
+
|
|
47
|
+
## React SDK
|
|
48
|
+
|
|
49
|
+
If you use React on your application, take a look at [the Starlight React SDK](https://github.com/starlightcms/react-sdk).
|
|
50
|
+
It's based in the JS SDK, and also provide useful React components to simplify content and image rendering.
|
|
51
|
+
|
|
52
|
+
## Issues
|
|
53
|
+
|
|
54
|
+
If you have any questions or you're facing any issues with the SDK, feel free to [open an issue](https://github.com/starlightcms/js-sdk/issues).
|
package/dist/cjs/client.d.ts
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
-
import { DefaultModelDefinition,
|
|
2
|
-
|
|
1
|
+
import { DefaultModelDefinition, DynamicStarlightClient, StarlightConfig, WorkspaceModelDefinition } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a new {@link DynamicStarlightClient}, which is a
|
|
4
|
+
* {@link StarlightClient} with support to create
|
|
5
|
+
* {@apilink ModelInstance | ModelInstances} using the dynamic syntax. To learn
|
|
6
|
+
* which methods a client supports, see {@link StarlightClient}.
|
|
7
|
+
*
|
|
8
|
+
* This function accepts a {@link StarlightConfig} object and can be used to
|
|
9
|
+
* create new clients that connect to a single Starlight workspace. Each client
|
|
10
|
+
* returned by this function is separate and independent of the others.
|
|
11
|
+
*
|
|
12
|
+
* If you only need to make requests to a single workspace, it's probably easier
|
|
13
|
+
* to use the SDK's default client. To use it, you only need to
|
|
14
|
+
* import the default object exported by the SDK:
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* // `Starlight` below is the default StarlightClient.
|
|
18
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* See {@link default} for more info on how to use the default client.
|
|
22
|
+
*
|
|
23
|
+
* @example Creating a new client and exporting it.
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { makeStarlightClient } from '@starlightcms/js-sdk'
|
|
26
|
+
*
|
|
27
|
+
* const BlogClient = makeStarlightClient({
|
|
28
|
+
* workspace: '123123123',
|
|
29
|
+
* debug: true
|
|
30
|
+
* })
|
|
31
|
+
*
|
|
32
|
+
* // Feel free to export the new client so your application can use it.
|
|
33
|
+
* export default BlogClient
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @param config The client configuration object. You need to provide at least
|
|
37
|
+
* the `workspace` property. See {@link StarlightConfig} to view all the
|
|
38
|
+
* available options.
|
|
39
|
+
* @group Client
|
|
40
|
+
*/
|
|
41
|
+
export declare function makeClient<D extends WorkspaceModelDefinition = DefaultModelDefinition>(config?: StarlightConfig): DynamicStarlightClient<D>;
|
|
3
42
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/cjs/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EAEtB,eAAe,EACf,wBAAwB,EACzB,MAAM,SAAS,CAAA;AAUhB,wBAAgB,UAAU,CACxB,CAAC,SAAS,wBAAwB,GAAG,sBAAsB,EAC3D,MAAM,GAAE,eAAoB,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAkFzD"}
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EAEtB,eAAe,EACf,wBAAwB,EACzB,MAAM,SAAS,CAAA;AAUhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,UAAU,CACxB,CAAC,SAAS,wBAAwB,GAAG,sBAAsB,EAC3D,MAAM,GAAE,eAAoB,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAkFzD"}
|
package/dist/cjs/client.js
CHANGED
|
@@ -21,6 +21,45 @@ const Collection_1 = __importDefault(require("./selectors/Collection"));
|
|
|
21
21
|
const Media_1 = __importDefault(require("./selectors/Media"));
|
|
22
22
|
const Search_1 = __importDefault(require("./selectors/Search"));
|
|
23
23
|
const Collection_2 = __importDefault(require("./instances/Collection"));
|
|
24
|
+
/**
|
|
25
|
+
* Returns a new {@link DynamicStarlightClient}, which is a
|
|
26
|
+
* {@link StarlightClient} with support to create
|
|
27
|
+
* {@apilink ModelInstance | ModelInstances} using the dynamic syntax. To learn
|
|
28
|
+
* which methods a client supports, see {@link StarlightClient}.
|
|
29
|
+
*
|
|
30
|
+
* This function accepts a {@link StarlightConfig} object and can be used to
|
|
31
|
+
* create new clients that connect to a single Starlight workspace. Each client
|
|
32
|
+
* returned by this function is separate and independent of the others.
|
|
33
|
+
*
|
|
34
|
+
* If you only need to make requests to a single workspace, it's probably easier
|
|
35
|
+
* to use the SDK's default client. To use it, you only need to
|
|
36
|
+
* import the default object exported by the SDK:
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* // `Starlight` below is the default StarlightClient.
|
|
40
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* See {@link default} for more info on how to use the default client.
|
|
44
|
+
*
|
|
45
|
+
* @example Creating a new client and exporting it.
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { makeStarlightClient } from '@starlightcms/js-sdk'
|
|
48
|
+
*
|
|
49
|
+
* const BlogClient = makeStarlightClient({
|
|
50
|
+
* workspace: '123123123',
|
|
51
|
+
* debug: true
|
|
52
|
+
* })
|
|
53
|
+
*
|
|
54
|
+
* // Feel free to export the new client so your application can use it.
|
|
55
|
+
* export default BlogClient
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @param config The client configuration object. You need to provide at least
|
|
59
|
+
* the `workspace` property. See {@link StarlightConfig} to view all the
|
|
60
|
+
* available options.
|
|
61
|
+
* @group Client
|
|
62
|
+
*/
|
|
24
63
|
function makeClient(config = {}) {
|
|
25
64
|
var _a, _b, _c;
|
|
26
65
|
let baseUrl = (_a = config.baseUrl) !== null && _a !== void 0 ? _a : 'https://query.starlight.sh/v2';
|
package/dist/cjs/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"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","sourcesContent":["import {\n DefaultModelDefinition,\n
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"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","sourcesContent":["import {\n DefaultModelDefinition,\n DynamicStarlightClient,\n StarlightClient,\n StarlightConfig,\n WorkspaceModelDefinition,\n} from './types'\nimport { StarlightError } from './errors'\nimport makeModelSelector from './selectors/Model'\nimport makeModelInstance from './instances/Model'\nimport makeSingletonSelector from './selectors/Singleton'\nimport makeCollectionSelector from './selectors/Collection'\nimport makeMediaSelector from './selectors/Media'\nimport makeSearchSelector from './selectors/Search'\nimport makeCollectionInstance from './instances/Collection'\n\n/**\n * Returns a new {@link DynamicStarlightClient}, which is a\n * {@link StarlightClient} with support to create\n * {@apilink ModelInstance | ModelInstances} using the dynamic syntax. To learn\n * which methods a client supports, see {@link StarlightClient}.\n *\n * This function accepts a {@link StarlightConfig} object and can be used to\n * create new clients that connect to a single Starlight workspace. Each client\n * returned by this function is separate and independent of the others.\n *\n * If you only need to make requests to a single workspace, it's probably easier\n * to use the SDK's default client. To use it, you only need to\n * import the default object exported by the SDK:\n *\n * ```ts\n * // `Starlight` below is the default StarlightClient.\n * import Starlight from '@starlightcms/js-sdk'\n * ```\n *\n * See {@link default} for more info on how to use the default client.\n *\n * @example Creating a new client and exporting it.\n * ```ts\n * import { makeStarlightClient } from '@starlightcms/js-sdk'\n *\n * const BlogClient = makeStarlightClient({\n * workspace: '123123123',\n * debug: true\n * })\n *\n * // Feel free to export the new client so your application can use it.\n * export default BlogClient\n * ```\n *\n * @param config The client configuration object. You need to provide at least\n * the `workspace` property. See {@link StarlightConfig} to view all the\n * available options.\n * @group Client\n */\nexport function makeClient<\n D extends WorkspaceModelDefinition = DefaultModelDefinition\n>(config: StarlightConfig = {}): DynamicStarlightClient<D> {\n let baseUrl = config.baseUrl ?? 'https://query.starlight.sh/v2'\n let workspace = config.workspace ?? ''\n let debug = config.debug ?? false\n\n const client: StarlightClient = {\n configure(config) {\n baseUrl = config.baseUrl ?? baseUrl\n workspace = config.workspace ?? workspace\n debug = config.debug ?? debug\n },\n\n log(message, ...optionalParams) {\n if (debug) console.log(message, ...optionalParams)\n },\n\n getBaseUrl() {\n return `${baseUrl}/workspaces/${workspace}`\n },\n\n async get(path, params = {}, options) {\n const filteredParams = Object.keys(params).reduce((accumulator, key) => {\n const param = params[key]\n\n if (param || param === false) accumulator[key] = String(param)\n\n return accumulator\n }, {} as Record<string, string>)\n\n const searchParams = new URLSearchParams(filteredParams).toString()\n const finalPath = searchParams ? `${path}?${searchParams}` : path\n\n this.log(`Starlight - GET ${finalPath}`)\n\n const response = await fetch(`${this.getBaseUrl()}${finalPath}`, options)\n\n if (response.status >= 200 && response.status < 300) {\n return await response.json()\n } else {\n const message = `Starlight - GET ${path} returned ${response.status}: ${response.statusText}`\n throw new StarlightError(message, response)\n }\n },\n\n get models() {\n return makeModelSelector(this)\n },\n\n model(slug) {\n return makeModelInstance(this, slug as string)\n },\n\n get singletons() {\n return makeSingletonSelector(this)\n },\n\n get collections() {\n return makeCollectionSelector(this)\n },\n\n collection(slug: string | number) {\n return makeCollectionInstance(this, slug)\n },\n\n get media() {\n return makeMediaSelector(this)\n },\n\n get search() {\n return makeSearchSelector(this)\n },\n }\n\n return new Proxy(client, {\n get(target, prop) {\n if (typeof prop === 'string' && !Reflect.has(target, prop)) {\n return makeModelInstance(target, prop)\n }\n\n return Reflect.get(target, prop)\n },\n }) as DynamicStarlightClient<D>\n}\n"]}
|
package/dist/cjs/errors.d.ts
CHANGED
|
@@ -1,4 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This error is thrown every time a problem occurs when requesting something
|
|
3
|
+
* from Starlight's APIs. When it does, you can inspect the attached response
|
|
4
|
+
* to verify what kind of problem happened and handle it accordingly.
|
|
5
|
+
*
|
|
6
|
+
* @group Errors
|
|
7
|
+
*/
|
|
1
8
|
export declare class StarlightError extends Error {
|
|
9
|
+
/**
|
|
10
|
+
* The response provided by the `fetch` method when the error occurred.
|
|
11
|
+
*
|
|
12
|
+
* @example Using the `response` property to handle 404 errors.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import Starlight, { StarlightError } from '@starlightcms/js-sdk'
|
|
16
|
+
*
|
|
17
|
+
* // Returns either an Entry, null on 404 errors, or false in all other cases
|
|
18
|
+
* const requestEntry = async (slug) => {
|
|
19
|
+
* try {
|
|
20
|
+
* const response = await Starlight.posts.entries.get(slug)
|
|
21
|
+
*
|
|
22
|
+
* return response.data
|
|
23
|
+
* } catch (error) {
|
|
24
|
+
* if (error instanceof StarlightError && error.response.status === 404) {
|
|
25
|
+
* // Return null to indicate a 404 error
|
|
26
|
+
* return null
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* // Return false in all other error scenarios
|
|
30
|
+
* return false
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @see [MDN documentation on the Response object](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
36
|
+
*/
|
|
2
37
|
response: Response;
|
|
3
38
|
constructor(message: string, response: Response);
|
|
4
39
|
}
|
package/dist/cjs/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,cAAe,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACI,QAAQ,EAAE,QAAQ,CAAA;gBAEb,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ;CAIhD"}
|
package/dist/cjs/errors.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StarlightError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* This error is thrown every time a problem occurs when requesting something
|
|
6
|
+
* from Starlight's APIs. When it does, you can inspect the attached response
|
|
7
|
+
* to verify what kind of problem happened and handle it accordingly.
|
|
8
|
+
*
|
|
9
|
+
* @group Errors
|
|
10
|
+
*/
|
|
4
11
|
class StarlightError extends Error {
|
|
5
12
|
constructor(message, response) {
|
|
6
13
|
super(message);
|
package/dist/cjs/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,cAAe,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,MAAa,cAAe,SAAQ,KAAK;IA+BvC,YAAY,OAAe,EAAE,QAAkB;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;CACF;AAnCD,wCAmCC","sourcesContent":["/**\n * This error is thrown every time a problem occurs when requesting something\n * from Starlight's APIs. When it does, you can inspect the attached response\n * to verify what kind of problem happened and handle it accordingly.\n *\n * @group Errors\n */\nexport class StarlightError extends Error {\n /**\n * The response provided by the `fetch` method when the error occurred.\n *\n * @example Using the `response` property to handle 404 errors.\n *\n * ```ts\n * import Starlight, { StarlightError } from '@starlightcms/js-sdk'\n *\n * // Returns either an Entry, null on 404 errors, or false in all other cases\n * const requestEntry = async (slug) => {\n * try {\n * const response = await Starlight.posts.entries.get(slug)\n *\n * return response.data\n * } catch (error) {\n * if (error instanceof StarlightError && error.response.status === 404) {\n * // Return null to indicate a 404 error\n * return null\n * }\n *\n * // Return false in all other error scenarios\n * return false\n * }\n * }\n * ```\n *\n * @see [MDN documentation on the Response object](https://developer.mozilla.org/en-US/docs/Web/API/Response)\n */\n public response: Response\n\n constructor(message: string, response: Response) {\n super(message)\n this.response = response\n }\n}\n"]}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
import { makeClient } from './client';
|
|
2
2
|
export { StarlightError } from './errors';
|
|
3
3
|
export * from './types';
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* This is the default object exported by the SDK module, which is a
|
|
6
|
+
* pre-created {@link StarlightClient}. In the docs, this is called the "global
|
|
7
|
+
* SDK client". If your application only requests data from a single Starlight
|
|
8
|
+
* workspace, using this client is easier than creating
|
|
9
|
+
* a new one using {@link makeStarlightClient}.
|
|
10
|
+
*
|
|
11
|
+
* Using the default client is as easy as importing the SDK:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* // "Starlight" below is the default client.
|
|
15
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
16
|
+
*
|
|
17
|
+
* const response = await Starlight.posts.entries.list()
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* You need to configure the default workspace before using it.
|
|
21
|
+
* See {@apilink StarlightClient.configure} to learn more.
|
|
22
|
+
*
|
|
23
|
+
* @group Client
|
|
24
|
+
*/
|
|
25
|
+
declare const Starlight: import("./types").DynamicStarlightClient<import("./types").DefaultModelDefinition>;
|
|
5
26
|
export { makeClient as makeStarlightClient };
|
|
6
27
|
export default Starlight;
|
|
7
28
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,cAAc,SAAS,CAAA;AAEvB,QAAA,MAAM,SAAS,oFAAe,CAAA;AAE9B,OAAO,EAAE,UAAU,IAAI,mBAAmB,EAAE,CAAA;AAE5C,eAAe,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,cAAc,SAAS,CAAA;AAEvB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,QAAA,MAAM,SAAS,oFAAe,CAAA;AAE9B,OAAO,EAAE,UAAU,IAAI,mBAAmB,EAAE,CAAA;AAE5C,eAAe,SAAS,CAAA"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -20,6 +20,27 @@ Object.defineProperty(exports, "makeStarlightClient", { enumerable: true, get: f
|
|
|
20
20
|
var errors_1 = require("./errors");
|
|
21
21
|
Object.defineProperty(exports, "StarlightError", { enumerable: true, get: function () { return errors_1.StarlightError; } });
|
|
22
22
|
__exportStar(require("./types"), exports);
|
|
23
|
+
/**
|
|
24
|
+
* This is the default object exported by the SDK module, which is a
|
|
25
|
+
* pre-created {@link StarlightClient}. In the docs, this is called the "global
|
|
26
|
+
* SDK client". If your application only requests data from a single Starlight
|
|
27
|
+
* workspace, using this client is easier than creating
|
|
28
|
+
* a new one using {@link makeStarlightClient}.
|
|
29
|
+
*
|
|
30
|
+
* Using the default client is as easy as importing the SDK:
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* // "Starlight" below is the default client.
|
|
34
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
35
|
+
*
|
|
36
|
+
* const response = await Starlight.posts.entries.list()
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* You need to configure the default workspace before using it.
|
|
40
|
+
* See {@apilink StarlightClient.configure} to learn more.
|
|
41
|
+
*
|
|
42
|
+
* @group Client
|
|
43
|
+
*/
|
|
23
44
|
const Starlight = (0, client_1.makeClient)();
|
|
24
45
|
exports.default = Starlight;
|
|
25
46
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qCAAqC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qCAAqC;AA2Bd,oGA3Bd,mBAAU,OA2BuB;AA1B1C,mCAAyC;AAAhC,wGAAA,cAAc,OAAA;AACvB,0CAAuB;AAEvB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,SAAS,GAAG,IAAA,mBAAU,GAAE,CAAA;AAI9B,kBAAe,SAAS,CAAA","sourcesContent":["import { makeClient } from './client'\nexport { StarlightError } from './errors'\nexport * from './types'\n\n/**\n * This is the default object exported by the SDK module, which is a\n * pre-created {@link StarlightClient}. In the docs, this is called the \"global\n * SDK client\". If your application only requests data from a single Starlight\n * workspace, using this client is easier than creating\n * a new one using {@link makeStarlightClient}.\n *\n * Using the default client is as easy as importing the SDK:\n *\n * ```ts\n * // \"Starlight\" below is the default client.\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.posts.entries.list()\n * ```\n *\n * You need to configure the default workspace before using it.\n * See {@apilink StarlightClient.configure} to learn more.\n *\n * @group Client\n */\nconst Starlight = makeClient()\n\nexport { makeClient as makeStarlightClient }\n\nexport default Starlight\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CollectionInstance } from './types';
|
|
3
|
-
export default function makeCollectionInstance<T extends
|
|
4
|
-
export { CollectionInstance };
|
|
1
|
+
import { CollectionEntityTypes, StarlightClient } from '../../types';
|
|
2
|
+
import { CollectionInstance, ListCollectionItemsParams } from './types';
|
|
3
|
+
export default function makeCollectionInstance<T extends CollectionEntityTypes = unknown>(client: StarlightClient, collection: string | number): CollectionInstance<T>;
|
|
4
|
+
export { CollectionInstance, ListCollectionItemsParams };
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/instances/Collection/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/instances/Collection/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAEvE,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,CAAC,SAAS,qBAAqB,GAAG,OAAO,EACzC,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAU7E;AAED,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/instances/Collection/index.ts"],"names":[],"mappings":";;AAGA,SAAwB,sBAAsB,CAE5C,MAAuB,EAAE,UAA2B;IACpD,OAAO;QACL,GAAG;YACD,OAAO,MAAM,CAAC,GAAG,CAAC,gBAAgB,UAAU,EAAE,CAAC,CAAA;QACjD,CAAC;QAED,KAAK,CAAC,OAAO;YACX,OAAO,MAAM,CAAC,GAAG,CAAC,gBAAgB,UAAU,QAAQ,EAAE,OAAO,CAAC,CAAA;QAChE,CAAC;KACF,CAAA;AACH,CAAC;AAZD,yCAYC","sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/instances/Collection/index.ts"],"names":[],"mappings":";;AAGA,SAAwB,sBAAsB,CAE5C,MAAuB,EAAE,UAA2B;IACpD,OAAO;QACL,GAAG;YACD,OAAO,MAAM,CAAC,GAAG,CAAC,gBAAgB,UAAU,EAAE,CAAC,CAAA;QACjD,CAAC;QAED,KAAK,CAAC,OAAO;YACX,OAAO,MAAM,CAAC,GAAG,CAAC,gBAAgB,UAAU,QAAQ,EAAE,OAAO,CAAC,CAAA;QAChE,CAAC;KACF,CAAA;AACH,CAAC;AAZD,yCAYC","sourcesContent":["import { CollectionEntityTypes, StarlightClient } from '../../types'\nimport { CollectionInstance, ListCollectionItemsParams } from './types'\n\nexport default function makeCollectionInstance<\n T extends CollectionEntityTypes = unknown\n>(client: StarlightClient, collection: string | number): CollectionInstance<T> {\n return {\n get() {\n return client.get(`/collections/${collection}`)\n },\n\n items(options) {\n return client.get(`/collections/${collection}/items`, options)\n },\n }\n}\n\nexport { CollectionInstance, ListCollectionItemsParams }\n"]}
|
|
@@ -1,15 +1,71 @@
|
|
|
1
|
-
import { Collection,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { BaseRequestParameters, Collection, CollectionEntityTypes, CollectionTypeMapper, QueryableRequestParameters, StarlightItemResponse, StarlightListResponse, WithQueryableFieldsOnModelables } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Request parameters for listing collection items.
|
|
4
|
+
*
|
|
5
|
+
* Used by {@apilink CollectionInstance.items}.
|
|
6
|
+
*
|
|
7
|
+
* @group Request Parameters
|
|
8
|
+
*/
|
|
9
|
+
export interface ListCollectionItemsParams extends BaseRequestParameters, QueryableRequestParameters {
|
|
10
|
+
/**
|
|
11
|
+
* Define how entries will be ordered. Check this field type to see the
|
|
12
|
+
* allowed options.
|
|
13
|
+
*/
|
|
8
14
|
order?: 'title:asc' | 'title:desc' | 'published_at:asc' | 'published_at:desc' | 'views:asc' | 'views:desc';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* An Instance that provide methods to request information and items from
|
|
18
|
+
* a specific {@link Collection}.
|
|
19
|
+
*
|
|
20
|
+
* You can access a CollectionInstance using
|
|
21
|
+
* {@apilink StarlightClient.collection}.
|
|
22
|
+
*
|
|
23
|
+
* To list all workspace collections, use a {@link CollectionSelector}.
|
|
24
|
+
*
|
|
25
|
+
* @group Instances
|
|
26
|
+
*/
|
|
27
|
+
export interface CollectionInstance<C extends CollectionEntityTypes> {
|
|
28
|
+
/**
|
|
29
|
+
* Returns a {@link StarlightItemResponse} with a single {@link Collection}.
|
|
30
|
+
*
|
|
31
|
+
* @example Requesting information from a collection of slug `featured-news`.
|
|
32
|
+
* ```ts
|
|
33
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
34
|
+
*
|
|
35
|
+
* const response = await Starlight.collection('featured-news').get()
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
get(): Promise<StarlightItemResponse<Collection<CollectionTypeMapper<C>>>>;
|
|
39
|
+
/**
|
|
40
|
+
* Returns a {@link StarlightListResponse} with the list of items of this
|
|
41
|
+
* {@link Collection}. The returned list type depends on the collection type:
|
|
42
|
+
* a list of {@apilink Entry | Entries} for a collection of type `entry`, a
|
|
43
|
+
* list of {@apilink MediaObject | MediaObjects} for a collection o type
|
|
44
|
+
* `media`, and so on.
|
|
45
|
+
*
|
|
46
|
+
* If the given Collection is not typed, this method will return a response of
|
|
47
|
+
* `StarlightListResponse<unknown>`.
|
|
48
|
+
*
|
|
49
|
+
* @example Requesting all items from an Entry collection of slug `featured-news`.
|
|
50
|
+
* ```ts
|
|
51
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
52
|
+
*
|
|
53
|
+
* const response = await Starlight.collection('featured-news').items()
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example Explicitly typing the returned items. Only possible in TypeScript.
|
|
57
|
+
* ```ts
|
|
58
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
59
|
+
* import { NewsPostType } from '../types'
|
|
60
|
+
*
|
|
61
|
+
* // response will be StarlightListResponse<Entry<NewsPostType>>
|
|
62
|
+
* const response = await Starlight.collection<Entry<NewsPostType>>('featured-news').items()
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @param options An optional object of request parameters. See
|
|
66
|
+
* {@link ListCollectionItemsParams} for all available options. `field:foo`
|
|
67
|
+
* syntax is also supported, see {@link QueryableFields} for more info.
|
|
68
|
+
*/
|
|
69
|
+
items(options?: ListCollectionItemsParams & WithQueryableFieldsOnModelables<C>): Promise<StarlightListResponse<C>>;
|
|
14
70
|
}
|
|
15
71
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/instances/Collection/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/instances/Collection/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,UAAU,EACV,qBAAqB,EACrB,oBAAoB,EACpB,0BAA0B,EAC1B,qBAAqB,EACrB,qBAAqB,EACrB,+BAA+B,EAChC,MAAM,aAAa,CAAA;AAEpB;;;;;;GAMG;AACH,MAAM,WAAW,yBACf,SAAQ,qBAAqB,EAC3B,0BAA0B;IAC5B;;;OAGG;IACH,KAAK,CAAC,EACF,WAAW,GACX,YAAY,GACZ,kBAAkB,GAClB,mBAAmB,GACnB,WAAW,GACX,YAAY,CAAA;CACjB;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,qBAAqB;IACjE;;;;;;;;;OASG;IACH,GAAG,IAAI,OAAO,CAAC,qBAAqB,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAE1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,KAAK,CACH,OAAO,CAAC,EAAE,yBAAyB,GAAG,+BAA+B,CAAC,CAAC,CAAC,GACvE,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAA;CACrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/instances/Collection/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n Collection,\n
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/instances/Collection/types.ts"],"names":[],"mappings":";;AA4FA,CAAC,CAAA","sourcesContent":["import {\n BaseRequestParameters,\n Collection,\n CollectionEntityTypes,\n CollectionTypeMapper,\n QueryableRequestParameters,\n StarlightItemResponse,\n StarlightListResponse,\n WithQueryableFieldsOnModelables,\n} from '../../types'\n\n/**\n * Request parameters for listing collection items.\n *\n * Used by {@apilink CollectionInstance.items}.\n *\n * @group Request Parameters\n */\nexport interface ListCollectionItemsParams\n extends BaseRequestParameters,\n QueryableRequestParameters {\n /**\n * Define how entries will be ordered. Check this field type to see the\n * allowed options.\n */\n order?:\n | 'title:asc'\n | 'title:desc'\n | 'published_at:asc'\n | 'published_at:desc'\n | 'views:asc'\n | 'views:desc'\n}\n\n/**\n * An Instance that provide methods to request information and items from\n * a specific {@link Collection}.\n *\n * You can access a CollectionInstance using\n * {@apilink StarlightClient.collection}.\n *\n * To list all workspace collections, use a {@link CollectionSelector}.\n *\n * @group Instances\n */\nexport interface CollectionInstance<C extends CollectionEntityTypes> {\n /**\n * Returns a {@link StarlightItemResponse} with a single {@link Collection}.\n *\n * @example Requesting information from a collection of slug `featured-news`.\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.collection('featured-news').get()\n * ```\n */\n get(): Promise<StarlightItemResponse<Collection<CollectionTypeMapper<C>>>>\n\n /**\n * Returns a {@link StarlightListResponse} with the list of items of this\n * {@link Collection}. The returned list type depends on the collection type:\n * a list of {@apilink Entry | Entries} for a collection of type `entry`, a\n * list of {@apilink MediaObject | MediaObjects} for a collection o type\n * `media`, and so on.\n *\n * If the given Collection is not typed, this method will return a response of\n * `StarlightListResponse<unknown>`.\n *\n * @example Requesting all items from an Entry collection of slug `featured-news`.\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.collection('featured-news').items()\n * ```\n *\n * @example Explicitly typing the returned items. Only possible in TypeScript.\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n * import { NewsPostType } from '../types'\n *\n * // response will be StarlightListResponse<Entry<NewsPostType>>\n * const response = await Starlight.collection<Entry<NewsPostType>>('featured-news').items()\n * ```\n *\n * @param options An optional object of request parameters. See\n * {@link ListCollectionItemsParams} for all available options. `field:foo`\n * syntax is also supported, see {@link QueryableFields} for more info.\n */\n items(\n options?: ListCollectionItemsParams & WithQueryableFieldsOnModelables<C>\n ): Promise<StarlightListResponse<C>>\n}\n0\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SerializedData, StarlightClient } from '../../types';
|
|
2
|
-
import {
|
|
3
|
-
export default function makeModelInstance<D extends SerializedData>(client: StarlightClient, model: string):
|
|
4
|
-
export {
|
|
2
|
+
import { DynamicModelInstance, ModelInstance } from './types';
|
|
3
|
+
export default function makeModelInstance<D extends SerializedData>(client: StarlightClient, model: string): DynamicModelInstance<D>;
|
|
4
|
+
export { DynamicModelInstance, ModelInstance };
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/instances/Model/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,eAAe,EAEhB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/instances/Model/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,eAAe,EAEhB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAS7D,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,CAAC,SAAS,cAAc,EAChE,MAAM,EAAE,eAAe,EACvB,KAAK,EAAE,MAAM,GACZ,oBAAoB,CAAC,CAAC,CAAC,CA4BzB;AAED,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/instances/Model/index.ts"],"names":[],"mappings":";;;;;AAOA,kEAAwE;AACxE,kFAEsC;AACtC,qEAEyB;AAEzB,SAAwB,iBAAiB,CACvC,MAAuB,EACvB,KAAa;IAEb,MAAM,QAAQ,GAAG;QACf,GAAG;YACD,OAAO,MAAM,CAAC,GAAG,CAAC,WAAW,KAAK,EAAE,CAAC,CAAA;QACvC,CAAC;QAED,QAAQ,CAAC,IAAY;YACnB,OAAO,IAAA,uBAAyB,EAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;QACvD,CAAC;QAED,IAAI,OAAO;YACT,OAAO,IAAA,eAAiB,EAAI,MAAM,EAAE,KAAK,CAAC,CAAA;QAC5C,CAAC;QAED,IAAI,UAAU;YACZ,OAAO,IAAA,uBAAyB,EAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QACjD,CAAC;KACF,CAAA;IAED,OAAO,IAAI,KAAK,CAAC,QAAQ,EAAE;QACzB,GAAG,CAAC,MAAM,EAAE,IAAI;YACd,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE;gBAC1D,OAAO,IAAA,uBAAyB,EAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;aACtD;YAED,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QAClC,CAAC;KACF,CAA4B,CAAA;AAC/B,CAAC;AA/BD,oCA+BC","sourcesContent":["import {\n Model,\n SerializedData,\n StarlightClient,\n StarlightItemResponse,\n} from '../../types'\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/instances/Model/index.ts"],"names":[],"mappings":";;;;;AAOA,kEAAwE;AACxE,kFAEsC;AACtC,qEAEyB;AAEzB,SAAwB,iBAAiB,CACvC,MAAuB,EACvB,KAAa;IAEb,MAAM,QAAQ,GAAG;QACf,GAAG;YACD,OAAO,MAAM,CAAC,GAAG,CAAC,WAAW,KAAK,EAAE,CAAC,CAAA;QACvC,CAAC;QAED,QAAQ,CAAC,IAAY;YACnB,OAAO,IAAA,uBAAyB,EAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;QACvD,CAAC;QAED,IAAI,OAAO;YACT,OAAO,IAAA,eAAiB,EAAI,MAAM,EAAE,KAAK,CAAC,CAAA;QAC5C,CAAC;QAED,IAAI,UAAU;YACZ,OAAO,IAAA,uBAAyB,EAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QACjD,CAAC;KACF,CAAA;IAED,OAAO,IAAI,KAAK,CAAC,QAAQ,EAAE;QACzB,GAAG,CAAC,MAAM,EAAE,IAAI;YACd,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE;gBAC1D,OAAO,IAAA,uBAAyB,EAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;aACtD;YAED,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QAClC,CAAC;KACF,CAA4B,CAAA;AAC/B,CAAC;AA/BD,oCA+BC","sourcesContent":["import {\n Model,\n SerializedData,\n StarlightClient,\n StarlightItemResponse,\n} from '../../types'\nimport { DynamicModelInstance, ModelInstance } from './types'\nimport makeEntrySelector, { EntrySelector } from '../../selectors/Entry'\nimport makeModelCategorySelector, {\n DynamicModelCategorySelector,\n} from '../../selectors/ModelCategory'\nimport makeModelCategoryInstance, {\n ModelCategoryInstance,\n} from '../ModelCategory'\n\nexport default function makeModelInstance<D extends SerializedData>(\n client: StarlightClient,\n model: string\n): DynamicModelInstance<D> {\n const instance = {\n get(): Promise<StarlightItemResponse<Model>> {\n return client.get(`/models/${model}`)\n },\n\n category(slug: string): ModelCategoryInstance<D> {\n return makeModelCategoryInstance(client, model, slug)\n },\n\n get entries(): EntrySelector<D> {\n return makeEntrySelector<D>(client, model)\n },\n\n get categories(): DynamicModelCategorySelector<D> {\n return makeModelCategorySelector(client, model)\n },\n }\n\n return new Proxy(instance, {\n get(target, prop) {\n if (typeof prop === 'string' && !Reflect.has(target, prop)) {\n return makeModelCategoryInstance(client, model, prop)\n }\n\n return Reflect.get(target, prop)\n },\n }) as DynamicModelInstance<D>\n}\n\nexport { DynamicModelInstance, ModelInstance }\n"]}
|
|
@@ -1,14 +1,97 @@
|
|
|
1
1
|
import { Model, SerializedData, StarlightItemResponse } from '../../types';
|
|
2
2
|
import { EntrySelector } from '../../selectors/Entry';
|
|
3
|
-
import {
|
|
3
|
+
import { DynamicModelCategorySelector } from '../../selectors/ModelCategory';
|
|
4
4
|
import { ModelCategoryInstance } from '../ModelCategory';
|
|
5
|
+
/**
|
|
6
|
+
* An Instance that provide methods to request information from a {@link Model},
|
|
7
|
+
* its {@apilink Entry | Entries}, and its {@apilink ModelCategory | Categories}.
|
|
8
|
+
*
|
|
9
|
+
* You can access a ModelInstance using {@apilink StarlightClient.model} or
|
|
10
|
+
* using the dynamic syntax on a {@link DynamicStarlightClient}. Usage
|
|
11
|
+
* examples will use the dynamic syntax.
|
|
12
|
+
*
|
|
13
|
+
* To list all workspace models, use a {@link ModelSelector}.
|
|
14
|
+
*
|
|
15
|
+
* @group Instances
|
|
16
|
+
*/
|
|
5
17
|
export interface ModelInstance<D extends SerializedData> {
|
|
18
|
+
/**
|
|
19
|
+
* Returns a {@link StarlightItemResponse} with a single {@link Model}.
|
|
20
|
+
*
|
|
21
|
+
* @example Requesting information from a model of slug `posts`.
|
|
22
|
+
* ```ts
|
|
23
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
24
|
+
*
|
|
25
|
+
* const response = await Starlight.posts.get()
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
6
28
|
get(): Promise<StarlightItemResponse<Model>>;
|
|
29
|
+
/**
|
|
30
|
+
* Returns a {@link ModelCategoryInstance}.
|
|
31
|
+
*
|
|
32
|
+
* If you're using a {@link DynamicModelInstance}, you can use the
|
|
33
|
+
* dynamic syntax instead of this method.
|
|
34
|
+
*
|
|
35
|
+
* @example Listing all entries from the "news" category of a model of slug "posts".
|
|
36
|
+
* ```ts
|
|
37
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
38
|
+
*
|
|
39
|
+
* const response = await Starlight.posts.category('news').entries()
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @param slug The category slug.
|
|
43
|
+
*/
|
|
7
44
|
category(slug: string): ModelCategoryInstance<D>;
|
|
45
|
+
/**
|
|
46
|
+
* Returns an {@link EntrySelector}.
|
|
47
|
+
*
|
|
48
|
+
* This is an accessor, which means that it should be used just like a common
|
|
49
|
+
* object parameter. For instance:
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
53
|
+
*
|
|
54
|
+
* // "entries" below is an EntrySelector.
|
|
55
|
+
* const response = await Starlight.posts.entries.list()
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
8
58
|
get entries(): EntrySelector<D>;
|
|
9
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Returns a {@link DynamicModelCategorySelector}.
|
|
61
|
+
*
|
|
62
|
+
* This is an accessor, which means that it should be used just like a common
|
|
63
|
+
* object parameter. For instance:
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
67
|
+
*
|
|
68
|
+
* // "categories" below is a DynamicModelCategorySelector.
|
|
69
|
+
* const response = await Starlight.posts.categories.get('interviews')
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
get categories(): DynamicModelCategorySelector<D>;
|
|
10
73
|
}
|
|
11
|
-
|
|
74
|
+
/**
|
|
75
|
+
* An Instance that provide all {@link ModelInstance} methods and adds support
|
|
76
|
+
* for creating {@apilink ModelCategoryInstance | ModelCategoryInstances} using
|
|
77
|
+
* the dynamic syntax.
|
|
78
|
+
*
|
|
79
|
+
* See {@link ModelInstance} to view all available methods.
|
|
80
|
+
*
|
|
81
|
+
* See {@doclink requests-and-responses#dynamic-syntax | Dynamic Instances}
|
|
82
|
+
* documentation to learn more about the dynamic syntax.
|
|
83
|
+
*
|
|
84
|
+
* @example Accessing a ModelCategoryInstance using the dynamic syntax.
|
|
85
|
+
* ```ts
|
|
86
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
87
|
+
*
|
|
88
|
+
* // "articles" below will be a ModelCategoryInstance.
|
|
89
|
+
* const response = await Starlight.posts.articles.list()
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @category Instances
|
|
93
|
+
*/
|
|
94
|
+
export declare type DynamicModelInstance<D extends SerializedData> = ModelInstance<D> & {
|
|
12
95
|
[key: string]: ModelCategoryInstance<D>;
|
|
13
96
|
};
|
|
14
97
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/instances/Model/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAA;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAExD,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,cAAc;IACrD,GAAG,IAAI,OAAO,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/instances/Model/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAA;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAExD;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,cAAc;IACrD;;;;;;;;;OASG;IACH,GAAG,IAAI,OAAO,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC,CAAA;IAE5C;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAA;IAEhD;;;;;;;;;;;;OAYG;IACH,IAAI,OAAO,IAAI,aAAa,CAAC,CAAC,CAAC,CAAA;IAE/B;;;;;;;;;;;;OAYG;IACH,IAAI,UAAU,IAAI,4BAA4B,CAAC,CAAC,CAAC,CAAA;CAClD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,oBAAY,oBAAoB,CAAC,CAAC,SAAS,cAAc,IACvD,aAAa,CAAC,CAAC,CAAC,GAAG;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAA;CACxC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/instances/Model/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Model, SerializedData, StarlightItemResponse } from '../../types'\nimport { EntrySelector } from '../../selectors/Entry'\nimport {
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/instances/Model/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Model, SerializedData, StarlightItemResponse } from '../../types'\nimport { EntrySelector } from '../../selectors/Entry'\nimport { DynamicModelCategorySelector } from '../../selectors/ModelCategory'\nimport { ModelCategoryInstance } from '../ModelCategory'\n\n/**\n * An Instance that provide methods to request information from a {@link Model},\n * its {@apilink Entry | Entries}, and its {@apilink ModelCategory | Categories}.\n *\n * You can access a ModelInstance using {@apilink StarlightClient.model} or\n * using the dynamic syntax on a {@link DynamicStarlightClient}. Usage\n * examples will use the dynamic syntax.\n *\n * To list all workspace models, use a {@link ModelSelector}.\n *\n * @group Instances\n */\nexport interface ModelInstance<D extends SerializedData> {\n /**\n * Returns a {@link StarlightItemResponse} with a single {@link Model}.\n *\n * @example Requesting information from a model of slug `posts`.\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.posts.get()\n * ```\n */\n get(): Promise<StarlightItemResponse<Model>>\n\n /**\n * Returns a {@link ModelCategoryInstance}.\n *\n * If you're using a {@link DynamicModelInstance}, you can use the\n * dynamic syntax instead of this method.\n *\n * @example Listing all entries from the \"news\" category of a model of slug \"posts\".\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.posts.category('news').entries()\n * ```\n *\n * @param slug The category slug.\n */\n category(slug: string): ModelCategoryInstance<D>\n\n /**\n * Returns an {@link EntrySelector}.\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 * // \"entries\" below is an EntrySelector.\n * const response = await Starlight.posts.entries.list()\n * ```\n */\n get entries(): EntrySelector<D>\n\n /**\n * Returns a {@link DynamicModelCategorySelector}.\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 * // \"categories\" below is a DynamicModelCategorySelector.\n * const response = await Starlight.posts.categories.get('interviews')\n * ```\n */\n get categories(): DynamicModelCategorySelector<D>\n}\n\n/**\n * An Instance that provide all {@link ModelInstance} methods and adds support\n * for creating {@apilink ModelCategoryInstance | ModelCategoryInstances} using\n * the dynamic syntax.\n *\n * See {@link ModelInstance} to view all available methods.\n *\n * See {@doclink requests-and-responses#dynamic-syntax | Dynamic Instances}\n * documentation to learn more about the dynamic syntax.\n *\n * @example Accessing a ModelCategoryInstance using the dynamic syntax.\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * // \"articles\" below will be a ModelCategoryInstance.\n * const response = await Starlight.posts.articles.list()\n * ```\n *\n * @category Instances\n */\nexport type DynamicModelInstance<D extends SerializedData> =\n ModelInstance<D> & {\n [key: string]: ModelCategoryInstance<D>\n }\n"]}
|