@starlightcms/js-sdk 4.0.0-beta.2 → 4.0.0-beta.3

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 (304) hide show
  1. package/dist/index.cjs +397 -0
  2. package/dist/index.d.cts +5087 -0
  3. package/dist/index.d.cts.map +1 -0
  4. package/dist/index.d.mts +5087 -0
  5. package/dist/index.d.mts.map +1 -0
  6. package/dist/index.mjs +391 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +18 -13
  9. package/dist/cjs/client.d.ts +0 -42
  10. package/dist/cjs/client.d.ts.map +0 -1
  11. package/dist/cjs/client.js +0 -145
  12. package/dist/cjs/client.js.map +0 -1
  13. package/dist/cjs/errors.d.ts +0 -40
  14. package/dist/cjs/errors.d.ts.map +0 -1
  15. package/dist/cjs/errors.js +0 -18
  16. package/dist/cjs/errors.js.map +0 -1
  17. package/dist/cjs/index.d.ts +0 -29
  18. package/dist/cjs/index.d.ts.map +0 -1
  19. package/dist/cjs/index.js +0 -47
  20. package/dist/cjs/index.js.map +0 -1
  21. package/dist/cjs/instances/Collection/index.d.ts +0 -5
  22. package/dist/cjs/instances/Collection/index.d.ts.map +0 -1
  23. package/dist/cjs/instances/Collection/index.js +0 -14
  24. package/dist/cjs/instances/Collection/index.js.map +0 -1
  25. package/dist/cjs/instances/Collection/types.d.ts +0 -79
  26. package/dist/cjs/instances/Collection/types.d.ts.map +0 -1
  27. package/dist/cjs/instances/Collection/types.js +0 -3
  28. package/dist/cjs/instances/Collection/types.js.map +0 -1
  29. package/dist/cjs/instances/Form/index.d.ts +0 -5
  30. package/dist/cjs/instances/Form/index.d.ts.map +0 -1
  31. package/dist/cjs/instances/Form/index.js +0 -14
  32. package/dist/cjs/instances/Form/index.js.map +0 -1
  33. package/dist/cjs/instances/Form/types.d.ts +0 -46
  34. package/dist/cjs/instances/Form/types.d.ts.map +0 -1
  35. package/dist/cjs/instances/Form/types.js +0 -3
  36. package/dist/cjs/instances/Form/types.js.map +0 -1
  37. package/dist/cjs/instances/Model/index.d.ts +0 -5
  38. package/dist/cjs/instances/Model/index.d.ts.map +0 -1
  39. package/dist/cjs/instances/Model/index.js +0 -34
  40. package/dist/cjs/instances/Model/index.js.map +0 -1
  41. package/dist/cjs/instances/Model/types.d.ts +0 -102
  42. package/dist/cjs/instances/Model/types.d.ts.map +0 -1
  43. package/dist/cjs/instances/Model/types.js +0 -3
  44. package/dist/cjs/instances/Model/types.js.map +0 -1
  45. package/dist/cjs/instances/ModelCategory/index.d.ts +0 -5
  46. package/dist/cjs/instances/ModelCategory/index.d.ts.map +0 -1
  47. package/dist/cjs/instances/ModelCategory/index.js +0 -14
  48. package/dist/cjs/instances/ModelCategory/index.js.map +0 -1
  49. package/dist/cjs/instances/ModelCategory/types.d.ts +0 -76
  50. package/dist/cjs/instances/ModelCategory/types.d.ts.map +0 -1
  51. package/dist/cjs/instances/ModelCategory/types.js +0 -3
  52. package/dist/cjs/instances/ModelCategory/types.js.map +0 -1
  53. package/dist/cjs/selectors/Collection/index.d.ts +0 -5
  54. package/dist/cjs/selectors/Collection/index.d.ts.map +0 -1
  55. package/dist/cjs/selectors/Collection/index.js +0 -26
  56. package/dist/cjs/selectors/Collection/index.js.map +0 -1
  57. package/dist/cjs/selectors/Collection/types.d.ts +0 -98
  58. package/dist/cjs/selectors/Collection/types.d.ts.map +0 -1
  59. package/dist/cjs/selectors/Collection/types.js +0 -3
  60. package/dist/cjs/selectors/Collection/types.js.map +0 -1
  61. package/dist/cjs/selectors/Entry/index.d.ts +0 -5
  62. package/dist/cjs/selectors/Entry/index.d.ts.map +0 -1
  63. package/dist/cjs/selectors/Entry/index.js +0 -14
  64. package/dist/cjs/selectors/Entry/index.js.map +0 -1
  65. package/dist/cjs/selectors/Entry/types.d.ts +0 -138
  66. package/dist/cjs/selectors/Entry/types.d.ts.map +0 -1
  67. package/dist/cjs/selectors/Entry/types.js +0 -3
  68. package/dist/cjs/selectors/Entry/types.js.map +0 -1
  69. package/dist/cjs/selectors/Form/index.d.ts +0 -4
  70. package/dist/cjs/selectors/Form/index.d.ts.map +0 -1
  71. package/dist/cjs/selectors/Form/index.js +0 -18
  72. package/dist/cjs/selectors/Form/index.js.map +0 -1
  73. package/dist/cjs/selectors/Form/types.d.ts +0 -22
  74. package/dist/cjs/selectors/Form/types.d.ts.map +0 -1
  75. package/dist/cjs/selectors/Form/types.js +0 -3
  76. package/dist/cjs/selectors/Form/types.js.map +0 -1
  77. package/dist/cjs/selectors/Media/index.d.ts +0 -5
  78. package/dist/cjs/selectors/Media/index.d.ts.map +0 -1
  79. package/dist/cjs/selectors/Media/index.js +0 -14
  80. package/dist/cjs/selectors/Media/index.js.map +0 -1
  81. package/dist/cjs/selectors/Media/types.d.ts +0 -49
  82. package/dist/cjs/selectors/Media/types.d.ts.map +0 -1
  83. package/dist/cjs/selectors/Media/types.js +0 -3
  84. package/dist/cjs/selectors/Media/types.js.map +0 -1
  85. package/dist/cjs/selectors/Model/index.d.ts +0 -5
  86. package/dist/cjs/selectors/Model/index.d.ts.map +0 -1
  87. package/dist/cjs/selectors/Model/index.js +0 -26
  88. package/dist/cjs/selectors/Model/index.js.map +0 -1
  89. package/dist/cjs/selectors/Model/types.d.ts +0 -78
  90. package/dist/cjs/selectors/Model/types.d.ts.map +0 -1
  91. package/dist/cjs/selectors/Model/types.js +0 -3
  92. package/dist/cjs/selectors/Model/types.js.map +0 -1
  93. package/dist/cjs/selectors/ModelCategory/index.d.ts +0 -5
  94. package/dist/cjs/selectors/ModelCategory/index.d.ts.map +0 -1
  95. package/dist/cjs/selectors/ModelCategory/index.js +0 -26
  96. package/dist/cjs/selectors/ModelCategory/index.js.map +0 -1
  97. package/dist/cjs/selectors/ModelCategory/types.d.ts +0 -87
  98. package/dist/cjs/selectors/ModelCategory/types.d.ts.map +0 -1
  99. package/dist/cjs/selectors/ModelCategory/types.js +0 -3
  100. package/dist/cjs/selectors/ModelCategory/types.js.map +0 -1
  101. package/dist/cjs/selectors/Search/index.d.ts +0 -5
  102. package/dist/cjs/selectors/Search/index.d.ts.map +0 -1
  103. package/dist/cjs/selectors/Search/index.js +0 -11
  104. package/dist/cjs/selectors/Search/index.js.map +0 -1
  105. package/dist/cjs/selectors/Search/types.d.ts +0 -90
  106. package/dist/cjs/selectors/Search/types.d.ts.map +0 -1
  107. package/dist/cjs/selectors/Search/types.js +0 -3
  108. package/dist/cjs/selectors/Search/types.js.map +0 -1
  109. package/dist/cjs/selectors/Singleton/index.d.ts +0 -5
  110. package/dist/cjs/selectors/Singleton/index.d.ts.map +0 -1
  111. package/dist/cjs/selectors/Singleton/index.js +0 -14
  112. package/dist/cjs/selectors/Singleton/index.js.map +0 -1
  113. package/dist/cjs/selectors/Singleton/types.d.ts +0 -64
  114. package/dist/cjs/selectors/Singleton/types.d.ts.map +0 -1
  115. package/dist/cjs/selectors/Singleton/types.js +0 -3
  116. package/dist/cjs/selectors/Singleton/types.js.map +0 -1
  117. package/dist/cjs/types/entities.d.ts +0 -362
  118. package/dist/cjs/types/entities.d.ts.map +0 -1
  119. package/dist/cjs/types/entities.js +0 -3
  120. package/dist/cjs/types/entities.js.map +0 -1
  121. package/dist/cjs/types/fields.d.ts +0 -123
  122. package/dist/cjs/types/fields.d.ts.map +0 -1
  123. package/dist/cjs/types/fields.js +0 -3
  124. package/dist/cjs/types/fields.js.map +0 -1
  125. package/dist/cjs/types/groups.d.ts +0 -30
  126. package/dist/cjs/types/groups.d.ts.map +0 -1
  127. package/dist/cjs/types/groups.js +0 -3
  128. package/dist/cjs/types/groups.js.map +0 -1
  129. package/dist/cjs/types/index.d.ts +0 -629
  130. package/dist/cjs/types/index.d.ts.map +0 -1
  131. package/dist/cjs/types/index.js +0 -24
  132. package/dist/cjs/types/index.js.map +0 -1
  133. package/dist/cjs/types/instances.d.ts +0 -4
  134. package/dist/cjs/types/instances.d.ts.map +0 -1
  135. package/dist/cjs/types/instances.js +0 -3
  136. package/dist/cjs/types/instances.js.map +0 -1
  137. package/dist/cjs/types/selectors.d.ts +0 -8
  138. package/dist/cjs/types/selectors.d.ts.map +0 -1
  139. package/dist/cjs/types/selectors.js +0 -3
  140. package/dist/cjs/types/selectors.js.map +0 -1
  141. package/dist/cjs/types/utilities.d.ts +0 -83
  142. package/dist/cjs/types/utilities.d.ts.map +0 -1
  143. package/dist/cjs/types/utilities.js +0 -3
  144. package/dist/cjs/types/utilities.js.map +0 -1
  145. package/dist/cjs/types/visual.d.ts +0 -185
  146. package/dist/cjs/types/visual.d.ts.map +0 -1
  147. package/dist/cjs/types/visual.js +0 -3
  148. package/dist/cjs/types/visual.js.map +0 -1
  149. package/dist/cjs/utils/image.d.ts +0 -72
  150. package/dist/cjs/utils/image.d.ts.map +0 -1
  151. package/dist/cjs/utils/image.js +0 -101
  152. package/dist/cjs/utils/image.js.map +0 -1
  153. package/dist/cjs/utils/index.d.ts +0 -2
  154. package/dist/cjs/utils/index.d.ts.map +0 -1
  155. package/dist/cjs/utils/index.js +0 -18
  156. package/dist/cjs/utils/index.js.map +0 -1
  157. package/dist/esm/client.d.ts +0 -42
  158. package/dist/esm/client.d.ts.map +0 -1
  159. package/dist/esm/client.js +0 -139
  160. package/dist/esm/client.js.map +0 -1
  161. package/dist/esm/errors.d.ts +0 -40
  162. package/dist/esm/errors.d.ts.map +0 -1
  163. package/dist/esm/errors.js +0 -14
  164. package/dist/esm/errors.js.map +0 -1
  165. package/dist/esm/index.d.ts +0 -29
  166. package/dist/esm/index.d.ts.map +0 -1
  167. package/dist/esm/index.js +0 -29
  168. package/dist/esm/index.js.map +0 -1
  169. package/dist/esm/instances/Collection/index.d.ts +0 -5
  170. package/dist/esm/instances/Collection/index.d.ts.map +0 -1
  171. package/dist/esm/instances/Collection/index.js +0 -11
  172. package/dist/esm/instances/Collection/index.js.map +0 -1
  173. package/dist/esm/instances/Collection/types.d.ts +0 -79
  174. package/dist/esm/instances/Collection/types.d.ts.map +0 -1
  175. package/dist/esm/instances/Collection/types.js +0 -2
  176. package/dist/esm/instances/Collection/types.js.map +0 -1
  177. package/dist/esm/instances/Form/index.d.ts +0 -5
  178. package/dist/esm/instances/Form/index.d.ts.map +0 -1
  179. package/dist/esm/instances/Form/index.js +0 -11
  180. package/dist/esm/instances/Form/index.js.map +0 -1
  181. package/dist/esm/instances/Form/types.d.ts +0 -46
  182. package/dist/esm/instances/Form/types.d.ts.map +0 -1
  183. package/dist/esm/instances/Form/types.js +0 -2
  184. package/dist/esm/instances/Form/types.js.map +0 -1
  185. package/dist/esm/instances/Model/index.d.ts +0 -5
  186. package/dist/esm/instances/Model/index.d.ts.map +0 -1
  187. package/dist/esm/instances/Model/index.js +0 -28
  188. package/dist/esm/instances/Model/index.js.map +0 -1
  189. package/dist/esm/instances/Model/types.d.ts +0 -102
  190. package/dist/esm/instances/Model/types.d.ts.map +0 -1
  191. package/dist/esm/instances/Model/types.js +0 -2
  192. package/dist/esm/instances/Model/types.js.map +0 -1
  193. package/dist/esm/instances/ModelCategory/index.d.ts +0 -5
  194. package/dist/esm/instances/ModelCategory/index.d.ts.map +0 -1
  195. package/dist/esm/instances/ModelCategory/index.js +0 -11
  196. package/dist/esm/instances/ModelCategory/index.js.map +0 -1
  197. package/dist/esm/instances/ModelCategory/types.d.ts +0 -76
  198. package/dist/esm/instances/ModelCategory/types.d.ts.map +0 -1
  199. package/dist/esm/instances/ModelCategory/types.js +0 -2
  200. package/dist/esm/instances/ModelCategory/types.js.map +0 -1
  201. package/dist/esm/selectors/Collection/index.d.ts +0 -5
  202. package/dist/esm/selectors/Collection/index.d.ts.map +0 -1
  203. package/dist/esm/selectors/Collection/index.js +0 -20
  204. package/dist/esm/selectors/Collection/index.js.map +0 -1
  205. package/dist/esm/selectors/Collection/types.d.ts +0 -98
  206. package/dist/esm/selectors/Collection/types.d.ts.map +0 -1
  207. package/dist/esm/selectors/Collection/types.js +0 -2
  208. package/dist/esm/selectors/Collection/types.js.map +0 -1
  209. package/dist/esm/selectors/Entry/index.d.ts +0 -5
  210. package/dist/esm/selectors/Entry/index.d.ts.map +0 -1
  211. package/dist/esm/selectors/Entry/index.js +0 -11
  212. package/dist/esm/selectors/Entry/index.js.map +0 -1
  213. package/dist/esm/selectors/Entry/types.d.ts +0 -138
  214. package/dist/esm/selectors/Entry/types.d.ts.map +0 -1
  215. package/dist/esm/selectors/Entry/types.js +0 -2
  216. package/dist/esm/selectors/Entry/types.js.map +0 -1
  217. package/dist/esm/selectors/Form/index.d.ts +0 -4
  218. package/dist/esm/selectors/Form/index.d.ts.map +0 -1
  219. package/dist/esm/selectors/Form/index.js +0 -12
  220. package/dist/esm/selectors/Form/index.js.map +0 -1
  221. package/dist/esm/selectors/Form/types.d.ts +0 -22
  222. package/dist/esm/selectors/Form/types.d.ts.map +0 -1
  223. package/dist/esm/selectors/Form/types.js +0 -2
  224. package/dist/esm/selectors/Form/types.js.map +0 -1
  225. package/dist/esm/selectors/Media/index.d.ts +0 -5
  226. package/dist/esm/selectors/Media/index.d.ts.map +0 -1
  227. package/dist/esm/selectors/Media/index.js +0 -11
  228. package/dist/esm/selectors/Media/index.js.map +0 -1
  229. package/dist/esm/selectors/Media/types.d.ts +0 -49
  230. package/dist/esm/selectors/Media/types.d.ts.map +0 -1
  231. package/dist/esm/selectors/Media/types.js +0 -2
  232. package/dist/esm/selectors/Media/types.js.map +0 -1
  233. package/dist/esm/selectors/Model/index.d.ts +0 -5
  234. package/dist/esm/selectors/Model/index.d.ts.map +0 -1
  235. package/dist/esm/selectors/Model/index.js +0 -20
  236. package/dist/esm/selectors/Model/index.js.map +0 -1
  237. package/dist/esm/selectors/Model/types.d.ts +0 -78
  238. package/dist/esm/selectors/Model/types.d.ts.map +0 -1
  239. package/dist/esm/selectors/Model/types.js +0 -2
  240. package/dist/esm/selectors/Model/types.js.map +0 -1
  241. package/dist/esm/selectors/ModelCategory/index.d.ts +0 -5
  242. package/dist/esm/selectors/ModelCategory/index.d.ts.map +0 -1
  243. package/dist/esm/selectors/ModelCategory/index.js +0 -20
  244. package/dist/esm/selectors/ModelCategory/index.js.map +0 -1
  245. package/dist/esm/selectors/ModelCategory/types.d.ts +0 -87
  246. package/dist/esm/selectors/ModelCategory/types.d.ts.map +0 -1
  247. package/dist/esm/selectors/ModelCategory/types.js +0 -2
  248. package/dist/esm/selectors/ModelCategory/types.js.map +0 -1
  249. package/dist/esm/selectors/Search/index.d.ts +0 -5
  250. package/dist/esm/selectors/Search/index.d.ts.map +0 -1
  251. package/dist/esm/selectors/Search/index.js +0 -8
  252. package/dist/esm/selectors/Search/index.js.map +0 -1
  253. package/dist/esm/selectors/Search/types.d.ts +0 -90
  254. package/dist/esm/selectors/Search/types.d.ts.map +0 -1
  255. package/dist/esm/selectors/Search/types.js +0 -2
  256. package/dist/esm/selectors/Search/types.js.map +0 -1
  257. package/dist/esm/selectors/Singleton/index.d.ts +0 -5
  258. package/dist/esm/selectors/Singleton/index.d.ts.map +0 -1
  259. package/dist/esm/selectors/Singleton/index.js +0 -11
  260. package/dist/esm/selectors/Singleton/index.js.map +0 -1
  261. package/dist/esm/selectors/Singleton/types.d.ts +0 -64
  262. package/dist/esm/selectors/Singleton/types.d.ts.map +0 -1
  263. package/dist/esm/selectors/Singleton/types.js +0 -2
  264. package/dist/esm/selectors/Singleton/types.js.map +0 -1
  265. package/dist/esm/types/entities.d.ts +0 -362
  266. package/dist/esm/types/entities.d.ts.map +0 -1
  267. package/dist/esm/types/entities.js +0 -2
  268. package/dist/esm/types/entities.js.map +0 -1
  269. package/dist/esm/types/fields.d.ts +0 -123
  270. package/dist/esm/types/fields.d.ts.map +0 -1
  271. package/dist/esm/types/fields.js +0 -2
  272. package/dist/esm/types/fields.js.map +0 -1
  273. package/dist/esm/types/groups.d.ts +0 -30
  274. package/dist/esm/types/groups.d.ts.map +0 -1
  275. package/dist/esm/types/groups.js +0 -2
  276. package/dist/esm/types/groups.js.map +0 -1
  277. package/dist/esm/types/index.d.ts +0 -629
  278. package/dist/esm/types/index.d.ts.map +0 -1
  279. package/dist/esm/types/index.js +0 -8
  280. package/dist/esm/types/index.js.map +0 -1
  281. package/dist/esm/types/instances.d.ts +0 -4
  282. package/dist/esm/types/instances.d.ts.map +0 -1
  283. package/dist/esm/types/instances.js +0 -2
  284. package/dist/esm/types/instances.js.map +0 -1
  285. package/dist/esm/types/selectors.d.ts +0 -8
  286. package/dist/esm/types/selectors.d.ts.map +0 -1
  287. package/dist/esm/types/selectors.js +0 -2
  288. package/dist/esm/types/selectors.js.map +0 -1
  289. package/dist/esm/types/utilities.d.ts +0 -83
  290. package/dist/esm/types/utilities.d.ts.map +0 -1
  291. package/dist/esm/types/utilities.js +0 -2
  292. package/dist/esm/types/utilities.js.map +0 -1
  293. package/dist/esm/types/visual.d.ts +0 -185
  294. package/dist/esm/types/visual.d.ts.map +0 -1
  295. package/dist/esm/types/visual.js +0 -2
  296. package/dist/esm/types/visual.js.map +0 -1
  297. package/dist/esm/utils/image.d.ts +0 -72
  298. package/dist/esm/utils/image.d.ts.map +0 -1
  299. package/dist/esm/utils/image.js +0 -96
  300. package/dist/esm/utils/image.js.map +0 -1
  301. package/dist/esm/utils/index.d.ts +0 -2
  302. package/dist/esm/utils/index.d.ts.map +0 -1
  303. package/dist/esm/utils/index.js +0 -2
  304. package/dist/esm/utils/index.js.map +0 -1
package/dist/index.cjs ADDED
@@ -0,0 +1,397 @@
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ //#region src/errors.ts
6
+ /**
7
+ * This error is thrown every time a problem occurs when requesting something
8
+ * from Starlight's APIs. When it does, you can inspect the attached response
9
+ * to verify what kind of problem happened and handle it accordingly.
10
+ *
11
+ * @group Errors
12
+ */
13
+ var StarlightError = class extends Error {
14
+ constructor(message, response) {
15
+ super(message);
16
+ this.response = response;
17
+ }
18
+ };
19
+ //#endregion
20
+ //#region src/selectors/Entry/index.ts
21
+ function makeEntrySelector(client, model) {
22
+ return {
23
+ list(params, options) {
24
+ return client.get(`/models/${model}/entries`, params, options);
25
+ },
26
+ get(slug, params, options) {
27
+ return client.get(`/models/${model}/entries/${slug}`, params, options);
28
+ }
29
+ };
30
+ }
31
+ //#endregion
32
+ //#region src/instances/ModelCategory/index.ts
33
+ function makeModelCategoryInstance(client, model, category) {
34
+ return {
35
+ get(params, options) {
36
+ return client.get(`/models/${model}/categories/${category}`, params, options);
37
+ },
38
+ entries(params, options) {
39
+ return client.get(`/models/${model}/categories/${category}/entries`, params, options);
40
+ }
41
+ };
42
+ }
43
+ //#endregion
44
+ //#region src/selectors/ModelCategory/index.ts
45
+ function makeModelCategorySelector(client, model) {
46
+ return new Proxy({
47
+ list(params, options) {
48
+ return client.get(`/models/${model}/categories`, params, options);
49
+ },
50
+ get(slug, params, options) {
51
+ return client.get(`/models/${model}/categories/${slug}`, params, options);
52
+ }
53
+ }, { get(target, prop) {
54
+ if (typeof prop === "string" && !Reflect.has(target, prop)) return makeModelCategoryInstance(client, model, prop);
55
+ return Reflect.get(target, prop);
56
+ } });
57
+ }
58
+ //#endregion
59
+ //#region src/instances/Model/index.ts
60
+ function makeModelInstance(client, model) {
61
+ return new Proxy({
62
+ get(params, options) {
63
+ return client.get(`/models/${model}`, params, options);
64
+ },
65
+ category(slug) {
66
+ return makeModelCategoryInstance(client, model, slug);
67
+ },
68
+ get entries() {
69
+ return makeEntrySelector(client, model);
70
+ },
71
+ get categories() {
72
+ return makeModelCategorySelector(client, model);
73
+ }
74
+ }, { get(target, prop) {
75
+ if (typeof prop === "string" && !Reflect.has(target, prop)) return makeModelCategoryInstance(client, model, prop);
76
+ return Reflect.get(target, prop);
77
+ } });
78
+ }
79
+ //#endregion
80
+ //#region src/selectors/Model/index.ts
81
+ function makeModelSelector(client) {
82
+ return new Proxy({
83
+ list(params, options) {
84
+ return client.get("/models", params, options);
85
+ },
86
+ get(slug, params, options) {
87
+ return client.get(`/models/${slug}`, params, options);
88
+ }
89
+ }, { get(target, prop) {
90
+ if (typeof prop === "string" && !Reflect.has(target, prop)) return makeModelInstance(client, prop);
91
+ return Reflect.get(target, prop);
92
+ } });
93
+ }
94
+ //#endregion
95
+ //#region src/selectors/Singleton/index.ts
96
+ function makeSingletonSelector(client) {
97
+ return {
98
+ list(params, options) {
99
+ return client.get("/singletons", params, options);
100
+ },
101
+ get(slug, params, options) {
102
+ return client.get(`/singletons/${slug}`, params, options);
103
+ }
104
+ };
105
+ }
106
+ //#endregion
107
+ //#region src/instances/Collection/index.ts
108
+ function makeCollectionInstance(client, collection) {
109
+ return {
110
+ get(params, options) {
111
+ return client.get(`/collections/${collection}`, params, options);
112
+ },
113
+ items(params, options) {
114
+ return client.get(`/collections/${collection}/items`, params, options);
115
+ }
116
+ };
117
+ }
118
+ //#endregion
119
+ //#region src/selectors/Collection/index.ts
120
+ function makeCollectionSelector(client) {
121
+ return new Proxy({
122
+ list(params, options) {
123
+ return client.get("/collections", params, options);
124
+ },
125
+ get(slug, params, options) {
126
+ return client.get(`/collections/${slug}`, params, options);
127
+ }
128
+ }, { get(target, prop) {
129
+ if (typeof prop === "string" && !Reflect.has(target, prop)) return makeCollectionInstance(client, prop);
130
+ return Reflect.get(target, prop);
131
+ } });
132
+ }
133
+ //#endregion
134
+ //#region src/selectors/Media/index.ts
135
+ function makeMediaSelector(client) {
136
+ return {
137
+ list(params, options) {
138
+ return client.get("/media", params, options);
139
+ },
140
+ get(id, params, options) {
141
+ return client.get(`/media/${id}`, params, options);
142
+ }
143
+ };
144
+ }
145
+ //#endregion
146
+ //#region src/selectors/Search/index.ts
147
+ function makeSearchSelector(client) {
148
+ return { entries(params, options) {
149
+ return client.get("/search/entries", params, options);
150
+ } };
151
+ }
152
+ //#endregion
153
+ //#region src/instances/Form/index.ts
154
+ function makeFormInstance(client, form) {
155
+ return {
156
+ get(params, options) {
157
+ return client.get(`/forms/${form}`, params, options);
158
+ },
159
+ schema(params, options) {
160
+ return client.get(`/forms/${form}/schema`, params, options);
161
+ }
162
+ };
163
+ }
164
+ //#endregion
165
+ //#region src/selectors/Form/index.ts
166
+ function makeFormSelector(client) {
167
+ return new Proxy({}, { get(target, prop) {
168
+ if (typeof prop === "string" && !Reflect.has(target, prop)) return makeFormInstance(client, prop);
169
+ return Reflect.get(target, prop);
170
+ } });
171
+ }
172
+ //#endregion
173
+ //#region src/client.ts
174
+ /**
175
+ * Returns a new {@link DynamicStarlightClient}, which is a
176
+ * {@link StarlightClient} with support to create
177
+ * {@apilink ModelInstance | ModelInstances} using the dynamic syntax. To learn
178
+ * which methods a client supports, see {@link StarlightClient}.
179
+ *
180
+ * This function accepts a {@link StarlightConfig} object and can be used to
181
+ * create new clients that connect to a single Starlight workspace. Each client
182
+ * returned by this function is separate and independent of the others.
183
+ *
184
+ * If you only need to make requests to a single workspace, it's probably easier
185
+ * to use the SDK's default client. To use it, you only need to
186
+ * import the default object exported by the SDK:
187
+ *
188
+ * ```ts
189
+ * // `Starlight` below is the default StarlightClient.
190
+ * import Starlight from '@starlightcms/js-sdk'
191
+ * ```
192
+ *
193
+ * See {@link default} for more info on how to use the default client.
194
+ *
195
+ * @example Creating a new client and exporting it.
196
+ * ```ts
197
+ * import { makeStarlightClient } from '@starlightcms/js-sdk'
198
+ *
199
+ * const BlogClient = makeStarlightClient({
200
+ * workspace: '123123123',
201
+ * debug: true
202
+ * })
203
+ *
204
+ * // Feel free to export the new client so your application can use it.
205
+ * export default BlogClient
206
+ * ```
207
+ *
208
+ * @param config The client configuration object. You need to provide at least
209
+ * the `workspace` property. See {@link StarlightConfig} to view all the
210
+ * available options.
211
+ * @group Client
212
+ */
213
+ function makeClient(config = {}) {
214
+ let baseUrl = config.baseUrl ?? "https://query.starlightcms.io/v2";
215
+ let workspace = config.workspace ?? "";
216
+ let debug = config.debug ?? false;
217
+ return new Proxy({
218
+ configure(config) {
219
+ baseUrl = config.baseUrl ?? baseUrl;
220
+ workspace = config.workspace ?? workspace;
221
+ debug = config.debug ?? debug;
222
+ },
223
+ log(message, ...optionalParams) {
224
+ if (debug) console.log(message, ...optionalParams);
225
+ },
226
+ getBaseUrl() {
227
+ if (!workspace.length) throw new Error("No workspace defined. Use the `configure()` method on the Starlight client to define one.");
228
+ return `${baseUrl}/workspaces/${workspace}`;
229
+ },
230
+ async get(path, params = {}, options) {
231
+ const filteredParams = Object.keys(params).reduce((accumulator, key) => {
232
+ const param = params[key];
233
+ if (param || param === false || param === 0) accumulator[key] = String(param);
234
+ return accumulator;
235
+ }, {});
236
+ const searchParams = new URLSearchParams(filteredParams).toString();
237
+ const finalPath = searchParams ? `${path}?${searchParams}` : path;
238
+ this.log(`Starlight - GET ${finalPath}`);
239
+ const response = await fetch(`${this.getBaseUrl()}${finalPath}`, options);
240
+ if (response.status >= 200 && response.status < 300) return await response.json();
241
+ else throw new StarlightError(`Starlight - GET ${path} returned ${response.status}: ${response.statusText}`, response);
242
+ },
243
+ get models() {
244
+ return makeModelSelector(this);
245
+ },
246
+ model(slug) {
247
+ return makeModelInstance(this, slug);
248
+ },
249
+ get forms() {
250
+ return makeFormSelector(this);
251
+ },
252
+ form(slug) {
253
+ return makeFormInstance(this, String(slug));
254
+ },
255
+ get singletons() {
256
+ return makeSingletonSelector(this);
257
+ },
258
+ get collections() {
259
+ return makeCollectionSelector(this);
260
+ },
261
+ collection(slug) {
262
+ return makeCollectionInstance(this, slug);
263
+ },
264
+ get media() {
265
+ return makeMediaSelector(this);
266
+ },
267
+ get search() {
268
+ return makeSearchSelector(this);
269
+ }
270
+ }, { get(target, prop) {
271
+ if (typeof prop === "string" && !Reflect.has(target, prop)) return makeModelInstance(target, prop);
272
+ return Reflect.get(target, prop);
273
+ } });
274
+ }
275
+ //#endregion
276
+ //#region src/utils/image.ts
277
+ /**
278
+ * Returns the optimized variation file of the given MediaObject
279
+ * or the original file if the optimized variation doesn't exist.
280
+ *
281
+ * @param media The MediaObject to analyze.
282
+ */
283
+ const getOptimizedOrOriginal = (media) => {
284
+ return media.files.find((file) => file.variation === "optimized") ?? media.files.find((file) => file.variation === "original");
285
+ };
286
+ /**
287
+ * Returns the given variation of the provided MediaObject.
288
+ *
289
+ * @param media The MediaObject to analyze. If undefined, the function will also
290
+ * return undefined.
291
+ * @param variation A string or array of strings with the variation name that
292
+ * should be returned. If an array is given, the first variation found will
293
+ * be returned.
294
+ *
295
+ * @returns The MediaFile of the first given variation found. If the provided
296
+ * variations weren't found, or if no variation parameter was provided, returns
297
+ * the optimized variation file (if it exists) or the original file. Returns
298
+ * undefined if no media object is provided.
299
+ *
300
+ * @example Getting the optimized or original file of the given MediaObject.
301
+ * ```ts
302
+ * import Starlight, { getMediaFile } from '@starlightcms/js-sdk'
303
+ *
304
+ * const response = await Starlight.posts.entries.get('foo')
305
+ *
306
+ * // `info.featured_image` is the path of an arbitrary Media content field.
307
+ * const file = getMediaFile(response.data.data.info.featured_image)
308
+ * ```
309
+ *
310
+ * @category Media Utilities
311
+ */
312
+ const getMediaFile = (media, variation) => {
313
+ if (!media) return void 0;
314
+ if (variation) {
315
+ const variationArray = Array.isArray(variation) ? variation : [variation];
316
+ for (const variationName of variationArray) {
317
+ const file = media.files.find((file) => file.variation === variationName);
318
+ if (file) return file;
319
+ }
320
+ }
321
+ return getOptimizedOrOriginal(media);
322
+ };
323
+ /**
324
+ * Returns the source URL of the optimized file (if it exists) or the original
325
+ * file of the given MediaObject. If the variation parameter is provided,
326
+ * returns the source URL of that variation instead, if it exists, but falls
327
+ * back to the optimized or original files if it doesn't.
328
+ *
329
+ * @param media The MediaObject to analyze. If undefined, the function will also
330
+ * return undefined.
331
+ * @param variation A string or array of strings with the variation name that
332
+ * should be returned. If an array is given, the first variation found will
333
+ * be returned.
334
+ *
335
+ * @returns The source URL of the first given variation found. If the provided
336
+ * variations weren't found, or if no variation parameter was provided, returns
337
+ * the optimized variation source URL (if it exists) or the original source URL.
338
+ * Returns undefined if no media object is provided.
339
+ *
340
+ * @example Getting the optimized or original source URL of the given MediaObject.
341
+ * ```ts
342
+ * import Starlight, { getMediaSource } from '@starlightcms/js-sdk'
343
+ *
344
+ * const response = await Starlight.posts.entries.get('foo')
345
+ *
346
+ * // `content.background` is the path of an arbitrary Media content field.
347
+ * const imageUrl = getMediaSource(response.data.data.content.background)
348
+ * ```
349
+ *
350
+ * @example Getting the source URL of a specific variation of the given MediaObject.
351
+ * ```ts
352
+ * import Starlight, { getMediaSource } from '@starlightcms/js-sdk'
353
+ *
354
+ * const response = await Starlight.posts.entries.get('foo')
355
+ *
356
+ * // `content.background` is the path of an arbitrary Media content field.
357
+ * const imageUrl = getMediaSource(
358
+ * response.data.data.content.background,
359
+ * ['large', 'medium']
360
+ * )
361
+ * ```
362
+ *
363
+ * @category Media Utilities
364
+ */
365
+ function getMediaSource(media, variation) {
366
+ return media ? getMediaFile(media, variation).path : void 0;
367
+ }
368
+ //#endregion
369
+ //#region src/index.ts
370
+ /**
371
+ * This is the default object exported by the SDK module, which is a
372
+ * pre-created {@link StarlightClient}. In the docs, this is called the "global
373
+ * SDK client". If your application only requests data from a single Starlight
374
+ * workspace, using this client is easier than creating
375
+ * a new one using {@link makeStarlightClient}.
376
+ *
377
+ * Using the default client is as easy as importing the SDK:
378
+ *
379
+ * ```ts
380
+ * // "Starlight" below is the default client.
381
+ * import Starlight from '@starlightcms/js-sdk'
382
+ *
383
+ * const response = await Starlight.posts.entries.list()
384
+ * ```
385
+ *
386
+ * You need to configure the default workspace before using it.
387
+ * See {@apilink StarlightClient.configure} to learn more.
388
+ *
389
+ * @group Client
390
+ */
391
+ const Starlight = makeClient();
392
+ //#endregion
393
+ exports.StarlightError = StarlightError;
394
+ exports.default = Starlight;
395
+ exports.getMediaFile = getMediaFile;
396
+ exports.getMediaSource = getMediaSource;
397
+ exports.makeStarlightClient = makeClient;