@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SerializedData, StarlightClient } from '../../types';
|
|
2
|
-
import { ModelCategorySelector,
|
|
3
|
-
export default function makeModelCategorySelector<D extends SerializedData>(client: StarlightClient, model: string):
|
|
4
|
-
export { ModelCategorySelector,
|
|
2
|
+
import { ModelCategorySelector, DynamicModelCategorySelector } from './types';
|
|
3
|
+
export default function makeModelCategorySelector<D extends SerializedData>(client: StarlightClient, model: string): DynamicModelCategorySelector<D>;
|
|
4
|
+
export { ModelCategorySelector, DynamicModelCategorySelector };
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -7,7 +7,7 @@ const ModelCategory_1 = __importDefault(require("../../instances/ModelCategory")
|
|
|
7
7
|
function makeModelCategorySelector(client, model) {
|
|
8
8
|
const selector = {
|
|
9
9
|
list(options) {
|
|
10
|
-
return client.get(`/models/${model}/categories`, options);
|
|
10
|
+
return client.get(`/models/${model}/categories`, Object.assign({}, options));
|
|
11
11
|
},
|
|
12
12
|
get(slug) {
|
|
13
13
|
return client.get(`/models/${model}/categories/${slug}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/selectors/ModelCategory/index.ts"],"names":[],"mappings":";;;;;AAQA,kFAAqE;AAErE,SAAwB,yBAAyB,CAC/C,MAAuB,EACvB,KAAa;IAEb,MAAM,QAAQ,GAA0B;QACtC,IAAI,CAAC,OAAO;YACV,OAAO,MAAM,CAAC,GAAG,CAAC,WAAW,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/selectors/ModelCategory/index.ts"],"names":[],"mappings":";;;;;AAQA,kFAAqE;AAErE,SAAwB,yBAAyB,CAC/C,MAAuB,EACvB,KAAa;IAEb,MAAM,QAAQ,GAA0B;QACtC,IAAI,CAAC,OAAO;YACV,OAAO,MAAM,CAAC,GAAG,CAAC,WAAW,KAAK,aAAa,oBAAO,OAAO,EAAG,CAAA;QAClE,CAAC;QAED,GAAG,CAAC,IAAI;YACN,OAAO,MAAM,CAAC,GAAG,CAAC,WAAW,KAAK,eAAe,IAAI,EAAE,CAAC,CAAA;QAC1D,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,CAAoC,CAAA;AACvC,CAAC;AAvBD,4CAuBC","sourcesContent":["import {\n ModelCategory,\n SerializedData,\n StarlightClient,\n StarlightItemResponse,\n StarlightListResponse,\n} from '../../types'\nimport { ModelCategorySelector, DynamicModelCategorySelector } from './types'\nimport makeModelCategoryInstance from '../../instances/ModelCategory'\n\nexport default function makeModelCategorySelector<D extends SerializedData>(\n client: StarlightClient,\n model: string\n): DynamicModelCategorySelector<D> {\n const selector: ModelCategorySelector = {\n list(options): Promise<StarlightListResponse<ModelCategory>> {\n return client.get(`/models/${model}/categories`, { ...options })\n },\n\n get(slug): Promise<StarlightItemResponse<ModelCategory>> {\n return client.get(`/models/${model}/categories/${slug}`)\n },\n }\n\n return new Proxy(selector, {\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 DynamicModelCategorySelector<D>\n}\n\nexport { ModelCategorySelector, DynamicModelCategorySelector }\n"]}
|
|
@@ -1,16 +1,59 @@
|
|
|
1
|
-
import { ModelCategory, SerializedData, StarlightItemResponse, StarlightListResponse } from '../../types';
|
|
1
|
+
import { BaseRequestParameters, ModelCategory, SerializedData, StarlightItemResponse, StarlightListResponse } from '../../types';
|
|
2
2
|
import { ModelCategoryInstance } from '../../instances/ModelCategory';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export interface ListModelCategoriesOptions extends BaseRequestParameters {
|
|
4
|
+
/**
|
|
5
|
+
* Define how items will be ordered. Check this field type to see the
|
|
6
|
+
* allowed options.
|
|
7
|
+
*/
|
|
7
8
|
order?: 'title:asc' | 'title:desc' | 'entry_count:asc' | 'entry_count:desc';
|
|
8
|
-
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A Selector that provide methods to list and request information on
|
|
12
|
+
* {@apilink ModelCategory | ModelCategories}.
|
|
13
|
+
*
|
|
14
|
+
* You can use a ModelCategorySelector by accessing
|
|
15
|
+
* {@apilink ModelInstance.categories}.
|
|
16
|
+
*
|
|
17
|
+
* @group Selectors
|
|
18
|
+
*/
|
|
9
19
|
export interface ModelCategorySelector {
|
|
10
20
|
list(options?: ListModelCategoriesOptions): Promise<StarlightListResponse<ModelCategory>>;
|
|
21
|
+
/**
|
|
22
|
+
* Returns a {@link StarlightItemResponse} with a single {@link ModelCategory}.
|
|
23
|
+
*
|
|
24
|
+
* @example Requesting information from a category "premium" from a model of slug "plans".
|
|
25
|
+
* ```ts
|
|
26
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
27
|
+
*
|
|
28
|
+
* const response = await Starlight.plans.premium.get()
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @param slug The category slug.
|
|
32
|
+
*/
|
|
11
33
|
get(slug: string): Promise<StarlightItemResponse<ModelCategory>>;
|
|
12
34
|
}
|
|
13
|
-
|
|
35
|
+
/**
|
|
36
|
+
* A Selector that provide all {@link ModelCategorySelector} methods and adds
|
|
37
|
+
* support for creating {@apilink ModelCategoryInstance | ModelCategoryInstances}
|
|
38
|
+
* using the dynamic syntax.
|
|
39
|
+
*
|
|
40
|
+
* See {@link ModelCategorySelector} to view all available methods. You can use
|
|
41
|
+
* a DynamicModelCategorySelector by accessing {@apilink ModelInstance.categories}.
|
|
42
|
+
*
|
|
43
|
+
* See {@doclink requests-and-responses#dynamic-syntax | Dynamic Instances}
|
|
44
|
+
* documentation to learn more about the dynamic syntax.
|
|
45
|
+
*
|
|
46
|
+
* @example Accessing a ModelCategorySelector using the dynamic syntax on a model of slug "posts"
|
|
47
|
+
* ```ts
|
|
48
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
49
|
+
*
|
|
50
|
+
* // "articles" below will be a ModelCategorySelector.
|
|
51
|
+
* const response = await Starlight.posts.categories.articles.list()
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @category Instances
|
|
55
|
+
*/
|
|
56
|
+
export declare type DynamicModelCategorySelector<D extends SerializedData> = ModelCategorySelector & {
|
|
14
57
|
[slug: string]: ModelCategoryInstance<D>;
|
|
15
58
|
};
|
|
16
59
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/selectors/ModelCategory/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAErE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/selectors/ModelCategory/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAErE,MAAM,WAAW,0BAA2B,SAAQ,qBAAqB;IACvE;;;OAGG;IACH,KAAK,CAAC,EAAE,WAAW,GAAG,YAAY,GAAG,iBAAiB,GAAG,kBAAkB,CAAA;CAC5E;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,CACF,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,CAAC,qBAAqB,CAAC,aAAa,CAAC,CAAC,CAAA;IAEhD;;;;;;;;;;;OAWG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,aAAa,CAAC,CAAC,CAAA;CACjE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,oBAAY,4BAA4B,CAAC,CAAC,SAAS,cAAc,IAC/D,qBAAqB,GAAG;IACtB,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAA;CACzC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/selectors/ModelCategory/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n ModelCategory,\n SerializedData,\n StarlightItemResponse,\n StarlightListResponse,\n} from '../../types'\nimport { ModelCategoryInstance } from '../../instances/ModelCategory'\n\nexport
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/selectors/ModelCategory/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n BaseRequestParameters,\n ModelCategory,\n SerializedData,\n StarlightItemResponse,\n StarlightListResponse,\n} from '../../types'\nimport { ModelCategoryInstance } from '../../instances/ModelCategory'\n\nexport interface ListModelCategoriesOptions extends BaseRequestParameters {\n /**\n * Define how items will be ordered. Check this field type to see the\n * allowed options.\n */\n order?: 'title:asc' | 'title:desc' | 'entry_count:asc' | 'entry_count:desc'\n}\n\n/**\n * A Selector that provide methods to list and request information on\n * {@apilink ModelCategory | ModelCategories}.\n *\n * You can use a ModelCategorySelector by accessing\n * {@apilink ModelInstance.categories}.\n *\n * @group Selectors\n */\nexport interface ModelCategorySelector {\n list(\n options?: ListModelCategoriesOptions\n ): Promise<StarlightListResponse<ModelCategory>>\n\n /**\n * Returns a {@link StarlightItemResponse} with a single {@link ModelCategory}.\n *\n * @example Requesting information from a category \"premium\" from a model of slug \"plans\".\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.plans.premium.get()\n * ```\n *\n * @param slug The category slug.\n */\n get(slug: string): Promise<StarlightItemResponse<ModelCategory>>\n}\n\n/**\n * A Selector that provide all {@link ModelCategorySelector} methods and adds\n * support for creating {@apilink ModelCategoryInstance | ModelCategoryInstances}\n * using the dynamic syntax.\n *\n * See {@link ModelCategorySelector} to view all available methods. You can use\n * a DynamicModelCategorySelector by accessing {@apilink ModelInstance.categories}.\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 ModelCategorySelector using the dynamic syntax on a model of slug \"posts\"\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * // \"articles\" below will be a ModelCategorySelector.\n * const response = await Starlight.posts.categories.articles.list()\n * ```\n *\n * @category Instances\n */\nexport type DynamicModelCategorySelector<D extends SerializedData> =\n ModelCategorySelector & {\n [slug: string]: ModelCategoryInstance<D>\n }\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarlightClient } from '../../types';
|
|
2
|
-
import { SearchSelector } from './types';
|
|
2
|
+
import { SearchEntriesParams, SearchSelector } from './types';
|
|
3
3
|
export default function makeSearchSelector(client: StarlightClient): SearchSelector;
|
|
4
|
-
export { SearchSelector };
|
|
4
|
+
export { SearchSelector, SearchEntriesParams };
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/selectors/Search/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EAEhB,MAAM,aAAa,CAAA;AACpB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/selectors/Search/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EAEhB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7D,MAAM,CAAC,OAAO,UAAU,kBAAkB,CACxC,MAAM,EAAE,eAAe,GACtB,cAAc,CAQhB;AAED,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/selectors/Search/index.ts"],"names":[],"mappings":";;AAQA,SAAwB,kBAAkB,CACxC,MAAuB;IAEvB,OAAO;QACL,OAAO,CACL,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/selectors/Search/index.ts"],"names":[],"mappings":";;AAQA,SAAwB,kBAAkB,CACxC,MAAuB;IAEvB,OAAO;QACL,OAAO,CACL,OAA4B;YAE5B,OAAO,MAAM,CAAC,GAAG,CAAC,iBAAiB,oBAAO,OAAO,EAAG,CAAA;QACtD,CAAC;KACF,CAAA;AACH,CAAC;AAVD,qCAUC","sourcesContent":["import {\n Entry,\n SerializedData,\n StarlightClient,\n StarlightListResponse,\n} from '../../types'\nimport { SearchEntriesParams, SearchSelector } from './types'\n\nexport default function makeSearchSelector(\n client: StarlightClient\n): SearchSelector {\n return {\n entries<T extends SerializedData = Record<string, unknown>>(\n options: SearchEntriesParams\n ): Promise<StarlightListResponse<Entry<T>>> {\n return client.get('/search/entries', { ...options })\n },\n }\n}\n\nexport { SearchSelector, SearchEntriesParams }\n"]}
|
|
@@ -1,14 +1,87 @@
|
|
|
1
|
-
import { Entry, SerializedData, StarlightListResponse } from '../../types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { BaseRequestParameters, Entry, SerializedData, StarlightListResponse } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Request parameters for searching entries.
|
|
4
|
+
*
|
|
5
|
+
* Used by {@apilink SearchSelector.entries}.
|
|
6
|
+
*
|
|
7
|
+
* @group Request Parameters
|
|
8
|
+
*/
|
|
9
|
+
export interface SearchEntriesParams extends BaseRequestParameters {
|
|
10
|
+
/**
|
|
11
|
+
* A comma-separated list of models. Only entries in these models
|
|
12
|
+
* will be returned. If undefined, entries from all
|
|
13
|
+
* workspace models will be listed.
|
|
14
|
+
*
|
|
15
|
+
* For instance, to show only entries in the "posts" and "videos" categories,
|
|
16
|
+
* pass `'posts,videos'`.
|
|
17
|
+
*/
|
|
6
18
|
models?: string;
|
|
19
|
+
/**
|
|
20
|
+
* A comma-separated list of categories. Only entries in these categories
|
|
21
|
+
* will be returned. If undefined, all entries will be listed, independently
|
|
22
|
+
* of their categories.
|
|
23
|
+
*
|
|
24
|
+
* For instance, to show only entries in the "news" and "articles" categories,
|
|
25
|
+
* pass `'news,category'`.
|
|
26
|
+
*/
|
|
7
27
|
categories?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Define how items will be ordered. Check this field type to see the
|
|
30
|
+
* allowed options.
|
|
31
|
+
*/
|
|
8
32
|
order?: 'title:asc' | 'title:desc' | 'published_at:asc' | 'published_at:desc' | 'updated_at:asc' | 'updated_at:desc';
|
|
33
|
+
/**
|
|
34
|
+
* If defined, removes the given item from the list. Useful to create "related
|
|
35
|
+
* posts" lists.
|
|
36
|
+
*
|
|
37
|
+
* Note: this field only accepts IDs, and not slugs. Only one ID is allowed.
|
|
38
|
+
*/
|
|
9
39
|
except?: number;
|
|
10
|
-
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A Selector that provide methods to search for content. Only entry search
|
|
43
|
+
* is supported for the time being.
|
|
44
|
+
*
|
|
45
|
+
* You can use a SearchSelector by accessing
|
|
46
|
+
* {@apilink StarlightClient.search}.
|
|
47
|
+
*
|
|
48
|
+
* @group Selectors
|
|
49
|
+
*/
|
|
11
50
|
export interface SearchSelector {
|
|
12
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Returns a {@link StarlightListResponse} with a list of
|
|
53
|
+
* {@apilink Entry | Entries}. By default, entries from all models are
|
|
54
|
+
* returned, but filtering by model can be configured.
|
|
55
|
+
*
|
|
56
|
+
* @example Listing all entries in all workspace models.
|
|
57
|
+
* ```ts
|
|
58
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
59
|
+
*
|
|
60
|
+
* const response = await Starlight.search.entries()
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @example Searching for "hello world" within all entries in all workspace models.
|
|
64
|
+
* ```ts
|
|
65
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
66
|
+
*
|
|
67
|
+
* const response = await Starlight.search.entries({
|
|
68
|
+
* query: 'hello world'
|
|
69
|
+
* })
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @example Filtering the last example within specific models.
|
|
73
|
+
* ```ts
|
|
74
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
75
|
+
*
|
|
76
|
+
* const response = await Starlight.search.entries({
|
|
77
|
+
* query: 'hello world',
|
|
78
|
+
* models: 'posts,videos,magazines'
|
|
79
|
+
* })
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @param options An optional object of request parameters. See
|
|
83
|
+
* {@link SearchEntriesParams} for all available options.
|
|
84
|
+
*/
|
|
85
|
+
entries<T extends SerializedData = Record<string, unknown>>(options?: SearchEntriesParams): Promise<StarlightListResponse<Entry<T>>>;
|
|
13
86
|
}
|
|
14
87
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/selectors/Search/types.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/selectors/Search/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,KAAK,EACL,cAAc,EACd,qBAAqB,EACtB,MAAM,aAAa,CAAA;AAEpB;;;;;;GAMG;AACH,MAAM,WAAW,mBAAoB,SAAQ,qBAAqB;IAChE;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;OAGG;IACH,KAAK,CAAC,EACF,WAAW,GACX,YAAY,GACZ,kBAAkB,GAClB,mBAAmB,GACnB,gBAAgB,GAChB,iBAAiB,CAAA;IACrB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,OAAO,CAAC,CAAC,SAAS,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxD,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;CAC5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/selectors/Search/types.ts"],"names":[],"mappings":"","sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/selectors/Search/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n BaseRequestParameters,\n Entry,\n SerializedData,\n StarlightListResponse,\n} from '../../types'\n\n/**\n * Request parameters for searching entries.\n *\n * Used by {@apilink SearchSelector.entries}.\n *\n * @group Request Parameters\n */\nexport interface SearchEntriesParams extends BaseRequestParameters {\n /**\n * A comma-separated list of models. Only entries in these models\n * will be returned. If undefined, entries from all\n * workspace models will be listed.\n *\n * For instance, to show only entries in the \"posts\" and \"videos\" categories,\n * pass `'posts,videos'`.\n */\n models?: string\n /**\n * A comma-separated list of categories. Only entries in these categories\n * will be returned. If undefined, all entries will be listed, independently\n * of their categories.\n *\n * For instance, to show only entries in the \"news\" and \"articles\" categories,\n * pass `'news,category'`.\n */\n categories?: string\n /**\n * Define how items 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 | 'updated_at:asc'\n | 'updated_at:desc'\n /**\n * If defined, removes the given item from the list. Useful to create \"related\n * posts\" lists.\n *\n * Note: this field only accepts IDs, and not slugs. Only one ID is allowed.\n */\n except?: number\n}\n\n/**\n * A Selector that provide methods to search for content. Only entry search\n * is supported for the time being.\n *\n * You can use a SearchSelector by accessing\n * {@apilink StarlightClient.search}.\n *\n * @group Selectors\n */\nexport interface SearchSelector {\n /**\n * Returns a {@link StarlightListResponse} with a list of\n * {@apilink Entry | Entries}. By default, entries from all models are\n * returned, but filtering by model can be configured.\n *\n * @example Listing all entries in all workspace models.\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.search.entries()\n * ```\n *\n * @example Searching for \"hello world\" within all entries in all workspace models.\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.search.entries({\n * query: 'hello world'\n * })\n * ```\n *\n * @example Filtering the last example within specific models.\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.search.entries({\n * query: 'hello world',\n * models: 'posts,videos,magazines'\n * })\n * ```\n *\n * @param options An optional object of request parameters. See\n * {@link SearchEntriesParams} for all available options.\n */\n entries<T extends SerializedData = Record<string, unknown>>(\n options?: SearchEntriesParams\n ): Promise<StarlightListResponse<Entry<T>>>\n}\n"]}
|
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
import { SerializedData, Singleton, StarlightItemResponse, StarlightListResponse } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* A Selector that provide methods to list and request information on
|
|
4
|
+
* {@apilink Singleton | Singletons}.
|
|
5
|
+
*
|
|
6
|
+
* You can use an SingletonSelector by accessing
|
|
7
|
+
* {@apilink ModelInstance.singletons}.
|
|
8
|
+
*
|
|
9
|
+
* @group Selectors
|
|
10
|
+
*/
|
|
2
11
|
export interface SingletonSelector {
|
|
12
|
+
/**
|
|
13
|
+
* Returns a {@link StarlightItemResponse} with a single {@link Singleton}.
|
|
14
|
+
* This methods supports typing the returned Singleton by passing its data
|
|
15
|
+
* type as the generic type `<D>`.
|
|
16
|
+
*
|
|
17
|
+
* @example Requesting information from a singleton of slug "home".
|
|
18
|
+
* ```ts
|
|
19
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
20
|
+
*
|
|
21
|
+
* const response = await Starlight.singletons.get('home')
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example Typing last example's response.
|
|
25
|
+
* ```ts
|
|
26
|
+
* import Starlight, { StringField, MediaField, VisualField } from '@starlightcms/js-sdk'
|
|
27
|
+
*
|
|
28
|
+
* type HomeFields = {
|
|
29
|
+
* title: StringField
|
|
30
|
+
* subtitle: StringField
|
|
31
|
+
* hero_image: MediaField
|
|
32
|
+
* hero_content: VisualField
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* // `response.data` will be of type Singleton<HomeFields>
|
|
36
|
+
* const response = await Starlight.singletons.get<HomeFields>('home')
|
|
37
|
+
* ```
|
|
38
|
+
* @typeParam D - The type of the returned Singleton's `data` property.
|
|
39
|
+
* @param slug The singleton slug.
|
|
40
|
+
*/
|
|
3
41
|
get<D extends SerializedData>(slug: string): Promise<StarlightItemResponse<Singleton<D>>>;
|
|
42
|
+
/**
|
|
43
|
+
* Returns a {@link StarlightListResponse} with a list of
|
|
44
|
+
* {@apilink Singleton | Singletons}.
|
|
45
|
+
*
|
|
46
|
+
* @example Requesting all workspace singletons.
|
|
47
|
+
* ```ts
|
|
48
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
49
|
+
*
|
|
50
|
+
* const response = await Starlight.singletons.list()
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
4
53
|
list(): Promise<StarlightListResponse<Singleton<Record<string, unknown>>>>;
|
|
5
54
|
}
|
|
6
55
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/selectors/Singleton/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,SAAS,EACT,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,aAAa,CAAA;AAEpB,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,CAAC,SAAS,cAAc,EAC1B,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/selectors/Singleton/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,SAAS,EACT,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,aAAa,CAAA;AAEpB;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,GAAG,CAAC,CAAC,SAAS,cAAc,EAC1B,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAE/C;;;;;;;;;;OAUG;IACH,IAAI,IAAI,OAAO,CAAC,qBAAqB,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;CAC3E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/selectors/Singleton/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n SerializedData,\n Singleton,\n StarlightItemResponse,\n StarlightListResponse,\n} from '../../types'\n\nexport interface SingletonSelector {\n get<D extends SerializedData>(\n slug: string\n ): Promise<StarlightItemResponse<Singleton<D>>>\n list(): Promise<StarlightListResponse<Singleton<Record<string, unknown>>>>\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/selectors/Singleton/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n SerializedData,\n Singleton,\n StarlightItemResponse,\n StarlightListResponse,\n} from '../../types'\n\n/**\n * A Selector that provide methods to list and request information on\n * {@apilink Singleton | Singletons}.\n *\n * You can use an SingletonSelector by accessing\n * {@apilink ModelInstance.singletons}.\n *\n * @group Selectors\n */\nexport interface SingletonSelector {\n /**\n * Returns a {@link StarlightItemResponse} with a single {@link Singleton}.\n * This methods supports typing the returned Singleton by passing its data\n * type as the generic type `<D>`.\n *\n * @example Requesting information from a singleton of slug \"home\".\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.singletons.get('home')\n * ```\n *\n * @example Typing last example's response.\n * ```ts\n * import Starlight, { StringField, MediaField, VisualField } from '@starlightcms/js-sdk'\n *\n * type HomeFields = {\n * title: StringField\n * subtitle: StringField\n * hero_image: MediaField\n * hero_content: VisualField\n * }\n *\n * // `response.data` will be of type Singleton<HomeFields>\n * const response = await Starlight.singletons.get<HomeFields>('home')\n * ```\n * @typeParam D - The type of the returned Singleton's `data` property.\n * @param slug The singleton slug.\n */\n get<D extends SerializedData>(\n slug: string\n ): Promise<StarlightItemResponse<Singleton<D>>>\n\n /**\n * Returns a {@link StarlightListResponse} with a list of\n * {@apilink Singleton | Singletons}.\n *\n * @example Requesting all workspace singletons.\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.singletons.list()\n * ```\n */\n list(): Promise<StarlightListResponse<Singleton<Record<string, unknown>>>>\n}\n"]}
|
|
@@ -1,13 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base interface used by all entities returned by the API.
|
|
3
|
+
*
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
1
6
|
interface StarlightEntity {
|
|
2
7
|
id: number;
|
|
3
8
|
created_at: string;
|
|
4
9
|
updated_at?: string;
|
|
5
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Represents a Model Category entity returned by the API.
|
|
13
|
+
*
|
|
14
|
+
* @group API Entities
|
|
15
|
+
*/
|
|
6
16
|
export interface ModelCategory extends StarlightEntity {
|
|
7
17
|
title: string;
|
|
8
18
|
slug: string;
|
|
9
19
|
entry_count?: number;
|
|
10
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Represents a Media File entity returned by the API.
|
|
23
|
+
*
|
|
24
|
+
* @group API Entities
|
|
25
|
+
*/
|
|
11
26
|
export interface MediaFile extends StarlightEntity {
|
|
12
27
|
variation: string;
|
|
13
28
|
path: string;
|
|
@@ -16,6 +31,11 @@ export interface MediaFile extends StarlightEntity {
|
|
|
16
31
|
filesize: number;
|
|
17
32
|
meta?: Record<string, unknown>;
|
|
18
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Represents a Media Object entity returned by the API.
|
|
36
|
+
*
|
|
37
|
+
* @group API Entities
|
|
38
|
+
*/
|
|
19
39
|
export interface MediaObject extends StarlightEntity {
|
|
20
40
|
name: string;
|
|
21
41
|
extension: string;
|
|
@@ -24,19 +44,162 @@ export interface MediaObject extends StarlightEntity {
|
|
|
24
44
|
alt?: string;
|
|
25
45
|
description?: string;
|
|
26
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Represents an Author entity returned by the API. Authors are returned in
|
|
49
|
+
* {@link Entry} requests.
|
|
50
|
+
*
|
|
51
|
+
* @group API Entities
|
|
52
|
+
*/
|
|
27
53
|
export interface Author {
|
|
28
54
|
id: number;
|
|
29
55
|
name: string;
|
|
30
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Represents a Model entity returned by the API.
|
|
59
|
+
*
|
|
60
|
+
* @group API Entities
|
|
61
|
+
*/
|
|
31
62
|
export interface Model extends StarlightEntity {
|
|
32
63
|
title: string;
|
|
33
64
|
slug: string;
|
|
34
65
|
entry_count?: number;
|
|
35
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Represents content data returned by either an {@link Entry} or
|
|
69
|
+
* {@link Singleton} entity from the API.
|
|
70
|
+
*
|
|
71
|
+
* This is a utility type used internally by the SDK and you don't
|
|
72
|
+
* need to use it. Its purpose is to constraint Entry and Singleton
|
|
73
|
+
* data to the shape of a JS object.
|
|
74
|
+
*
|
|
75
|
+
* @category Internal Types
|
|
76
|
+
*/
|
|
36
77
|
export declare type SerializedData = Record<string, unknown> | undefined;
|
|
37
|
-
|
|
38
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Utility type that creates a string map of all fields of the given
|
|
80
|
+
* SerializedData type with the `field:` prefix. This syntax allows to filter
|
|
81
|
+
* specific fields when listing {@apilink Entry | Entries}:
|
|
82
|
+
*
|
|
83
|
+
* - Text fields can be filtered by a string query. This works just like
|
|
84
|
+
* passing a `query` parameter, but it only applies to one field.
|
|
85
|
+
* - Boolean fields can be filtered by "true" or "false".
|
|
86
|
+
*
|
|
87
|
+
* If a request uses this type, it means that this syntax can be used in their
|
|
88
|
+
* parameters:
|
|
89
|
+
*
|
|
90
|
+
* ```ts
|
|
91
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
92
|
+
*
|
|
93
|
+
* const response = await Starlight.posts.entries.list({
|
|
94
|
+
* // EntrySelector.list() supports the "field:foo" syntax:
|
|
95
|
+
* 'field:content': 'hello world',
|
|
96
|
+
* 'field:is_featured': true,
|
|
97
|
+
*
|
|
98
|
+
* // EntrySelector.list() also support other parameters,
|
|
99
|
+
* // which are passed in this object too:
|
|
100
|
+
* page: 42,
|
|
101
|
+
* limit: 20,
|
|
102
|
+
* })
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @remark
|
|
106
|
+
*
|
|
107
|
+
* The information below is only useful for SDK maintainers.
|
|
108
|
+
*
|
|
109
|
+
* This type receives a {@link SerializedData}-like structure, like an object.
|
|
110
|
+
* For instance, for an {@link Entry} with fields "content" and "summary",
|
|
111
|
+
* the generated type would look like this:
|
|
112
|
+
*
|
|
113
|
+
* ```ts
|
|
114
|
+
* type GeneratedType = {
|
|
115
|
+
* 'field:content'?: string
|
|
116
|
+
* 'field:summary'?: string
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* However, note that QueryableFields receive a {@link SerializedData}, not an
|
|
121
|
+
* {@link Entry}:
|
|
122
|
+
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* import { VisualField, StringField } from '@starlightcms/js-sdk'
|
|
125
|
+
*
|
|
126
|
+
* type EntryFields = {
|
|
127
|
+
* content: VisualField
|
|
128
|
+
* summary: StringField
|
|
129
|
+
* }
|
|
130
|
+
*
|
|
131
|
+
* type MyEntry = Entry<EntryFields>
|
|
132
|
+
*
|
|
133
|
+
* // Error TS2344: Type does not satisfy the constraint 'SerializedData'
|
|
134
|
+
* type GeneratedType = QueryableFields<MyEntry>
|
|
135
|
+
*
|
|
136
|
+
* // Works!
|
|
137
|
+
* type GeneratedType = QueryableFields<EntryFields>
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* This type is only useful to request methods that support
|
|
141
|
+
* field querying using the "field:foo" syntax.
|
|
142
|
+
*
|
|
143
|
+
* @category Internal Types
|
|
144
|
+
*/
|
|
145
|
+
export declare type QueryableFields<D extends SerializedData> = {
|
|
146
|
+
[K in keyof D as `field:${string & K}`]?: string | boolean;
|
|
39
147
|
};
|
|
148
|
+
/**
|
|
149
|
+
* Utility type that return {@link QueryableFields} if the given type T
|
|
150
|
+
* is an {@link Entry} or a {@link Singleton}, but generates an empty object
|
|
151
|
+
* otherwise.
|
|
152
|
+
*
|
|
153
|
+
* Fun fact: internally, Entries and Singletons have parent Models,
|
|
154
|
+
* which is why they are called "modelables" here.
|
|
155
|
+
*
|
|
156
|
+
* @category Internal Types
|
|
157
|
+
*/
|
|
158
|
+
export declare type WithQueryableFieldsOnModelables<T> = T extends Entry<never> | Singleton<never> ? QueryableFields<Pick<T, 'data'>> : Record<string, never>;
|
|
159
|
+
/**
|
|
160
|
+
* Represents an Entry entity returned by the API.
|
|
161
|
+
*
|
|
162
|
+
* An Entry's `data` field can be further typed by passing an object-like
|
|
163
|
+
* structure as the D generic type. This is useful to provide type-safety to
|
|
164
|
+
* your application, since the `data` field is a generic JS object by default.
|
|
165
|
+
*
|
|
166
|
+
* It's recommended to use the Field types provided by this SDK to type your
|
|
167
|
+
* entities using a type definition file on your project. For instance:
|
|
168
|
+
*
|
|
169
|
+
* ```ts
|
|
170
|
+
* // starlight.d.ts file
|
|
171
|
+
* import { VisualField, MediaField } from '@starlightcms/js-sdk'
|
|
172
|
+
*
|
|
173
|
+
* type PostFields = {
|
|
174
|
+
* featured_image: MediaField
|
|
175
|
+
* content: VisualField
|
|
176
|
+
* }
|
|
177
|
+
*
|
|
178
|
+
* declare module '@starlightcms/js-sdk' {
|
|
179
|
+
* export interface DefaultModelDefinition {
|
|
180
|
+
* posts: PostFields
|
|
181
|
+
* }
|
|
182
|
+
* }
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* You can place this type definition file anywhere in your repository, but it's
|
|
186
|
+
* good practice to place it at the same level as your root index.ts file. Then,
|
|
187
|
+
* in your files, all SDK calls will correctly type `posts`:
|
|
188
|
+
*
|
|
189
|
+
* ```ts
|
|
190
|
+
* import Starlight from '@starlightcms/js-sdk'
|
|
191
|
+
*
|
|
192
|
+
* // response type will be StarlightItemResponse<Entry<PostFields>> on request success
|
|
193
|
+
* const response = await Starlight.posts.entries.get('hello-world')
|
|
194
|
+
*
|
|
195
|
+
* // helloWorld type is Entry<PostFields>
|
|
196
|
+
* const helloWorld = response.data
|
|
197
|
+
* ```
|
|
198
|
+
*
|
|
199
|
+
* See {@apilink DefaultModelDefinition} for more info.
|
|
200
|
+
*
|
|
201
|
+
* @group API Entities
|
|
202
|
+
*/
|
|
40
203
|
export interface Entry<D extends SerializedData> extends Omit<StarlightEntity, 'created_at'> {
|
|
41
204
|
title: string;
|
|
42
205
|
slug: string;
|
|
@@ -46,21 +209,97 @@ export interface Entry<D extends SerializedData> extends Omit<StarlightEntity, '
|
|
|
46
209
|
category: ModelCategory | null;
|
|
47
210
|
published_at: string | null;
|
|
48
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Represents a Singleton entity returned by the API.
|
|
214
|
+
*
|
|
215
|
+
* A Singleton's `data` field can be further typed by passing an object-like
|
|
216
|
+
* structure as the D generic type. This is useful to provide type-safety to
|
|
217
|
+
* your application, since the `data` field is a generic JS object by default.
|
|
218
|
+
*
|
|
219
|
+
* It's recommended to use the Field types provided by this SDK to type your
|
|
220
|
+
* Singletons. For instance:
|
|
221
|
+
*
|
|
222
|
+
* ```ts
|
|
223
|
+
* import { StringField, VisualField, MediaField } from '@starlightcms/js-sdk'
|
|
224
|
+
*
|
|
225
|
+
* type HomeFields = {
|
|
226
|
+
* site_title: StringField
|
|
227
|
+
* hero_image: MediaField
|
|
228
|
+
* hero_content: VisualField
|
|
229
|
+
* }
|
|
230
|
+
*
|
|
231
|
+
* // response type will be StarlightItemResponse<Singleton<HomeFields>> on request success
|
|
232
|
+
* const response = Starlight.singletons.get<HomeFields>('home')
|
|
233
|
+
*
|
|
234
|
+
* // home type is Singleton<HomeFields>
|
|
235
|
+
* const home = response.data
|
|
236
|
+
* ```
|
|
237
|
+
*
|
|
238
|
+
* You could also place all your Singleton field types in the same type
|
|
239
|
+
* definition file used to configure Entry fields, which makes it easier to
|
|
240
|
+
* import these types in other files on your project. See
|
|
241
|
+
* {@apilink DefaultModelDefinition} for more info.
|
|
242
|
+
*
|
|
243
|
+
* @group API Entities
|
|
244
|
+
*/
|
|
49
245
|
export interface Singleton<D extends SerializedData> extends Omit<StarlightEntity, 'created_at'> {
|
|
50
246
|
title: string;
|
|
51
247
|
slug: string;
|
|
52
248
|
data: D;
|
|
53
249
|
published_at: string | null;
|
|
54
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Currently supported Collection types. This type is mainly used to provide
|
|
253
|
+
* autocompletion on IDEs, since it lets users use any string as well as the
|
|
254
|
+
* known supported types.
|
|
255
|
+
*
|
|
256
|
+
* @internal
|
|
257
|
+
*/
|
|
55
258
|
export declare type CollectionTypes = 'entry' | 'singleton' | 'media' | string;
|
|
259
|
+
/**
|
|
260
|
+
* Currently supported Collection entities. This type is mainly used to infer
|
|
261
|
+
* the collection type string (see {@link CollectionTypes}) from the type of
|
|
262
|
+
* entity that that Collection holds.
|
|
263
|
+
*
|
|
264
|
+
* @internal
|
|
265
|
+
*/
|
|
266
|
+
export declare type CollectionEntityTypes = Entry<never> | Singleton<never> | MediaObject | unknown;
|
|
267
|
+
/**
|
|
268
|
+
* Infers a Collection type from an entity type. See {@link CollectionTypes} and
|
|
269
|
+
* {@link CollectionEntityTypes} to know more.
|
|
270
|
+
*
|
|
271
|
+
* @internal
|
|
272
|
+
*/
|
|
273
|
+
export declare type CollectionTypeMapper<T extends CollectionEntityTypes> = T extends Entry<any> ? 'entry' : T extends Singleton<any> ? 'singleton' : T extends MediaObject ? 'media' : string;
|
|
274
|
+
/**
|
|
275
|
+
* Represents a Collection entity returned by the API.
|
|
276
|
+
*
|
|
277
|
+
* You can request collections using a {@link CollectionInstance} or a
|
|
278
|
+
* {@link CollectionSelector}.
|
|
279
|
+
*
|
|
280
|
+
* @group API Entities
|
|
281
|
+
*/
|
|
56
282
|
export interface Collection<T extends CollectionTypes = string> extends StarlightEntity {
|
|
57
283
|
title: string;
|
|
58
284
|
slug: string;
|
|
59
285
|
type: T;
|
|
60
286
|
item_count?: number;
|
|
61
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* Currently supported Relation types.
|
|
290
|
+
*/
|
|
62
291
|
declare type RelationTypes = Entry<never> | Singleton<never> | MediaObject | Collection | unknown;
|
|
292
|
+
/**
|
|
293
|
+
* Represents a Relation entity returned by the API.
|
|
294
|
+
*
|
|
295
|
+
* @group API Entities
|
|
296
|
+
*/
|
|
63
297
|
export interface Relation<T extends RelationTypes> {
|
|
298
|
+
/**
|
|
299
|
+
* The relation type, which is always a string. If the `object` field of this
|
|
300
|
+
* Relation is an Entry, type will be `entry`, if it's a Singleton, type will
|
|
301
|
+
* be `singleton`, and so on.
|
|
302
|
+
*/
|
|
64
303
|
type: T extends Entry<never> ? 'entry' : T extends Singleton<never> ? 'singleton' : T extends MediaObject ? 'media' : T extends Collection ? 'collection' : string;
|
|
65
304
|
id: number;
|
|
66
305
|
object: T;
|