@starlightcms/js-sdk 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/cjs/client.d.ts +41 -2
  2. package/dist/cjs/client.d.ts.map +1 -1
  3. package/dist/cjs/client.js +39 -0
  4. package/dist/cjs/client.js.map +1 -1
  5. package/dist/cjs/errors.d.ts +12 -0
  6. package/dist/cjs/errors.d.ts.map +1 -1
  7. package/dist/cjs/errors.js +7 -0
  8. package/dist/cjs/errors.js.map +1 -1
  9. package/dist/cjs/index.d.ts +21 -1
  10. package/dist/cjs/index.d.ts.map +1 -1
  11. package/dist/cjs/index.js +20 -0
  12. package/dist/cjs/index.js.map +1 -1
  13. package/dist/cjs/instances/Collection/index.d.ts +2 -2
  14. package/dist/cjs/instances/Collection/index.d.ts.map +1 -1
  15. package/dist/cjs/instances/Collection/index.js.map +1 -1
  16. package/dist/cjs/instances/Collection/types.d.ts +49 -5
  17. package/dist/cjs/instances/Collection/types.d.ts.map +1 -1
  18. package/dist/cjs/instances/Collection/types.js.map +1 -1
  19. package/dist/cjs/instances/Model/index.d.ts +3 -3
  20. package/dist/cjs/instances/Model/index.d.ts.map +1 -1
  21. package/dist/cjs/instances/Model/index.js.map +1 -1
  22. package/dist/cjs/instances/Model/types.d.ts +3 -3
  23. package/dist/cjs/instances/Model/types.js.map +1 -1
  24. package/dist/cjs/selectors/Collection/index.d.ts +3 -3
  25. package/dist/cjs/selectors/Collection/index.js.map +1 -1
  26. package/dist/cjs/selectors/Collection/types.d.ts +2 -2
  27. package/dist/cjs/selectors/Collection/types.d.ts.map +1 -1
  28. package/dist/cjs/selectors/Collection/types.js.map +1 -1
  29. package/dist/cjs/selectors/Model/index.d.ts +3 -3
  30. package/dist/cjs/selectors/Model/index.js.map +1 -1
  31. package/dist/cjs/selectors/Model/types.d.ts +3 -3
  32. package/dist/cjs/selectors/Model/types.js.map +1 -1
  33. package/dist/cjs/selectors/ModelCategory/index.d.ts +3 -3
  34. package/dist/cjs/selectors/ModelCategory/index.js.map +1 -1
  35. package/dist/cjs/selectors/ModelCategory/types.d.ts +1 -1
  36. package/dist/cjs/selectors/ModelCategory/types.js.map +1 -1
  37. package/dist/cjs/types/entities.d.ts +158 -0
  38. package/dist/cjs/types/entities.d.ts.map +1 -1
  39. package/dist/cjs/types/entities.js.map +1 -1
  40. package/dist/cjs/types/fields.d.ts +63 -0
  41. package/dist/cjs/types/fields.d.ts.map +1 -1
  42. package/dist/cjs/types/fields.js.map +1 -1
  43. package/dist/cjs/types/index.d.ts +424 -11
  44. package/dist/cjs/types/index.d.ts.map +1 -1
  45. package/dist/cjs/types/index.js +2 -0
  46. package/dist/cjs/types/index.js.map +1 -1
  47. package/dist/cjs/types/instances.d.ts +4 -0
  48. package/dist/cjs/types/instances.d.ts.map +1 -0
  49. package/dist/cjs/types/instances.js +3 -0
  50. package/dist/cjs/types/instances.js.map +1 -0
  51. package/dist/cjs/types/selectors.d.ts +8 -0
  52. package/dist/cjs/types/selectors.d.ts.map +1 -0
  53. package/dist/cjs/types/selectors.js +3 -0
  54. package/dist/cjs/types/selectors.js.map +1 -0
  55. package/dist/cjs/types/visual.d.ts +69 -0
  56. package/dist/cjs/types/visual.d.ts.map +1 -1
  57. package/dist/cjs/types/visual.js.map +1 -1
  58. package/dist/esm/client.d.ts +41 -2
  59. package/dist/esm/client.d.ts.map +1 -1
  60. package/dist/esm/client.js +39 -0
  61. package/dist/esm/client.js.map +1 -1
  62. package/dist/esm/errors.d.ts +12 -0
  63. package/dist/esm/errors.d.ts.map +1 -1
  64. package/dist/esm/errors.js +7 -0
  65. package/dist/esm/errors.js.map +1 -1
  66. package/dist/esm/index.d.ts +21 -1
  67. package/dist/esm/index.d.ts.map +1 -1
  68. package/dist/esm/index.js +20 -0
  69. package/dist/esm/index.js.map +1 -1
  70. package/dist/esm/instances/Collection/index.d.ts +2 -2
  71. package/dist/esm/instances/Collection/index.d.ts.map +1 -1
  72. package/dist/esm/instances/Collection/index.js.map +1 -1
  73. package/dist/esm/instances/Collection/types.d.ts +49 -5
  74. package/dist/esm/instances/Collection/types.d.ts.map +1 -1
  75. package/dist/esm/instances/Collection/types.js.map +1 -1
  76. package/dist/esm/instances/Model/index.d.ts +3 -3
  77. package/dist/esm/instances/Model/index.d.ts.map +1 -1
  78. package/dist/esm/instances/Model/index.js.map +1 -1
  79. package/dist/esm/instances/Model/types.d.ts +3 -3
  80. package/dist/esm/instances/Model/types.js.map +1 -1
  81. package/dist/esm/selectors/Collection/index.d.ts +3 -3
  82. package/dist/esm/selectors/Collection/index.js.map +1 -1
  83. package/dist/esm/selectors/Collection/types.d.ts +2 -2
  84. package/dist/esm/selectors/Collection/types.d.ts.map +1 -1
  85. package/dist/esm/selectors/Collection/types.js.map +1 -1
  86. package/dist/esm/selectors/Model/index.d.ts +3 -3
  87. package/dist/esm/selectors/Model/index.js.map +1 -1
  88. package/dist/esm/selectors/Model/types.d.ts +3 -3
  89. package/dist/esm/selectors/Model/types.js.map +1 -1
  90. package/dist/esm/selectors/ModelCategory/index.d.ts +3 -3
  91. package/dist/esm/selectors/ModelCategory/index.js.map +1 -1
  92. package/dist/esm/selectors/ModelCategory/types.d.ts +1 -1
  93. package/dist/esm/selectors/ModelCategory/types.js.map +1 -1
  94. package/dist/esm/types/entities.d.ts +158 -0
  95. package/dist/esm/types/entities.d.ts.map +1 -1
  96. package/dist/esm/types/entities.js.map +1 -1
  97. package/dist/esm/types/fields.d.ts +63 -0
  98. package/dist/esm/types/fields.d.ts.map +1 -1
  99. package/dist/esm/types/fields.js.map +1 -1
  100. package/dist/esm/types/index.d.ts +424 -11
  101. package/dist/esm/types/index.d.ts.map +1 -1
  102. package/dist/esm/types/index.js +2 -0
  103. package/dist/esm/types/index.js.map +1 -1
  104. package/dist/esm/types/instances.d.ts +4 -0
  105. package/dist/esm/types/instances.d.ts.map +1 -0
  106. package/dist/esm/types/instances.js +2 -0
  107. package/dist/esm/types/instances.js.map +1 -0
  108. package/dist/esm/types/selectors.d.ts +8 -0
  109. package/dist/esm/types/selectors.d.ts.map +1 -0
  110. package/dist/esm/types/selectors.js +2 -0
  111. package/dist/esm/types/selectors.js.map +1 -0
  112. package/dist/esm/types/visual.d.ts +69 -0
  113. package/dist/esm/types/visual.d.ts.map +1 -1
  114. package/dist/esm/types/visual.js.map +1 -1
  115. package/package.json +1 -1
@@ -1,23 +1,61 @@
1
+ /**
2
+ * All supported block types.
3
+ *
4
+ * @group Visual Data Blocks
5
+ * @internal
6
+ */
1
7
  export declare type BlockType = 'paragraph' | 'quote' | 'header' | 'image' | 'raw' | 'list';
8
+ /**
9
+ * Base interface for types that represent block data.
10
+ *
11
+ * @group Visual Data Blocks
12
+ */
2
13
  export interface BlockData {
3
14
  [key: string]: unknown;
4
15
  }
16
+ /**
17
+ * Represents a Paragraph block, which is the default block type used
18
+ * for text content in the Visual Editor.
19
+ *
20
+ * @group Visual Data Blocks
21
+ */
5
22
  export interface ParagraphBlock extends BlockData {
6
23
  text: string;
7
24
  }
25
+ /**
26
+ * Represents a Header block, which is used to render h1 through h6 HTML elements.
27
+ *
28
+ * @group Visual Data Blocks
29
+ */
8
30
  export interface HeaderBlock extends BlockData {
9
31
  text: string;
10
32
  level: number;
11
33
  }
34
+ /**
35
+ * Represents a Quote block, which is used to render a blockquote HTML element.
36
+ *
37
+ * @group Visual Data Blocks
38
+ */
12
39
  export interface QuoteBlock extends BlockData {
13
40
  text: string;
14
41
  caption: string;
15
42
  alignment: 'left' | 'center';
16
43
  }
44
+ /**
45
+ * Represents an image file, used in Image blocks.
46
+ *
47
+ * @group Visual Data Blocks
48
+ * @internal
49
+ */
17
50
  declare type ImageFile = {
18
51
  url: string;
19
52
  width: number;
20
53
  };
54
+ /**
55
+ * Represents an Image block, which is used to render img or picture HTML elements.
56
+ *
57
+ * @group Visual Data Blocks
58
+ */
21
59
  export interface ImageBlock extends BlockData {
22
60
  id: number;
23
61
  url: string;
@@ -26,22 +64,53 @@ export interface ImageBlock extends BlockData {
26
64
  alt?: string;
27
65
  href?: string;
28
66
  }
67
+ /**
68
+ * Represents an HTML block, which is used to render custom HTML code. Mainly
69
+ * used to place embeds or heavily customized content structures.
70
+ *
71
+ * @group Visual Data Blocks
72
+ */
29
73
  export interface HTMLBlock extends BlockData {
30
74
  html: string;
31
75
  }
76
+ /**
77
+ * Represents a list item, which is used by List blocks.
78
+ *
79
+ * @group Visual Data Blocks
80
+ * @internal
81
+ */
32
82
  export interface ListItem {
33
83
  content: string;
34
84
  items?: ListItem[];
35
85
  }
86
+ /**
87
+ * Represents a List block, which is used to render ol or ul HTML elements.
88
+ *
89
+ * @group Visual Data Blocks
90
+ */
36
91
  export interface ListBlock extends BlockData {
37
92
  style: 'ordered' | 'unordered';
38
93
  items: ListItem[];
39
94
  }
95
+ /**
96
+ * A VisualDataBlock object represents a piece of content. Each block has a
97
+ * specific type and some data associated with it. For instance, a Paragraph
98
+ * block has text data, an Image block has a file path and image metadata, etc.
99
+ *
100
+ * @group Visual Data Blocks
101
+ */
40
102
  export interface VisualDataBlock<D extends BlockData = BlockData> {
41
103
  id: string;
42
104
  type: BlockType;
43
105
  data: D;
44
106
  }
107
+ /**
108
+ * VisualData represents content generated by Starlight using a "Visual Editor"
109
+ * field. It's an object-based data representation made out of "blocks". Each
110
+ * block has a type string and some data associated with it.
111
+ *
112
+ * @group Visual Data Blocks
113
+ */
45
114
  export interface VisualData {
46
115
  time?: number;
47
116
  version?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"visual.d.ts","sourceRoot":"","sources":["../../../src/types/visual.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS,GACjB,WAAW,GACX,OAAO,GACP,QAAQ,GACR,OAAO,GACP,KAAK,GACL,MAAM,CAAA;AAEV,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,cAAe,SAAQ,SAAS;IAC/C,IAAI,EAAE,MAAM,C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,SAAS,GAAG,WAAW,CAAA;IAC9B,KAAK,EAAE,QAAQ,EAAE,CAAA;CAClB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IAC9D,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,EAAE,CAAC,CAAA;CACR;AAED;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,eAAe,EAAE,CAAA;CAC1B"}
@@ -1 +1 @@
1
- {"version":3,"file":"visual.js","sourceRoot":"","sources":["../../../src/types/visual.ts"],"names":[],"mappings":"","sourcesContent":["export type BlockType =\n | 'paragraph'\n | 'quote'\n | 'header'\n | 'image'\n | 'raw'\n | 'list'\n\nexport interface BlockData {\n [key: string]: unknown\n}\n\nexport interface ParagraphBlock extends BlockData {\n text: string\n}\n\nexport interface HeaderBlock extends BlockData {\n text: string\n level: number\n}\n\nexport interface QuoteBlock extends BlockData {\n text: string\n caption: string\n alignment: 'left' | 'center'\n}\n\ntype ImageFile = {\n url: string\n width: number\n}\n\nexport interface ImageBlock extends BlockData {\n id: number\n url: string\n files: ImageFile[]\n caption?: string\n alt?: string\n href?: string\n}\n\nexport interface HTMLBlock extends BlockData {\n html: string\n}\n\nexport interface ListItem {\n content: string\n items?: ListItem[]\n}\n\nexport interface ListBlock extends BlockData {\n style: 'ordered' | 'unordered'\n items: ListItem[]\n}\n\nexport interface VisualDataBlock<D extends BlockData = BlockData> {\n id: string\n type: BlockType\n data: D\n}\n\nexport interface VisualData {\n time?: number\n version?: string\n blocks: VisualDataBlock[]\n}\n"]}
1
+ {"version":3,"file":"visual.js","sourceRoot":"","sources":["../../../src/types/visual.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * All supported block types.\n *\n * @group Visual Data Blocks\n * @internal\n */\nexport type BlockType =\n | 'paragraph'\n | 'quote'\n | 'header'\n | 'image'\n | 'raw'\n | 'list'\n\n/**\n * Base interface for types that represent block data.\n *\n * @group Visual Data Blocks\n */\nexport interface BlockData {\n [key: string]: unknown\n}\n\n/**\n * Represents a Paragraph block, which is the default block type used\n * for text content in the Visual Editor.\n *\n * @group Visual Data Blocks\n */\nexport interface ParagraphBlock extends BlockData {\n text: string\n}\n\n/**\n * Represents a Header block, which is used to render h1 through h6 HTML elements.\n *\n * @group Visual Data Blocks\n */\nexport interface HeaderBlock extends BlockData {\n text: string\n level: number\n}\n\n/**\n * Represents a Quote block, which is used to render a blockquote HTML element.\n *\n * @group Visual Data Blocks\n */\nexport interface QuoteBlock extends BlockData {\n text: string\n caption: string\n alignment: 'left' | 'center'\n}\n\n/**\n * Represents an image file, used in Image blocks.\n *\n * @group Visual Data Blocks\n * @internal\n */\ntype ImageFile = {\n url: string\n width: number\n}\n\n/**\n * Represents an Image block, which is used to render img or picture HTML elements.\n *\n * @group Visual Data Blocks\n */\nexport interface ImageBlock extends BlockData {\n id: number\n url: string\n files: ImageFile[]\n caption?: string\n alt?: string\n href?: string\n}\n\n/**\n * Represents an HTML block, which is used to render custom HTML code. Mainly\n * used to place embeds or heavily customized content structures.\n *\n * @group Visual Data Blocks\n */\nexport interface HTMLBlock extends BlockData {\n html: string\n}\n\n/**\n * Represents a list item, which is used by List blocks.\n *\n * @group Visual Data Blocks\n * @internal\n */\nexport interface ListItem {\n content: string\n items?: ListItem[]\n}\n\n/**\n * Represents a List block, which is used to render ol or ul HTML elements.\n *\n * @group Visual Data Blocks\n */\nexport interface ListBlock extends BlockData {\n style: 'ordered' | 'unordered'\n items: ListItem[]\n}\n\n/**\n * A VisualDataBlock object represents a piece of content. Each block has a\n * specific type and some data associated with it. For instance, a Paragraph\n * block has text data, an Image block has a file path and image metadata, etc.\n *\n * @group Visual Data Blocks\n */\nexport interface VisualDataBlock<D extends BlockData = BlockData> {\n id: string\n type: BlockType\n data: D\n}\n\n/**\n * VisualData represents content generated by Starlight using a \"Visual Editor\"\n * field. It's an object-based data representation made out of \"blocks\". Each\n * block has a type string and some data associated with it.\n *\n * @group Visual Data Blocks\n */\nexport interface VisualData {\n time?: number\n version?: string\n blocks: VisualDataBlock[]\n}\n"]}
@@ -1,3 +1,42 @@
1
- import { DefaultModelDefinition, ProxiedStarlightClient, StarlightConfig, WorkspaceModelDefinition } from './types';
2
- export declare function makeClient<D extends WorkspaceModelDefinition = DefaultModelDefinition>(config?: StarlightConfig): ProxiedStarlightClient<D>;
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 from 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 the default client, 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
24
+ * Creating a new client and exporting it.
25
+ * ```ts
26
+ * import { makeStarlightClient } from '@starlightcms/js-sdk'
27
+ *
28
+ * const BlogClient = makeStarlightClient({
29
+ * workspace: '123123123'
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
@@ -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"}
@@ -15,6 +15,45 @@ import makeCollectionSelector from './selectors/Collection';
15
15
  import makeMediaSelector from './selectors/Media';
16
16
  import makeSearchSelector from './selectors/Search';
17
17
  import makeCollectionInstance from './instances/Collection';
18
+ /**
19
+ * Returns a new {@link DynamicStarlightClient}, which is a
20
+ * {@link StarlightClient} with support to create
21
+ * {@apilink ModelInstance | ModelInstances} using the dynamic syntax. To learn
22
+ * which methods a client supports, see {@link StarlightClient}.
23
+ *
24
+ * This function accepts a {@link StarlightConfig} object and can be used to
25
+ * create new clients that connect to a single Starlight workspace. Each client
26
+ * returned by this function is separate and independent from the others.
27
+ *
28
+ * If you only need to make requests to a single workspace, it's probably easier
29
+ * to use the SDK's default client. To use the default client, you only need to
30
+ * import the default object exported by the SDK:
31
+ *
32
+ * ```ts
33
+ * // `Starlight` below is the default StarlightClient.
34
+ * import Starlight from '@starlightcms/js-sdk'
35
+ * ```
36
+ *
37
+ * See {@link default} for more info on how to use the default client.
38
+ *
39
+ * @example
40
+ * Creating a new client and exporting it.
41
+ * ```ts
42
+ * import { makeStarlightClient } from '@starlightcms/js-sdk'
43
+ *
44
+ * const BlogClient = makeStarlightClient({
45
+ * workspace: '123123123'
46
+ * })
47
+ *
48
+ * // Feel free to export the new client so your application can use it.
49
+ * export default BlogClient
50
+ * ```
51
+ *
52
+ * @param config The client configuration object. You need to provide at least
53
+ * the `workspace` property. See {@link StarlightConfig} to view all the
54
+ * available options.
55
+ * @group Client
56
+ */
18
57
  export function makeClient(config = {}) {
19
58
  var _a, _b, _c;
20
59
  let baseUrl = (_a = config.baseUrl) !== null && _a !== void 0 ? _a : 'https://query.starlight.sh/v2';
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;;;;;;;AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,iBAAiB,MAAM,mBAAmB,CAAA;AACjD,OAAO,iBAAiB,MAAM,mBAAmB,CAAA;AACjD,OAAO,qBAAqB,MAAM,uBAAuB,CAAA;AACzD,OAAO,sBAAsB,MAAM,wBAAwB,CAAA;AAC3D,OAAO,iBAAiB,MAAM,mBAAmB,CAAA;AACjD,OAAO,kBAAkB,MAAM,oBAAoB,CAAA;AACnD,OAAO,sBAAsB,MAAM,wBAAwB,CAAA;AAE3D,MAAM,UAAU,UAAU,CAExB,SAA0B,EAAE;;IAC5B,IAAI,OAAO,GAAG,MAAA,MAAM,CAAC,OAAO,mCAAI,+BAA+B,CAAA;IAC/D,IAAI,SAAS,GAAG,MAAA,MAAM,CAAC,SAAS,mCAAI,EAAE,CAAA;IACtC,IAAI,KAAK,GAAG,MAAA,MAAM,CAAC,KAAK,mCAAI,KAAK,CAAA;IAEjC,MAAM,MAAM,GAAoB;QAC9B,SAAS,CAAC,MAAM;;YACd,OAAO,GAAG,MAAA,MAAM,CAA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ient,\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\nexport function makeClient<\n D extends WorkspaceModelDefinition = DefaultModelDefinition\n>(config: StarlightConfig = {}): ProxiedStarlightClient<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 ProxiedStarlightClient<D>\n}\n"]}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;;;;;;;AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,iBAAiB,MAAM,mBAAmB,CAAA;AACjD,OAAO,iBAAiB,MAAM,mBAAmB,CAAA;AACjD,OAAO,qBAAqB,MAAM,uBAAuB,CAAA;AACzD,OAAO,sBAAsB,MAAM,wBAAwB,CAAA;AAC3D,OAAO,iBAAiB,MAAM,mBAAmB,CAAA;AACjD,OAAO,kBAAkB,MAAM,oBAAoB,CAAA;AACnD,OAAO,sBAAsB,MAAM,wBAAwB,CAAA;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,UAAU,UAAU,CAExB,SAA0B,EAAE;;IAC5B,IAAI,OAAO,GAAG,MAAA,MAAM,CAAC,OAAO,mCAAI,+BAA+B,CAAA;IAC/D,IAAI,SAAS,GAAG,MAAA,MAAM,CAAC,SAAS,mCAAI,EAAE,CAAA;IACtC,IAAI,KAAK,GAAG,MAAA,MAAM,CAAC,KAAK,mCAAI,KAAK,CAAA;IAEjC,MAAM,MAAM,GAAoB;QAC9B,SAAS,CAAC,MAAM;;YACd,OAAO,GAAG,MAAA,MAAM,CAAC,OAAO,mCAAI,OAAO,CAAA;YACnC,SAAS,GAAG,MAAA,MAAM,CAAC,SAAS,mCAAI,SAAS,CAAA;YACzC,KAAK,GAAG,MAAA,MAAM,CAAC,KAAK,mCAAI,KAAK,CAAA;QAC/B,CAAC;QAED,GAAG,CAAC,OAAO,EAAE,GAAG,cAAc;YAC5B,IAAI,KAAK;gBAAE,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC,CAAA;QACpD,CAAC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iB,CAAC,IAAI,CAAC,CAAA;QAChC,CAAC;QAED,KAAK,CAAC,IAAI;YACR,OAAO,iBAAiB,CAAC,IAAI,EAAE,IAAc,CAAC,CAAA;QAChD,CAAC;QAED,IAAI,UAAU;YACZ,OAAO,qBAAqB,CAAC,IAAI,CAAC,CAAA;QACpC,CAAC;QAED,IAAI,WAAW;YACb,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAA;QACrC,CAAC;QAED,UAAU,CAAC,IAAqB;YAC9B,OAAO,sBAAsB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAC3C,CAAC;QAED,IAAI,KAAK;YACP,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;QAChC,CAAC;QAED,IAAI,MAAM;YACR,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAA;QACjC,CAAC;KACF,CAAA;IAED,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE;QACvB,GAAG,CAAC,MAAM,EAAE,IAAI;YACd,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE;gBAC1D,OAAO,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;aACvC;YAED,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QAClC,CAAC;KACF,CAA8B,CAAA;AACjC,CAAC","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 from 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 the default client, 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\n * 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 * })\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"]}
@@ -1,4 +1,16 @@
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
+ * @see [MDN documentation on the Response object](https://developer.mozilla.org/en-US/docs/Web/API/Response)
13
+ */
2
14
  response: Response;
3
15
  constructor(message: string, response: Response);
4
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,cAAe,SAAQ,KAAK;IAChC,QAAQ,EAAE,QAAQ,CAAA;gBAEb,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ;CAIhD"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC;;;;OAIG;IACI,QAAQ,EAAE,QAAQ,CAAA;gBAEb,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ;CAIhD"}
@@ -1,3 +1,10 @@
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 class StarlightError extends Error {
2
9
  constructor(message, response) {
3
10
  super(message);
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,cAAe,SAAQ,KAAK;IAGvC,YAAY,OAAe,EAAE,QAAkB;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;CACF","sourcesContent":["export class StarlightError extends Error {\n public response: Response\n\n constructor(message: string, response: Response) {\n super(message)\n this.response = response\n }\n}\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAQvC,YAAY,OAAe,EAAE,QAAkB;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;CACF","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 * @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"]}
@@ -1,7 +1,27 @@
1
1
  import { makeClient } from './client';
2
2
  export { StarlightError } from './errors';
3
3
  export * from './types';
4
- declare const Starlight: import("./types").ProxiedStarlightClient<import("./types").DefaultModelDefinition>;
4
+ /**
5
+ * This is the default object exported by the SDK module, which is a
6
+ * pre-created {@link StarlightClient}. If your application only requests
7
+ * data from a single Starlight workspace, using this client is easier than
8
+ * creating a new one using {@link makeStarlightClient}.
9
+ *
10
+ * Using the default client is as easy as importing the SDK:
11
+ *
12
+ * ```ts
13
+ * // "Starlight" below is the default client.
14
+ * import Starlight from '@starlightcms/js-sdk'
15
+ *
16
+ * const response = await Starlight.posts.entries.list()
17
+ * ```
18
+ *
19
+ * You need to configure the default workspace once before using it, however.
20
+ * See {@apilink StarlightClient.configure} to learn more.
21
+ *
22
+ * @group Client
23
+ */
24
+ declare const Starlight: import("./types").DynamicStarlightClient<import("./types").DefaultModelDefinition>;
5
25
  export { makeClient as makeStarlightClient };
6
26
  export default Starlight;
7
27
  //# sourceMappingURL=index.d.ts.map
@@ -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;;;;;;;;;;;;;;;;;;;GAmBG;AACH,QAAA,MAAM,SAAS,oFAAe,CAAA;AAE9B,OAAO,EAAE,UAAU,IAAI,mBAAmB,EAAE,CAAA;AAE5C,eAAe,SAAS,CAAA"}
package/dist/esm/index.js CHANGED
@@ -1,6 +1,26 @@
1
1
  import { makeClient } from './client';
2
2
  export { StarlightError } from './errors';
3
3
  export * from './types';
4
+ /**
5
+ * This is the default object exported by the SDK module, which is a
6
+ * pre-created {@link StarlightClient}. If your application only requests
7
+ * data from a single Starlight workspace, using this client is easier than
8
+ * creating a new one using {@link makeStarlightClient}.
9
+ *
10
+ * Using the default client is as easy as importing the SDK:
11
+ *
12
+ * ```ts
13
+ * // "Starlight" below is the default client.
14
+ * import Starlight from '@starlightcms/js-sdk'
15
+ *
16
+ * const response = await Starlight.posts.entries.list()
17
+ * ```
18
+ *
19
+ * You need to configure the default workspace once before using it, however.
20
+ * See {@apilink StarlightClient.configure} to learn more.
21
+ *
22
+ * @group Client
23
+ */
4
24
  const Starlight = makeClient();
5
25
  export { makeClient as makeStarlightClient };
6
26
  export default Starlight;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","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,MAAM,SAAS,GAAG,UAAU,EAAE,CAAA;AAE9B,OAAO,EAAE,UAAU,IAAI,mBAAmB,EAAE,CAAA;AAE5C,eAAe,SAAS,CAAA","sourcesContent":["import { makeClient } from './client'\nexport { StarlightError } from './errors'\nexport * from './types'\n\nconst Starlight = makeClient()\n\nexport { makeClient as makeStarlightClient }\n\nexport default Starlight\n"]}
1
+ {"version":3,"file":"index.js","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;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,SAAS,GAAG,UAAU,EAAE,CAAA;AAE9B,OAAO,EAAE,UAAU,IAAI,mBAAmB,EAAE,CAAA;AAE5C,eAAe,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}. If your application only requests\n * data from a single Starlight workspace, using this client is easier than\n * creating 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 once before using it, however.\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 { CollectionTypes, StarlightClient } from '../../types';
1
+ import { CollectionEntityTypes, StarlightClient } from '../../types';
2
2
  import { CollectionInstance } from './types';
3
- export default function makeCollectionInstance<T extends CollectionTypes = string>(client: StarlightClient, collection: string | number): CollectionInstance<T>;
3
+ export default function makeCollectionInstance<T extends CollectionEntityTypes = unknown>(client: StarlightClient, collection: string | number): CollectionInstance<T>;
4
4
  export { CollectionInstance };
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,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAE5C,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,CAAC,SAAS,eAAe,GAAG,MAAM,EAClC,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAU7E;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAA"}
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,MAAM,SAAS,CAAA;AAE5C,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,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/instances/Collection/index.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,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","sourcesContent":["import { CollectionTypes, StarlightClient } from '../../types'\nimport { CollectionInstance } from './types'\n\nexport default function makeCollectionInstance<\n T extends CollectionTypes = string\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 }\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/instances/Collection/index.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,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","sourcesContent":["import { CollectionEntityTypes, StarlightClient } from '../../types'\nimport { CollectionInstance } 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 }\n"]}
@@ -1,4 +1,4 @@
1
- import { Collection, CollectionTypes, ModelFieldOptions, SerializedData, StarlightItemResponse, StarlightListResponse } from '../../types';
1
+ import { Collection, CollectionEntityTypes, CollectionTypeMapper, Entry, ModelFieldOptions, Singleton, StarlightItemResponse, StarlightListResponse } from '../../types';
2
2
  export declare type ListCollectionItemsOptions<T> = {
3
3
  page?: number;
4
4
  limit?: number;
@@ -7,9 +7,53 @@ export declare type ListCollectionItemsOptions<T> = {
7
7
  fields?: string;
8
8
  order?: 'title:asc' | 'title:desc' | 'published_at:asc' | 'published_at:desc' | 'views:asc' | 'views:desc';
9
9
  except?: number;
10
- } & (T extends SerializedData ? ModelFieldOptions<T> : unknown);
11
- export interface CollectionInstance<C extends CollectionTypes = string> {
12
- get(): Promise<StarlightItemResponse<Collection<C>>>;
13
- items<T>(options?: ListCollectionItemsOptions<T>): Promise<StarlightListResponse<T>>;
10
+ } & (T extends Entry<never> | Singleton<never> ? ModelFieldOptions<Pick<T, 'data'>> : Record<string, never>);
11
+ /**
12
+ * An Instance that provide methods to request information and items from
13
+ * {@apilink Collection | Collections}.
14
+ *
15
+ * @group Instances
16
+ */
17
+ export interface CollectionInstance<C extends CollectionEntityTypes> {
18
+ /**
19
+ * Returns a {@link StarlightItemResponse} with a single {@link Collection}.
20
+ *
21
+ * @example Requesting information from a collection of slug `featured-news`.
22
+ * ```ts
23
+ * import Starlight from '@starlightcms/js-sdk'
24
+ *
25
+ * const response = await Starlight.collection('featured-news').get()
26
+ * ```
27
+ */
28
+ get(): Promise<StarlightItemResponse<Collection<CollectionTypeMapper<C>>>>;
29
+ /**
30
+ * Returns a {@link StarlightListResponse} with the list of items of the given
31
+ * {@link Collection}. The returned list type depends on the collection type:
32
+ * a list of {@apilink Entry | Entries} for a collection of type `entry`, a
33
+ * list of {@apilink MediaObject | MediaObjects} for a collection o type
34
+ * `media`, and so on.
35
+ *
36
+ * If the given Collection is not typed, this method will return a response of
37
+ * `StarlightListResponse<unknown>`.
38
+ *
39
+ * @example Requesting all items from an Entry collection of slug `featured-news`.
40
+ * ```ts
41
+ * import Starlight from '@starlightcms/js-sdk'
42
+ *
43
+ * const response = await Starlight.collection('featured-news').items()
44
+ * ```
45
+ *
46
+ * @example Explicitly typing the returned items. Only possible in TypeScript.
47
+ * ```ts
48
+ * import Starlight from '@starlightcms/js-sdk'
49
+ * import { NewsPostType } from '../types'
50
+ *
51
+ * // response will be StarlightListResponse<Entry<NewsPostType>>
52
+ * const response = await Starlight.collection<Entry<NewsPostType>>('featured-news').items()
53
+ * ```
54
+ *
55
+ * @param options
56
+ */
57
+ items(options?: ListCollectionItemsOptions<C>): Promise<StarlightListResponse<C>>;
14
58
  }
15
59
  //# 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,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,aAAa,CAAA;AAEpB,oBAAY,0BAA0B,CAAC,CAAC,IAAI;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EACF,WAAW,GACX,YAAY,GACZ,kBAAkB,GAClB,mBAAmB,GACnB,WAAW,GACX,YAAY,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,GAAG,CAAC,CAAC,SAAS,cAAc,GAAG,iBAAiB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAA;AAE/D,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,eAAe,GAAG,MAAM;IACpE,GAAG,IAAI,OAAO,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACpD,KAAK,CAAC,CAAC,EACL,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,CAAC,GACtC,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAA;CACrC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/instances/Collection/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,qBAAqB,EACrB,oBAAoB,EACpB,KAAK,EACL,iBAAiB,EACjB,SAAS,EACT,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,aAAa,CAAA;AAEpB,oBAAY,0BAA0B,CAAC,CAAC,IAAI;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EACF,WAAW,GACX,YAAY,GACZ,kBAAkB,GAClB,mBAAmB,GACnB,WAAW,GACX,YAAY,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,GAAG,CAAC,CAAC,SAAS,KAAK,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAC1C,iBAAiB,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAClC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAA;AAE1B;;;;;GAKG;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;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,KAAK,CACH,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,CAAC,GACtC,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 CollectionTypes,\n ModelFieldOptions,\n SerializedData,\n StarlightItemResponse,\n StarlightListResponse,\n} from '../../types'\n\nexport type ListCollectionItemsOptions<T> = {\n page?: number\n limit?: number\n query?: string\n 'query:word'?: string\n fields?: string\n order?:\n | 'title:asc'\n | 'title:desc'\n | 'published_at:asc'\n | 'published_at:desc'\n | 'views:asc'\n | 'views:desc'\n except?: number\n} & (T extends SerializedData ? ModelFieldOptions<T> : unknown)\n\nexport interface CollectionInstance<C extends CollectionTypes = string> {\n get(): Promise<StarlightItemResponse<Collection<C>>>\n items<T>(\n options?: ListCollectionItemsOptions<T>\n ): Promise<StarlightListResponse<T>>\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/instances/Collection/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n Collection,\n CollectionEntityTypes,\n CollectionTypeMapper,\n Entry,\n ModelFieldOptions,\n Singleton,\n StarlightItemResponse,\n StarlightListResponse,\n} from '../../types'\n\nexport type ListCollectionItemsOptions<T> = {\n page?: number\n limit?: number\n query?: string\n 'query:word'?: string\n fields?: string\n order?:\n | 'title:asc'\n | 'title:desc'\n | 'published_at:asc'\n | 'published_at:desc'\n | 'views:asc'\n | 'views:desc'\n except?: number\n} & (T extends Entry<never> | Singleton<never>\n ? ModelFieldOptions<Pick<T, 'data'>>\n : Record<string, never>)\n\n/**\n * An Instance that provide methods to request information and items from\n * {@apilink Collection | Collections}.\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 the given\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\n */\n items(\n options?: ListCollectionItemsOptions<C>\n ): Promise<StarlightListResponse<C>>\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { SerializedData, StarlightClient } from '../../types';
2
- import { ProxiedModelInstance } from './types';
3
- export default function makeModelInstance<D extends SerializedData>(client: StarlightClient, model: string): ProxiedModelInstance<D>;
4
- export { ProxiedModelInstance };
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;AAS9C,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,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,OAAO,iBAAoC,MAAM,uBAAuB,CAAA;AACxE,OAAO,yBAEN,MAAM,+BAA+B,CAAA;AACtC,OAAO,yBAEN,MAAM,kBAAkB,CAAA;AAEzB,MAAM,CAAC,OAAO,UAAU,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,yBAAyB,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;QACvD,CAAC;QAED,IAAI,OAAO;YACT,OAAO,iBAAiB,CAAI,MAAM,EAAE,KAAK,CAAC,CAAA;QAC5C,CAAC;QAED,IAAI,UAAU;YACZ,OAAO,yBAAyB,CAAC,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,yBAAyB,CAAC,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","sourcesContent":["import {\n Model,\n SerializedData,\n StarlightClient,\n StarlightItemResponse,\n} from '../../types'\nimport { ProxiedModelInstance } from './types'\nimport makeEntrySelector, { EntrySelector } from '../../selectors/Entry'\nimport makeModelCategorySelector, {\n ProxiedModelCategorySelector,\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): ProxiedModelInstance<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(): ProxiedModelCategorySelector<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 ProxiedModelInstance<D>\n}\n\nexport { ProxiedModelInstance }\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/instances/Model/index.ts"],"names":[],"mappings":"AAOA,OAAO,iBAAoC,MAAM,uBAAuB,CAAA;AACxE,OAAO,yBAEN,MAAM,+BAA+B,CAAA;AACtC,OAAO,yBAEN,MAAM,kBAAkB,CAAA;AAEzB,MAAM,CAAC,OAAO,UAAU,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,yBAAyB,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;QACvD,CAAC;QAED,IAAI,OAAO;YACT,OAAO,iBAAiB,CAAI,MAAM,EAAE,KAAK,CAAC,CAAA;QAC5C,CAAC;QAED,IAAI,UAAU;YACZ,OAAO,yBAAyB,CAAC,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,yBAAyB,CAAC,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","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,14 @@
1
1
  import { Model, SerializedData, StarlightItemResponse } from '../../types';
2
2
  import { EntrySelector } from '../../selectors/Entry';
3
- import { ProxiedModelCategorySelector } from '../../selectors/ModelCategory';
3
+ import { DynamicModelCategorySelector } from '../../selectors/ModelCategory';
4
4
  import { ModelCategoryInstance } from '../ModelCategory';
5
5
  export interface ModelInstance<D extends SerializedData> {
6
6
  get(): Promise<StarlightItemResponse<Model>>;
7
7
  category(slug: string): ModelCategoryInstance<D>;
8
8
  get entries(): EntrySelector<D>;
9
- get categories(): ProxiedModelCategorySelector<D>;
9
+ get categories(): DynamicModelCategorySelector<D>;
10
10
  }
11
- export declare type ProxiedModelInstance<D extends SerializedData> = ModelInstance<D> & {
11
+ export declare type DynamicModelInstance<D extends SerializedData> = ModelInstance<D> & {
12
12
  [key: string]: ModelCategoryInstance<D>;
13
13
  };
14
14
  //# sourceMappingURL=types.d.ts.map
@@ -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 { ProxiedModelCategorySelector } from '../../selectors/ModelCategory'\nimport { ModelCategoryInstance } from '../ModelCategory'\n\nexport interface ModelInstance<D extends SerializedData> {\n get(): Promise<StarlightItemResponse<Model>>\n category(slug: string): ModelCategoryInstance<D>\n get entries(): EntrySelector<D>\n get categories(): ProxiedModelCategorySelector<D>\n}\n\nexport type ProxiedModelInstance<D extends SerializedData> =\n ModelInstance<D> & {\n [key: string]: ModelCategoryInstance<D>\n }\n"]}
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\nexport interface ModelInstance<D extends SerializedData> {\n get(): Promise<StarlightItemResponse<Model>>\n category(slug: string): ModelCategoryInstance<D>\n get entries(): EntrySelector<D>\n get categories(): DynamicModelCategorySelector<D>\n}\n\nexport type DynamicModelInstance<D extends SerializedData> =\n ModelInstance<D> & {\n [key: string]: ModelCategoryInstance<D>\n }\n"]}
@@ -1,5 +1,5 @@
1
1
  import { StarlightClient } from '../../types';
2
- import { CollectionSelector, ProxiedCollectionSelector } from './types';
3
- export default function makeCollectionSelector(client: StarlightClient): ProxiedCollectionSelector;
4
- export { CollectionSelector, ProxiedCollectionSelector };
2
+ import { CollectionSelector, DynamicCollectionSelector } from './types';
3
+ export default function makeCollectionSelector(client: StarlightClient): DynamicCollectionSelector;
4
+ export { CollectionSelector, DynamicCollectionSelector };
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/selectors/Collection/index.ts"],"names":[],"mappings":"AAEA,OAAO,sBAAsB,MAAM,4BAA4B,CAAA;AAE/D,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,MAAuB;IAEvB,MAAM,QAAQ,GAAuB;QACnC,IAAI,CAAC,OAAO;YACV,OAAO,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;QAC5C,CAAC;QAED,GAAG,CAAC,IAAI;YACN,OAAO,MAAM,CAAC,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAA;QAC3C,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,sBAAsB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;aAC5C;YAED,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QAClC,CAAC;KACF,CAA8B,CAAA;AACjC,CAAC","sourcesContent":["import { StarlightClient } from '../../types'\nimport { CollectionSelector, ProxiedCollectionSelector } from './types'\nimport makeCollectionInstance from '../../instances/Collection'\n\nexport default function makeCollectionSelector(\n client: StarlightClient\n): ProxiedCollectionSelector {\n const selector: CollectionSelector = {\n list(options) {\n return client.get('/collections', options)\n },\n\n get(slug) {\n return client.get(`/collections/${slug}`)\n },\n }\n\n return new Proxy(selector, {\n get(target, prop) {\n if (typeof prop === 'string' && !Reflect.has(target, prop)) {\n return makeCollectionInstance(client, prop)\n }\n\n return Reflect.get(target, prop)\n },\n }) as ProxiedCollectionSelector\n}\n\nexport { CollectionSelector, ProxiedCollectionSelector }\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/selectors/Collection/index.ts"],"names":[],"mappings":"AAEA,OAAO,sBAAsB,MAAM,4BAA4B,CAAA;AAE/D,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,MAAuB;IAEvB,MAAM,QAAQ,GAAuB;QACnC,IAAI,CAAC,OAAO;YACV,OAAO,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;QAC5C,CAAC;QAED,GAAG,CAAC,IAAI;YACN,OAAO,MAAM,CAAC,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAA;QAC3C,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,sBAAsB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;aAC5C;YAED,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QAClC,CAAC;KACF,CAA8B,CAAA;AACjC,CAAC","sourcesContent":["import { StarlightClient } from '../../types'\nimport { CollectionSelector, DynamicCollectionSelector } from './types'\nimport makeCollectionInstance from '../../instances/Collection'\n\nexport default function makeCollectionSelector(\n client: StarlightClient\n): DynamicCollectionSelector {\n const selector: CollectionSelector = {\n list(options) {\n return client.get('/collections', options)\n },\n\n get(slug) {\n return client.get(`/collections/${slug}`)\n },\n }\n\n return new Proxy(selector, {\n get(target, prop) {\n if (typeof prop === 'string' && !Reflect.has(target, prop)) {\n return makeCollectionInstance(client, prop)\n }\n\n return Reflect.get(target, prop)\n },\n }) as DynamicCollectionSelector\n}\n\nexport { CollectionSelector, DynamicCollectionSelector }\n"]}
@@ -10,7 +10,7 @@ export interface CollectionSelector {
10
10
  list(options?: ListCollectionsOptions): Promise<StarlightListResponse<Collection>>;
11
11
  get(slug: string | number): Promise<StarlightItemResponse<Collection>>;
12
12
  }
13
- export declare type ProxiedCollectionSelector = CollectionSelector & {
14
- [key: string]: CollectionInstance;
13
+ export declare type DynamicCollectionSelector = CollectionSelector & {
14
+ [key: string]: CollectionInstance<unknown>;
15
15
  };
16
16
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/selectors/Collection/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAE/D,oBAAY,sBAAsB,GAAG;IACnC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,WAAW,GAAG,YAAY,GAAG,gBAAgB,GAAG,iBAAiB,CAAA;CAC1E,CAAA;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,CACF,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAA;IAC7C,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAA;CACvE;AAED,oBAAY,yBAAyB,GAAG,kBAAkB,GAAG;IAC3D,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAAA;CAClC,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/selectors/Collection/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAE/D,oBAAY,sBAAsB,GAAG;IACnC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,WAAW,GAAG,YAAY,GAAG,gBAAgB,GAAG,iBAAiB,CAAA;CAC1E,CAAA;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,CACF,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAA;IAC7C,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAA;CACvE;AAED,oBAAY,yBAAyB,GAAG,kBAAkB,GAAG;IAC3D,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAA;CAC3C,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/selectors/Collection/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n Collection,\n StarlightItemResponse,\n StarlightListResponse,\n} from '../../types'\nimport { CollectionInstance } from '../../instances/Collection'\n\nexport type ListCollectionsOptions = {\n query?: string\n page?: number\n limit?: number\n order?: 'title:asc' | 'title:desc' | 'item_count:asc' | 'item_count:desc'\n}\n\nexport interface CollectionSelector {\n list(\n options?: ListCollectionsOptions\n ): Promise<StarlightListResponse<Collection>>\n get(slug: string | number): Promise<StarlightItemResponse<Collection>>\n}\n\nexport type ProxiedCollectionSelector = CollectionSelector & {\n [key: string]: CollectionInstance\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/selectors/Collection/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n Collection,\n StarlightItemResponse,\n StarlightListResponse,\n} from '../../types'\nimport { CollectionInstance } from '../../instances/Collection'\n\nexport type ListCollectionsOptions = {\n query?: string\n page?: number\n limit?: number\n order?: 'title:asc' | 'title:desc' | 'item_count:asc' | 'item_count:desc'\n}\n\nexport interface CollectionSelector {\n list(\n options?: ListCollectionsOptions\n ): Promise<StarlightListResponse<Collection>>\n get(slug: string | number): Promise<StarlightItemResponse<Collection>>\n}\n\nexport type DynamicCollectionSelector = CollectionSelector & {\n [key: string]: CollectionInstance<unknown>\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { StarlightClient, WorkspaceModelDefinition } from '../../types';
2
- import { ModelSelector, ProxiedModelSelector } from './types';
3
- export default function makeModelSelector<D extends WorkspaceModelDefinition>(client: StarlightClient): ProxiedModelSelector<D>;
4
- export { ModelSelector, ProxiedModelSelector };
2
+ import { ModelSelector, DynamicModelSelector } from './types';
3
+ export default function makeModelSelector<D extends WorkspaceModelDefinition>(client: StarlightClient): DynamicModelSelector<D>;
4
+ export { ModelSelector, DynamicModelSelector };
5
5
  //# sourceMappingURL=index.d.ts.map