@starlightcms/js-sdk 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/README.md +54 -0
  2. package/dist/cjs/client.d.ts +41 -2
  3. package/dist/cjs/client.d.ts.map +1 -1
  4. package/dist/cjs/client.js +39 -0
  5. package/dist/cjs/client.js.map +1 -1
  6. package/dist/cjs/errors.d.ts +35 -0
  7. package/dist/cjs/errors.d.ts.map +1 -1
  8. package/dist/cjs/errors.js +7 -0
  9. package/dist/cjs/errors.js.map +1 -1
  10. package/dist/cjs/index.d.ts +22 -1
  11. package/dist/cjs/index.d.ts.map +1 -1
  12. package/dist/cjs/index.js +21 -0
  13. package/dist/cjs/index.js.map +1 -1
  14. package/dist/cjs/instances/Collection/index.d.ts +4 -4
  15. package/dist/cjs/instances/Collection/index.d.ts.map +1 -1
  16. package/dist/cjs/instances/Collection/index.js.map +1 -1
  17. package/dist/cjs/instances/Collection/types.d.ts +68 -12
  18. package/dist/cjs/instances/Collection/types.d.ts.map +1 -1
  19. package/dist/cjs/instances/Collection/types.js +1 -0
  20. package/dist/cjs/instances/Collection/types.js.map +1 -1
  21. package/dist/cjs/instances/Model/index.d.ts +3 -3
  22. package/dist/cjs/instances/Model/index.d.ts.map +1 -1
  23. package/dist/cjs/instances/Model/index.js.map +1 -1
  24. package/dist/cjs/instances/Model/types.d.ts +86 -3
  25. package/dist/cjs/instances/Model/types.d.ts.map +1 -1
  26. package/dist/cjs/instances/Model/types.js.map +1 -1
  27. package/dist/cjs/instances/ModelCategory/index.d.ts +2 -2
  28. package/dist/cjs/instances/ModelCategory/index.d.ts.map +1 -1
  29. package/dist/cjs/instances/ModelCategory/index.js.map +1 -1
  30. package/dist/cjs/instances/ModelCategory/types.d.ts +62 -10
  31. package/dist/cjs/instances/ModelCategory/types.d.ts.map +1 -1
  32. package/dist/cjs/instances/ModelCategory/types.js.map +1 -1
  33. package/dist/cjs/selectors/Collection/index.d.ts +3 -3
  34. package/dist/cjs/selectors/Collection/index.d.ts.map +1 -1
  35. package/dist/cjs/selectors/Collection/index.js +1 -1
  36. package/dist/cjs/selectors/Collection/index.js.map +1 -1
  37. package/dist/cjs/selectors/Collection/types.d.ts +84 -9
  38. package/dist/cjs/selectors/Collection/types.d.ts.map +1 -1
  39. package/dist/cjs/selectors/Collection/types.js.map +1 -1
  40. package/dist/cjs/selectors/Entry/types.d.ts +105 -10
  41. package/dist/cjs/selectors/Entry/types.d.ts.map +1 -1
  42. package/dist/cjs/selectors/Entry/types.js.map +1 -1
  43. package/dist/cjs/selectors/Media/index.js +2 -2
  44. package/dist/cjs/selectors/Media/index.js.map +1 -1
  45. package/dist/cjs/selectors/Media/types.d.ts +35 -1
  46. package/dist/cjs/selectors/Media/types.d.ts.map +1 -1
  47. package/dist/cjs/selectors/Media/types.js.map +1 -1
  48. package/dist/cjs/selectors/Model/index.d.ts +3 -3
  49. package/dist/cjs/selectors/Model/index.js.map +1 -1
  50. package/dist/cjs/selectors/Model/types.d.ts +62 -3
  51. package/dist/cjs/selectors/Model/types.d.ts.map +1 -1
  52. package/dist/cjs/selectors/Model/types.js.map +1 -1
  53. package/dist/cjs/selectors/ModelCategory/index.d.ts +3 -3
  54. package/dist/cjs/selectors/ModelCategory/index.js +1 -1
  55. package/dist/cjs/selectors/ModelCategory/index.js.map +1 -1
  56. package/dist/cjs/selectors/ModelCategory/types.d.ts +50 -7
  57. package/dist/cjs/selectors/ModelCategory/types.d.ts.map +1 -1
  58. package/dist/cjs/selectors/ModelCategory/types.js.map +1 -1
  59. package/dist/cjs/selectors/Search/index.d.ts +2 -2
  60. package/dist/cjs/selectors/Search/index.d.ts.map +1 -1
  61. package/dist/cjs/selectors/Search/index.js +1 -1
  62. package/dist/cjs/selectors/Search/index.js.map +1 -1
  63. package/dist/cjs/selectors/Search/types.d.ts +80 -7
  64. package/dist/cjs/selectors/Search/types.d.ts.map +1 -1
  65. package/dist/cjs/selectors/Search/types.js.map +1 -1
  66. package/dist/cjs/selectors/Singleton/types.d.ts +49 -0
  67. package/dist/cjs/selectors/Singleton/types.d.ts.map +1 -1
  68. package/dist/cjs/selectors/Singleton/types.js.map +1 -1
  69. package/dist/cjs/types/entities.d.ts +241 -2
  70. package/dist/cjs/types/entities.d.ts.map +1 -1
  71. package/dist/cjs/types/entities.js.map +1 -1
  72. package/dist/cjs/types/fields.d.ts +63 -0
  73. package/dist/cjs/types/fields.d.ts.map +1 -1
  74. package/dist/cjs/types/fields.js.map +1 -1
  75. package/dist/cjs/types/index.d.ts +514 -11
  76. package/dist/cjs/types/index.d.ts.map +1 -1
  77. package/dist/cjs/types/index.js +2 -0
  78. package/dist/cjs/types/index.js.map +1 -1
  79. package/dist/cjs/types/instances.d.ts +4 -0
  80. package/dist/cjs/types/instances.d.ts.map +1 -0
  81. package/dist/cjs/types/instances.js +3 -0
  82. package/dist/cjs/types/instances.js.map +1 -0
  83. package/dist/cjs/types/selectors.d.ts +8 -0
  84. package/dist/cjs/types/selectors.d.ts.map +1 -0
  85. package/dist/cjs/types/selectors.js +3 -0
  86. package/dist/cjs/types/selectors.js.map +1 -0
  87. package/dist/cjs/types/visual.d.ts +69 -0
  88. package/dist/cjs/types/visual.d.ts.map +1 -1
  89. package/dist/cjs/types/visual.js.map +1 -1
  90. package/dist/esm/client.d.ts +41 -2
  91. package/dist/esm/client.d.ts.map +1 -1
  92. package/dist/esm/client.js +39 -0
  93. package/dist/esm/client.js.map +1 -1
  94. package/dist/esm/errors.d.ts +35 -0
  95. package/dist/esm/errors.d.ts.map +1 -1
  96. package/dist/esm/errors.js +7 -0
  97. package/dist/esm/errors.js.map +1 -1
  98. package/dist/esm/index.d.ts +22 -1
  99. package/dist/esm/index.d.ts.map +1 -1
  100. package/dist/esm/index.js +21 -0
  101. package/dist/esm/index.js.map +1 -1
  102. package/dist/esm/instances/Collection/index.d.ts +4 -4
  103. package/dist/esm/instances/Collection/index.d.ts.map +1 -1
  104. package/dist/esm/instances/Collection/index.js.map +1 -1
  105. package/dist/esm/instances/Collection/types.d.ts +68 -12
  106. package/dist/esm/instances/Collection/types.d.ts.map +1 -1
  107. package/dist/esm/instances/Collection/types.js +1 -0
  108. package/dist/esm/instances/Collection/types.js.map +1 -1
  109. package/dist/esm/instances/Model/index.d.ts +3 -3
  110. package/dist/esm/instances/Model/index.d.ts.map +1 -1
  111. package/dist/esm/instances/Model/index.js.map +1 -1
  112. package/dist/esm/instances/Model/types.d.ts +86 -3
  113. package/dist/esm/instances/Model/types.d.ts.map +1 -1
  114. package/dist/esm/instances/Model/types.js.map +1 -1
  115. package/dist/esm/instances/ModelCategory/index.d.ts +2 -2
  116. package/dist/esm/instances/ModelCategory/index.d.ts.map +1 -1
  117. package/dist/esm/instances/ModelCategory/index.js.map +1 -1
  118. package/dist/esm/instances/ModelCategory/types.d.ts +62 -10
  119. package/dist/esm/instances/ModelCategory/types.d.ts.map +1 -1
  120. package/dist/esm/instances/ModelCategory/types.js.map +1 -1
  121. package/dist/esm/selectors/Collection/index.d.ts +3 -3
  122. package/dist/esm/selectors/Collection/index.d.ts.map +1 -1
  123. package/dist/esm/selectors/Collection/index.js +1 -1
  124. package/dist/esm/selectors/Collection/index.js.map +1 -1
  125. package/dist/esm/selectors/Collection/types.d.ts +84 -9
  126. package/dist/esm/selectors/Collection/types.d.ts.map +1 -1
  127. package/dist/esm/selectors/Collection/types.js.map +1 -1
  128. package/dist/esm/selectors/Entry/types.d.ts +105 -10
  129. package/dist/esm/selectors/Entry/types.d.ts.map +1 -1
  130. package/dist/esm/selectors/Entry/types.js.map +1 -1
  131. package/dist/esm/selectors/Media/index.js +2 -2
  132. package/dist/esm/selectors/Media/index.js.map +1 -1
  133. package/dist/esm/selectors/Media/types.d.ts +35 -1
  134. package/dist/esm/selectors/Media/types.d.ts.map +1 -1
  135. package/dist/esm/selectors/Media/types.js.map +1 -1
  136. package/dist/esm/selectors/Model/index.d.ts +3 -3
  137. package/dist/esm/selectors/Model/index.js.map +1 -1
  138. package/dist/esm/selectors/Model/types.d.ts +62 -3
  139. package/dist/esm/selectors/Model/types.d.ts.map +1 -1
  140. package/dist/esm/selectors/Model/types.js.map +1 -1
  141. package/dist/esm/selectors/ModelCategory/index.d.ts +3 -3
  142. package/dist/esm/selectors/ModelCategory/index.js +1 -1
  143. package/dist/esm/selectors/ModelCategory/index.js.map +1 -1
  144. package/dist/esm/selectors/ModelCategory/types.d.ts +50 -7
  145. package/dist/esm/selectors/ModelCategory/types.d.ts.map +1 -1
  146. package/dist/esm/selectors/ModelCategory/types.js.map +1 -1
  147. package/dist/esm/selectors/Search/index.d.ts +2 -2
  148. package/dist/esm/selectors/Search/index.d.ts.map +1 -1
  149. package/dist/esm/selectors/Search/index.js +1 -1
  150. package/dist/esm/selectors/Search/index.js.map +1 -1
  151. package/dist/esm/selectors/Search/types.d.ts +80 -7
  152. package/dist/esm/selectors/Search/types.d.ts.map +1 -1
  153. package/dist/esm/selectors/Search/types.js.map +1 -1
  154. package/dist/esm/selectors/Singleton/types.d.ts +49 -0
  155. package/dist/esm/selectors/Singleton/types.d.ts.map +1 -1
  156. package/dist/esm/selectors/Singleton/types.js.map +1 -1
  157. package/dist/esm/types/entities.d.ts +241 -2
  158. package/dist/esm/types/entities.d.ts.map +1 -1
  159. package/dist/esm/types/entities.js.map +1 -1
  160. package/dist/esm/types/fields.d.ts +63 -0
  161. package/dist/esm/types/fields.d.ts.map +1 -1
  162. package/dist/esm/types/fields.js.map +1 -1
  163. package/dist/esm/types/index.d.ts +514 -11
  164. package/dist/esm/types/index.d.ts.map +1 -1
  165. package/dist/esm/types/index.js +2 -0
  166. package/dist/esm/types/index.js.map +1 -1
  167. package/dist/esm/types/instances.d.ts +4 -0
  168. package/dist/esm/types/instances.d.ts.map +1 -0
  169. package/dist/esm/types/instances.js +2 -0
  170. package/dist/esm/types/instances.js.map +1 -0
  171. package/dist/esm/types/selectors.d.ts +8 -0
  172. package/dist/esm/types/selectors.d.ts.map +1 -0
  173. package/dist/esm/types/selectors.js +2 -0
  174. package/dist/esm/types/selectors.js.map +1 -0
  175. package/dist/esm/types/visual.d.ts +69 -0
  176. package/dist/esm/types/visual.d.ts.map +1 -1
  177. package/dist/esm/types/visual.js.map +1 -1
  178. package/package.json +1 -1
@@ -0,0 +1,8 @@
1
+ export { ModelCategorySelector, DynamicModelCategorySelector, } from '../selectors/ModelCategory';
2
+ export { ModelSelector, DynamicModelSelector } from '../selectors/Model';
3
+ export { CollectionSelector, DynamicCollectionSelector, ListCollectionsParams, } from '../selectors/Collection';
4
+ export { EntrySelector } from '../selectors/Entry';
5
+ export { MediaSelector } from '../selectors/Media';
6
+ export { SearchSelector, SearchEntriesParams } from '../selectors/Search';
7
+ export { SingletonSelector } from '../selectors/Singleton';
8
+ //# sourceMappingURL=selectors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../../src/types/selectors.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AACxE,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=selectors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.js","sourceRoot":"","sources":["../../../src/types/selectors.ts"],"names":[],"mappings":"","sourcesContent":["// Selector types are exported here so they are visible in the API docs.\nexport {\n ModelCategorySelector,\n DynamicModelCategorySelector,\n} from '../selectors/ModelCategory'\nexport { ModelSelector, DynamicModelSelector } from '../selectors/Model'\nexport {\n CollectionSelector,\n DynamicCollectionSelector,\n ListCollectionsParams,\n} from '../selectors/Collection'\nexport { EntrySelector } from '../selectors/Entry'\nexport { MediaSelector } from '../selectors/Media'\nexport { SearchSelector, SearchEntriesParams } from '../selectors/Search'\nexport { SingletonSelector } from '../selectors/Singleton'\n"]}
@@ -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,W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,MAAM,WAAW,SAAU,SAAQ,SAAS;IAC1C,KAAK,EAAE,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 of the others.
11
+ *
12
+ * If you only need to make requests to a single workspace, it's probably easier
13
+ * to use the SDK's default client. To use it, you only need to
14
+ * import the default object exported by the SDK:
15
+ *
16
+ * ```ts
17
+ * // `Starlight` below is the default StarlightClient.
18
+ * import Starlight from '@starlightcms/js-sdk'
19
+ * ```
20
+ *
21
+ * See {@link default} for more info on how to use the default client.
22
+ *
23
+ * @example Creating a new client and exporting it.
24
+ * ```ts
25
+ * import { makeStarlightClient } from '@starlightcms/js-sdk'
26
+ *
27
+ * const BlogClient = makeStarlightClient({
28
+ * workspace: '123123123',
29
+ * debug: true
30
+ * })
31
+ *
32
+ * // Feel free to export the new client so your application can use it.
33
+ * export default BlogClient
34
+ * ```
35
+ *
36
+ * @param config The client configuration object. You need to provide at least
37
+ * the `workspace` property. See {@link StarlightConfig} to view all the
38
+ * available options.
39
+ * @group Client
40
+ */
41
+ export declare function makeClient<D extends WorkspaceModelDefinition = DefaultModelDefinition>(config?: StarlightConfig): DynamicStarlightClient<D>;
3
42
  //# sourceMappingURL=client.d.ts.map
@@ -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 of 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 it, 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 Creating a new client and exporting it.
40
+ * ```ts
41
+ * import { makeStarlightClient } from '@starlightcms/js-sdk'
42
+ *
43
+ * const BlogClient = makeStarlightClient({
44
+ * workspace: '123123123',
45
+ * debug: true
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;QAC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C","sourcesContent":["import {\n DefaultModelDefinition,\n ProxiedStarlightClient,\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\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,GAA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AC5C;YACH,CAAC;SAAA;QAED,IAAI,MAAM;YACR,OAAO,iBAAiB,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 of the others.\n *\n * If you only need to make requests to a single workspace, it's probably easier\n * to use the SDK's default client. To use it, you only need to\n * import the default object exported by the SDK:\n *\n * ```ts\n * // `Starlight` below is the default StarlightClient.\n * import Starlight from '@starlightcms/js-sdk'\n * ```\n *\n * See {@link default} for more info on how to use the default client.\n *\n * @example Creating a new client and exporting it.\n * ```ts\n * import { makeStarlightClient } from '@starlightcms/js-sdk'\n *\n * const BlogClient = makeStarlightClient({\n * workspace: '123123123',\n * debug: true\n * })\n *\n * // Feel free to export the new client so your application can use it.\n * export default BlogClient\n * ```\n *\n * @param config The client configuration object. You need to provide at least\n * the `workspace` property. See {@link StarlightConfig} to view all the\n * available options.\n * @group Client\n */\nexport function makeClient<\n D extends WorkspaceModelDefinition = DefaultModelDefinition\n>(config: StarlightConfig = {}): DynamicStarlightClient<D> {\n let baseUrl = config.baseUrl ?? 'https://query.starlight.sh/v2'\n let workspace = config.workspace ?? ''\n let debug = config.debug ?? false\n\n const client: StarlightClient = {\n configure(config) {\n baseUrl = config.baseUrl ?? baseUrl\n workspace = config.workspace ?? workspace\n debug = config.debug ?? debug\n },\n\n log(message, ...optionalParams) {\n if (debug) console.log(message, ...optionalParams)\n },\n\n getBaseUrl() {\n return `${baseUrl}/workspaces/${workspace}`\n },\n\n async get(path, params = {}, options) {\n const filteredParams = Object.keys(params).reduce((accumulator, key) => {\n const param = params[key]\n\n if (param || param === false) accumulator[key] = String(param)\n\n return accumulator\n }, {} as Record<string, string>)\n\n const searchParams = new URLSearchParams(filteredParams).toString()\n const finalPath = searchParams ? `${path}?${searchParams}` : path\n\n this.log(`Starlight - GET ${finalPath}`)\n\n const response = await fetch(`${this.getBaseUrl()}${finalPath}`, options)\n\n if (response.status >= 200 && response.status < 300) {\n return await response.json()\n } else {\n const message = `Starlight - GET ${path} returned ${response.status}: ${response.statusText}`\n throw new StarlightError(message, response)\n }\n },\n\n get models() {\n return makeModelSelector(this)\n },\n\n model(slug) {\n return makeModelInstance(this, slug as string)\n },\n\n get singletons() {\n return makeSingletonSelector(this)\n },\n\n get collections() {\n return makeCollectionSelector(this)\n },\n\n collection(slug: string | number) {\n return makeCollectionInstance(this, slug)\n },\n\n get media() {\n return makeMediaSelector(this)\n },\n\n get search() {\n return makeSearchSelector(this)\n },\n }\n\n return new Proxy(client, {\n get(target, prop) {\n if (typeof prop === 'string' && !Reflect.has(target, prop)) {\n return makeModelInstance(target, prop)\n }\n\n return Reflect.get(target, prop)\n },\n }) as DynamicStarlightClient<D>\n}\n"]}
@@ -1,4 +1,39 @@
1
+ /**
2
+ * This error is thrown every time a problem occurs when requesting something
3
+ * from Starlight's APIs. When it does, you can inspect the attached response
4
+ * to verify what kind of problem happened and handle it accordingly.
5
+ *
6
+ * @group Errors
7
+ */
1
8
  export declare class StarlightError extends Error {
9
+ /**
10
+ * The response provided by the `fetch` method when the error occurred.
11
+ *
12
+ * @example Using the `response` property to handle 404 errors.
13
+ *
14
+ * ```ts
15
+ * import Starlight, { StarlightError } from '@starlightcms/js-sdk'
16
+ *
17
+ * // Returns either an Entry, null on 404 errors, or false in all other cases
18
+ * const requestEntry = async (slug) => {
19
+ * try {
20
+ * const response = await Starlight.posts.entries.get(slug)
21
+ *
22
+ * return response.data
23
+ * } catch (error) {
24
+ * if (error instanceof StarlightError && error.response.status === 404) {
25
+ * // Return null to indicate a 404 error
26
+ * return null
27
+ * }
28
+ *
29
+ * // Return false in all other error scenarios
30
+ * return false
31
+ * }
32
+ * }
33
+ * ```
34
+ *
35
+ * @see [MDN documentation on the Response object](https://developer.mozilla.org/en-US/docs/Web/API/Response)
36
+ */
2
37
  response: Response;
3
38
  constructor(message: string, response: Response);
4
39
  }
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;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;IA+BvC,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 * @example Using the `response` property to handle 404 errors.\n *\n * ```ts\n * import Starlight, { StarlightError } from '@starlightcms/js-sdk'\n *\n * // Returns either an Entry, null on 404 errors, or false in all other cases\n * const requestEntry = async (slug) => {\n * try {\n * const response = await Starlight.posts.entries.get(slug)\n *\n * return response.data\n * } catch (error) {\n * if (error instanceof StarlightError && error.response.status === 404) {\n * // Return null to indicate a 404 error\n * return null\n * }\n *\n * // Return false in all other error scenarios\n * return false\n * }\n * }\n * ```\n *\n * @see [MDN documentation on the Response object](https://developer.mozilla.org/en-US/docs/Web/API/Response)\n */\n public response: Response\n\n constructor(message: string, response: Response) {\n super(message)\n this.response = response\n }\n}\n"]}
@@ -1,7 +1,28 @@
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}. In the docs, this is called the "global
7
+ * SDK client". If your application only requests data from a single Starlight
8
+ * workspace, using this client is easier than creating
9
+ * a new one using {@link makeStarlightClient}.
10
+ *
11
+ * Using the default client is as easy as importing the SDK:
12
+ *
13
+ * ```ts
14
+ * // "Starlight" below is the default client.
15
+ * import Starlight from '@starlightcms/js-sdk'
16
+ *
17
+ * const response = await Starlight.posts.entries.list()
18
+ * ```
19
+ *
20
+ * You need to configure the default workspace before using it.
21
+ * See {@apilink StarlightClient.configure} to learn more.
22
+ *
23
+ * @group Client
24
+ */
25
+ declare const Starlight: import("./types").DynamicStarlightClient<import("./types").DefaultModelDefinition>;
5
26
  export { makeClient as makeStarlightClient };
6
27
  export default Starlight;
7
28
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,cAAc,SAAS,CAAA;AAEvB,QAAA,MAAM,SAAS,oFAAe,CAAA;AAE9B,OAAO,EAAE,UAAU,IAAI,mBAAmB,EAAE,CAAA;AAE5C,eAAe,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,cAAc,SAAS,CAAA;AAEvB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,QAAA,MAAM,SAAS,oFAAe,CAAA;AAE9B,OAAO,EAAE,UAAU,IAAI,mBAAmB,EAAE,CAAA;AAE5C,eAAe,SAAS,CAAA"}
package/dist/esm/index.js CHANGED
@@ -1,6 +1,27 @@
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}. In the docs, this is called the "global
7
+ * SDK client". If your application only requests data from a single Starlight
8
+ * workspace, using this client is easier than creating
9
+ * a new one using {@link makeStarlightClient}.
10
+ *
11
+ * Using the default client is as easy as importing the SDK:
12
+ *
13
+ * ```ts
14
+ * // "Starlight" below is the default client.
15
+ * import Starlight from '@starlightcms/js-sdk'
16
+ *
17
+ * const response = await Starlight.posts.entries.list()
18
+ * ```
19
+ *
20
+ * You need to configure the default workspace before using it.
21
+ * See {@apilink StarlightClient.configure} to learn more.
22
+ *
23
+ * @group Client
24
+ */
4
25
  const Starlight = makeClient();
5
26
  export { makeClient as makeStarlightClient };
6
27
  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;;;;;;;;;;;;;;;;;;;;GAoBG;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}. In the docs, this is called the \"global\n * SDK client\". If your application only requests data from a single Starlight\n * workspace, using this client is easier than creating\n * a new one using {@link makeStarlightClient}.\n *\n * Using the default client is as easy as importing the SDK:\n *\n * ```ts\n * // \"Starlight\" below is the default client.\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.posts.entries.list()\n * ```\n *\n * You need to configure the default workspace before using it.\n * See {@apilink StarlightClient.configure} to learn more.\n *\n * @group Client\n */\nconst Starlight = makeClient()\n\nexport { makeClient as makeStarlightClient }\n\nexport default Starlight\n"]}
@@ -1,5 +1,5 @@
1
- import { CollectionTypes, StarlightClient } from '../../types';
2
- import { CollectionInstance } from './types';
3
- export default function makeCollectionInstance<T extends CollectionTypes = string>(client: StarlightClient, collection: string | number): CollectionInstance<T>;
4
- export { CollectionInstance };
1
+ import { CollectionEntityTypes, StarlightClient } from '../../types';
2
+ import { CollectionInstance, ListCollectionItemsParams } from './types';
3
+ export default function makeCollectionInstance<T extends CollectionEntityTypes = unknown>(client: StarlightClient, collection: string | number): CollectionInstance<T>;
4
+ export { CollectionInstance, ListCollectionItemsParams };
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/instances/Collection/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAEvE,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,CAAC,SAAS,qBAAqB,GAAG,OAAO,EACzC,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAU7E;AAED,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/instances/Collection/index.ts"],"names":[],"mappings":"AAGA,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, ListCollectionItemsParams } from './types'\n\nexport default function makeCollectionInstance<\n T extends CollectionEntityTypes = unknown\n>(client: StarlightClient, collection: string | number): CollectionInstance<T> {\n return {\n get() {\n return client.get(`/collections/${collection}`)\n },\n\n items(options) {\n return client.get(`/collections/${collection}/items`, options)\n },\n }\n}\n\nexport { CollectionInstance, ListCollectionItemsParams }\n"]}
@@ -1,15 +1,71 @@
1
- import { Collection, CollectionTypes, ModelFieldOptions, SerializedData, StarlightItemResponse, StarlightListResponse } from '../../types';
2
- export declare type ListCollectionItemsOptions<T> = {
3
- page?: number;
4
- limit?: number;
5
- query?: string;
6
- 'query:word'?: string;
7
- fields?: string;
1
+ import { BaseRequestParameters, Collection, CollectionEntityTypes, CollectionTypeMapper, QueryableRequestParameters, StarlightItemResponse, StarlightListResponse, WithQueryableFieldsOnModelables } from '../../types';
2
+ /**
3
+ * Request parameters for listing collection items.
4
+ *
5
+ * Used by {@apilink CollectionInstance.items}.
6
+ *
7
+ * @group Request Parameters
8
+ */
9
+ export interface ListCollectionItemsParams extends BaseRequestParameters, QueryableRequestParameters {
10
+ /**
11
+ * Define how entries will be ordered. Check this field type to see the
12
+ * allowed options.
13
+ */
8
14
  order?: 'title:asc' | 'title:desc' | 'published_at:asc' | 'published_at:desc' | 'views:asc' | 'views:desc';
9
- 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>>;
15
+ }
16
+ /**
17
+ * An Instance that provide methods to request information and items from
18
+ * a specific {@link Collection}.
19
+ *
20
+ * You can access a CollectionInstance using
21
+ * {@apilink StarlightClient.collection}.
22
+ *
23
+ * To list all workspace collections, use a {@link CollectionSelector}.
24
+ *
25
+ * @group Instances
26
+ */
27
+ export interface CollectionInstance<C extends CollectionEntityTypes> {
28
+ /**
29
+ * Returns a {@link StarlightItemResponse} with a single {@link Collection}.
30
+ *
31
+ * @example Requesting information from a collection of slug `featured-news`.
32
+ * ```ts
33
+ * import Starlight from '@starlightcms/js-sdk'
34
+ *
35
+ * const response = await Starlight.collection('featured-news').get()
36
+ * ```
37
+ */
38
+ get(): Promise<StarlightItemResponse<Collection<CollectionTypeMapper<C>>>>;
39
+ /**
40
+ * Returns a {@link StarlightListResponse} with the list of items of this
41
+ * {@link Collection}. The returned list type depends on the collection type:
42
+ * a list of {@apilink Entry | Entries} for a collection of type `entry`, a
43
+ * list of {@apilink MediaObject | MediaObjects} for a collection o type
44
+ * `media`, and so on.
45
+ *
46
+ * If the given Collection is not typed, this method will return a response of
47
+ * `StarlightListResponse<unknown>`.
48
+ *
49
+ * @example Requesting all items from an Entry collection of slug `featured-news`.
50
+ * ```ts
51
+ * import Starlight from '@starlightcms/js-sdk'
52
+ *
53
+ * const response = await Starlight.collection('featured-news').items()
54
+ * ```
55
+ *
56
+ * @example Explicitly typing the returned items. Only possible in TypeScript.
57
+ * ```ts
58
+ * import Starlight from '@starlightcms/js-sdk'
59
+ * import { NewsPostType } from '../types'
60
+ *
61
+ * // response will be StarlightListResponse<Entry<NewsPostType>>
62
+ * const response = await Starlight.collection<Entry<NewsPostType>>('featured-news').items()
63
+ * ```
64
+ *
65
+ * @param options An optional object of request parameters. See
66
+ * {@link ListCollectionItemsParams} for all available options. `field:foo`
67
+ * syntax is also supported, see {@link QueryableFields} for more info.
68
+ */
69
+ items(options?: ListCollectionItemsParams & WithQueryableFieldsOnModelables<C>): Promise<StarlightListResponse<C>>;
14
70
  }
15
71
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/instances/Collection/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,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,qBAAqB,EACrB,UAAU,EACV,qBAAqB,EACrB,oBAAoB,EACpB,0BAA0B,EAC1B,qBAAqB,EACrB,qBAAqB,EACrB,+BAA+B,EAChC,MAAM,aAAa,CAAA;AAEpB;;;;;;GAMG;AACH,MAAM,WAAW,yBACf,SAAQ,qBAAqB,EAC3B,0BAA0B;IAC5B;;;OAGG;IACH,KAAK,CAAC,EACF,WAAW,GACX,YAAY,GACZ,kBAAkB,GAClB,mBAAmB,GACnB,WAAW,GACX,YAAY,CAAA;CACjB;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,qBAAqB;IACjE;;;;;;;;;OASG;IACH,GAAG,IAAI,OAAO,CAAC,qBAAqB,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAE1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,KAAK,CACH,OAAO,CAAC,EAAE,yBAAyB,GAAG,+BAA+B,CAAC,CAAC,CAAC,GACvE,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAA;CACrC"}
@@ -1,2 +1,3 @@
1
+ 0;
1
2
  export {};
2
3
  //# sourceMappingURL=types.js.map
@@ -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":"AA4FA,CAAC,CAAA","sourcesContent":["import {\n BaseRequestParameters,\n Collection,\n CollectionEntityTypes,\n CollectionTypeMapper,\n QueryableRequestParameters,\n StarlightItemResponse,\n StarlightListResponse,\n WithQueryableFieldsOnModelables,\n} from '../../types'\n\n/**\n * Request parameters for listing collection items.\n *\n * Used by {@apilink CollectionInstance.items}.\n *\n * @group Request Parameters\n */\nexport interface ListCollectionItemsParams\n extends BaseRequestParameters,\n QueryableRequestParameters {\n /**\n * Define how entries will be ordered. Check this field type to see the\n * allowed options.\n */\n order?:\n | 'title:asc'\n | 'title:desc'\n | 'published_at:asc'\n | 'published_at:desc'\n | 'views:asc'\n | 'views:desc'\n}\n\n/**\n * An Instance that provide methods to request information and items from\n * a specific {@link Collection}.\n *\n * You can access a CollectionInstance using\n * {@apilink StarlightClient.collection}.\n *\n * To list all workspace collections, use a {@link CollectionSelector}.\n *\n * @group Instances\n */\nexport interface CollectionInstance<C extends CollectionEntityTypes> {\n /**\n * Returns a {@link StarlightItemResponse} with a single {@link Collection}.\n *\n * @example Requesting information from a collection of slug `featured-news`.\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.collection('featured-news').get()\n * ```\n */\n get(): Promise<StarlightItemResponse<Collection<CollectionTypeMapper<C>>>>\n\n /**\n * Returns a {@link StarlightListResponse} with the list of items of this\n * {@link Collection}. The returned list type depends on the collection type:\n * a list of {@apilink Entry | Entries} for a collection of type `entry`, a\n * list of {@apilink MediaObject | MediaObjects} for a collection o type\n * `media`, and so on.\n *\n * If the given Collection is not typed, this method will return a response of\n * `StarlightListResponse<unknown>`.\n *\n * @example Requesting all items from an Entry collection of slug `featured-news`.\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n *\n * const response = await Starlight.collection('featured-news').items()\n * ```\n *\n * @example Explicitly typing the returned items. Only possible in TypeScript.\n * ```ts\n * import Starlight from '@starlightcms/js-sdk'\n * import { NewsPostType } from '../types'\n *\n * // response will be StarlightListResponse<Entry<NewsPostType>>\n * const response = await Starlight.collection<Entry<NewsPostType>>('featured-news').items()\n * ```\n *\n * @param options An optional object of request parameters. See\n * {@link ListCollectionItemsParams} for all available options. `field:foo`\n * syntax is also supported, see {@link QueryableFields} for more info.\n */\n items(\n options?: ListCollectionItemsParams & WithQueryableFieldsOnModelables<C>\n ): Promise<StarlightListResponse<C>>\n}\n0\n"]}
@@ -1,5 +1,5 @@
1
1
  import { SerializedData, StarlightClient } from '../../types';
2
- import { 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"]}