@seshuk/payload-plugin-openapi 0.2.2 → 1.0.0-beta.1

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 (377) hide show
  1. package/README.md +67 -25
  2. package/dist/_tooling/telemetry.js +168 -0
  3. package/dist/_tooling/telemetry.js.map +1 -0
  4. package/dist/cli/generateSpec.d.ts +2 -0
  5. package/dist/cli/generateSpec.js +40 -0
  6. package/dist/cli/generateSpec.js.map +1 -0
  7. package/dist/index.d.ts +8 -9
  8. package/dist/index.js +76 -65
  9. package/dist/index.js.map +1 -0
  10. package/dist/{endpoints → server/endpoints}/interactiveAuth.d.ts +2 -2
  11. package/dist/server/endpoints/interactiveAuth.js +25 -0
  12. package/dist/server/endpoints/interactiveAuth.js.map +1 -0
  13. package/dist/server/endpoints/spec.d.ts +5 -0
  14. package/dist/server/endpoints/spec.js +39 -0
  15. package/dist/server/endpoints/spec.js.map +1 -0
  16. package/dist/server/options/resolveOptions.d.ts +4 -0
  17. package/dist/server/options/resolveOptions.js +65 -0
  18. package/dist/server/options/resolveOptions.js.map +1 -0
  19. package/dist/server/spec/build.d.ts +14 -0
  20. package/dist/server/spec/build.js +40 -0
  21. package/dist/server/spec/build.js.map +1 -0
  22. package/dist/server/spec/buildDocument.d.ts +16 -0
  23. package/dist/server/spec/buildDocument.js +287 -0
  24. package/dist/server/spec/buildDocument.js.map +1 -0
  25. package/dist/server/spec/components.d.ts +61 -0
  26. package/dist/server/spec/components.js +265 -0
  27. package/dist/server/spec/components.js.map +1 -0
  28. package/dist/{spec → server/spec}/downconvert.d.ts +2 -1
  29. package/dist/server/spec/downconvert.js +69 -0
  30. package/dist/server/spec/downconvert.js.map +1 -0
  31. package/dist/server/spec/entitySchemas.d.ts +16 -0
  32. package/dist/server/spec/entitySchemas.js +207 -0
  33. package/dist/server/spec/entitySchemas.js.map +1 -0
  34. package/dist/{spec → server/spec}/fields.d.ts +2 -1
  35. package/dist/server/spec/fields.js +47 -0
  36. package/dist/server/spec/fields.js.map +1 -0
  37. package/dist/server/spec/filters.d.ts +12 -0
  38. package/dist/server/spec/filters.js +91 -0
  39. package/dist/server/spec/filters.js.map +1 -0
  40. package/dist/server/spec/hierarchy.d.ts +11 -0
  41. package/dist/server/spec/hierarchy.js +38 -0
  42. package/dist/server/spec/hierarchy.js.map +1 -0
  43. package/dist/{spec → server/spec}/names.d.ts +2 -2
  44. package/dist/server/spec/names.js +43 -0
  45. package/dist/server/spec/names.js.map +1 -0
  46. package/dist/server/spec/params.d.ts +57 -0
  47. package/dist/server/spec/params.js +394 -0
  48. package/dist/server/spec/params.js.map +1 -0
  49. package/dist/server/spec/paths/auth.d.ts +10 -0
  50. package/dist/server/spec/paths/auth.js +190 -0
  51. package/dist/server/spec/paths/auth.js.map +1 -0
  52. package/dist/server/spec/paths/collections.d.ts +11 -0
  53. package/dist/server/spec/paths/collections.js +314 -0
  54. package/dist/server/spec/paths/collections.js.map +1 -0
  55. package/dist/server/spec/paths/custom.d.ts +10 -0
  56. package/dist/server/spec/paths/custom.js +42 -0
  57. package/dist/server/spec/paths/custom.js.map +1 -0
  58. package/dist/server/spec/paths/globals.d.ts +11 -0
  59. package/dist/server/spec/paths/globals.js +87 -0
  60. package/dist/server/spec/paths/globals.js.map +1 -0
  61. package/dist/server/spec/paths/jobs.d.ts +9 -0
  62. package/dist/server/spec/paths/jobs.js +98 -0
  63. package/dist/server/spec/paths/jobs.js.map +1 -0
  64. package/dist/server/spec/paths/system.d.ts +8 -0
  65. package/dist/server/spec/paths/system.js +137 -0
  66. package/dist/server/spec/paths/system.js.map +1 -0
  67. package/dist/server/spec/paths/versions.d.ts +22 -0
  68. package/dist/server/spec/paths/versions.js +185 -0
  69. package/dist/server/spec/paths/versions.js.map +1 -0
  70. package/dist/server/spec/security.d.ts +33 -0
  71. package/dist/server/spec/security.js +97 -0
  72. package/dist/server/spec/security.js.map +1 -0
  73. package/dist/server/spec/tags.d.ts +34 -0
  74. package/dist/server/spec/tags.js +83 -0
  75. package/dist/server/spec/tags.js.map +1 -0
  76. package/dist/server/telemetry.d.ts +31 -0
  77. package/dist/server/telemetry.js +33 -0
  78. package/dist/server/telemetry.js.map +1 -0
  79. package/dist/server/ui/createUiPlugin.d.ts +16 -0
  80. package/dist/server/ui/createUiPlugin.js +33 -0
  81. package/dist/server/ui/createUiPlugin.js.map +1 -0
  82. package/dist/{ui → server/ui}/html.d.ts +5 -3
  83. package/dist/server/ui/html.js +11 -0
  84. package/dist/server/ui/html.js.map +1 -0
  85. package/dist/server/ui/scalar.d.ts +4 -0
  86. package/dist/server/ui/scalar.js +17 -0
  87. package/dist/server/ui/scalar.js.map +1 -0
  88. package/dist/server/ui/swagger.d.ts +4 -0
  89. package/dist/server/ui/swagger.js +18 -0
  90. package/dist/server/ui/swagger.js.map +1 -0
  91. package/dist/shared/constants.d.ts +4 -0
  92. package/dist/shared/constants.js +6 -0
  93. package/dist/shared/constants.js.map +1 -0
  94. package/dist/shared/translations/index.d.ts +5 -0
  95. package/dist/{translations → shared/translations}/index.js +49 -47
  96. package/dist/shared/translations/index.js.map +1 -0
  97. package/dist/shared/translations/locales/ar.d.ts +3 -0
  98. package/dist/shared/translations/locales/ar.js +99 -0
  99. package/dist/shared/translations/locales/ar.js.map +1 -0
  100. package/dist/shared/translations/locales/az.d.ts +3 -0
  101. package/dist/shared/translations/locales/az.js +99 -0
  102. package/dist/shared/translations/locales/az.js.map +1 -0
  103. package/dist/shared/translations/locales/bg.d.ts +3 -0
  104. package/dist/shared/translations/locales/bg.js +99 -0
  105. package/dist/shared/translations/locales/bg.js.map +1 -0
  106. package/dist/shared/translations/locales/bnBd.d.ts +3 -0
  107. package/dist/shared/translations/locales/bnBd.js +99 -0
  108. package/dist/shared/translations/locales/bnBd.js.map +1 -0
  109. package/dist/shared/translations/locales/bnIn.d.ts +3 -0
  110. package/dist/shared/translations/locales/bnIn.js +99 -0
  111. package/dist/shared/translations/locales/bnIn.js.map +1 -0
  112. package/dist/shared/translations/locales/ca.d.ts +3 -0
  113. package/dist/shared/translations/locales/ca.js +99 -0
  114. package/dist/shared/translations/locales/ca.js.map +1 -0
  115. package/dist/shared/translations/locales/cs.d.ts +3 -0
  116. package/dist/shared/translations/locales/cs.js +99 -0
  117. package/dist/shared/translations/locales/cs.js.map +1 -0
  118. package/dist/shared/translations/locales/da.d.ts +3 -0
  119. package/dist/shared/translations/locales/da.js +99 -0
  120. package/dist/shared/translations/locales/da.js.map +1 -0
  121. package/dist/shared/translations/locales/de.d.ts +3 -0
  122. package/dist/shared/translations/locales/de.js +99 -0
  123. package/dist/shared/translations/locales/de.js.map +1 -0
  124. package/dist/shared/translations/locales/en.d.ts +3 -0
  125. package/dist/shared/translations/locales/en.js +99 -0
  126. package/dist/shared/translations/locales/en.js.map +1 -0
  127. package/dist/shared/translations/locales/es.d.ts +3 -0
  128. package/dist/shared/translations/locales/es.js +99 -0
  129. package/dist/shared/translations/locales/es.js.map +1 -0
  130. package/dist/shared/translations/locales/et.d.ts +3 -0
  131. package/dist/shared/translations/locales/et.js +99 -0
  132. package/dist/shared/translations/locales/et.js.map +1 -0
  133. package/dist/shared/translations/locales/fa.d.ts +3 -0
  134. package/dist/shared/translations/locales/fa.js +99 -0
  135. package/dist/shared/translations/locales/fa.js.map +1 -0
  136. package/dist/shared/translations/locales/fr.d.ts +3 -0
  137. package/dist/shared/translations/locales/fr.js +99 -0
  138. package/dist/shared/translations/locales/fr.js.map +1 -0
  139. package/dist/shared/translations/locales/he.d.ts +3 -0
  140. package/dist/shared/translations/locales/he.js +99 -0
  141. package/dist/shared/translations/locales/he.js.map +1 -0
  142. package/dist/shared/translations/locales/hr.d.ts +3 -0
  143. package/dist/shared/translations/locales/hr.js +99 -0
  144. package/dist/shared/translations/locales/hr.js.map +1 -0
  145. package/dist/shared/translations/locales/hu.d.ts +3 -0
  146. package/dist/shared/translations/locales/hu.js +99 -0
  147. package/dist/shared/translations/locales/hu.js.map +1 -0
  148. package/dist/shared/translations/locales/hy.d.ts +3 -0
  149. package/dist/shared/translations/locales/hy.js +99 -0
  150. package/dist/shared/translations/locales/hy.js.map +1 -0
  151. package/dist/shared/translations/locales/id.d.ts +3 -0
  152. package/dist/shared/translations/locales/id.js +99 -0
  153. package/dist/shared/translations/locales/id.js.map +1 -0
  154. package/dist/shared/translations/locales/is.d.ts +3 -0
  155. package/dist/shared/translations/locales/is.js +99 -0
  156. package/dist/shared/translations/locales/is.js.map +1 -0
  157. package/dist/shared/translations/locales/it.d.ts +3 -0
  158. package/dist/shared/translations/locales/it.js +99 -0
  159. package/dist/shared/translations/locales/it.js.map +1 -0
  160. package/dist/shared/translations/locales/ja.d.ts +3 -0
  161. package/dist/shared/translations/locales/ja.js +99 -0
  162. package/dist/shared/translations/locales/ja.js.map +1 -0
  163. package/dist/shared/translations/locales/ko.d.ts +3 -0
  164. package/dist/shared/translations/locales/ko.js +99 -0
  165. package/dist/shared/translations/locales/ko.js.map +1 -0
  166. package/dist/shared/translations/locales/lt.d.ts +3 -0
  167. package/dist/shared/translations/locales/lt.js +99 -0
  168. package/dist/shared/translations/locales/lt.js.map +1 -0
  169. package/dist/shared/translations/locales/lv.d.ts +3 -0
  170. package/dist/shared/translations/locales/lv.js +99 -0
  171. package/dist/shared/translations/locales/lv.js.map +1 -0
  172. package/dist/shared/translations/locales/my.d.ts +3 -0
  173. package/dist/shared/translations/locales/my.js +99 -0
  174. package/dist/shared/translations/locales/my.js.map +1 -0
  175. package/dist/shared/translations/locales/nb.d.ts +3 -0
  176. package/dist/shared/translations/locales/nb.js +99 -0
  177. package/dist/shared/translations/locales/nb.js.map +1 -0
  178. package/dist/shared/translations/locales/nl.d.ts +3 -0
  179. package/dist/shared/translations/locales/nl.js +99 -0
  180. package/dist/shared/translations/locales/nl.js.map +1 -0
  181. package/dist/shared/translations/locales/pl.d.ts +3 -0
  182. package/dist/shared/translations/locales/pl.js +99 -0
  183. package/dist/shared/translations/locales/pl.js.map +1 -0
  184. package/dist/shared/translations/locales/pt.d.ts +3 -0
  185. package/dist/shared/translations/locales/pt.js +99 -0
  186. package/dist/shared/translations/locales/pt.js.map +1 -0
  187. package/dist/shared/translations/locales/ro.d.ts +3 -0
  188. package/dist/shared/translations/locales/ro.js +99 -0
  189. package/dist/shared/translations/locales/ro.js.map +1 -0
  190. package/dist/shared/translations/locales/rs.d.ts +3 -0
  191. package/dist/shared/translations/locales/rs.js +99 -0
  192. package/dist/shared/translations/locales/rs.js.map +1 -0
  193. package/dist/shared/translations/locales/rsLatin.d.ts +3 -0
  194. package/dist/shared/translations/locales/rsLatin.js +99 -0
  195. package/dist/shared/translations/locales/rsLatin.js.map +1 -0
  196. package/dist/shared/translations/locales/ru.d.ts +3 -0
  197. package/dist/shared/translations/locales/ru.js +99 -0
  198. package/dist/shared/translations/locales/ru.js.map +1 -0
  199. package/dist/shared/translations/locales/sk.d.ts +3 -0
  200. package/dist/shared/translations/locales/sk.js +99 -0
  201. package/dist/shared/translations/locales/sk.js.map +1 -0
  202. package/dist/shared/translations/locales/sl.d.ts +3 -0
  203. package/dist/shared/translations/locales/sl.js +99 -0
  204. package/dist/shared/translations/locales/sl.js.map +1 -0
  205. package/dist/shared/translations/locales/sv.d.ts +3 -0
  206. package/dist/shared/translations/locales/sv.js +99 -0
  207. package/dist/shared/translations/locales/sv.js.map +1 -0
  208. package/dist/shared/translations/locales/ta.d.ts +3 -0
  209. package/dist/shared/translations/locales/ta.js +99 -0
  210. package/dist/shared/translations/locales/ta.js.map +1 -0
  211. package/dist/shared/translations/locales/th.d.ts +3 -0
  212. package/dist/shared/translations/locales/th.js +99 -0
  213. package/dist/shared/translations/locales/th.js.map +1 -0
  214. package/dist/shared/translations/locales/tr.d.ts +3 -0
  215. package/dist/shared/translations/locales/tr.js +99 -0
  216. package/dist/shared/translations/locales/tr.js.map +1 -0
  217. package/dist/shared/translations/locales/uk.d.ts +3 -0
  218. package/dist/shared/translations/locales/uk.js +99 -0
  219. package/dist/shared/translations/locales/uk.js.map +1 -0
  220. package/dist/shared/translations/locales/vi.d.ts +3 -0
  221. package/dist/shared/translations/locales/vi.js +99 -0
  222. package/dist/shared/translations/locales/vi.js.map +1 -0
  223. package/dist/shared/translations/locales/zh.d.ts +3 -0
  224. package/dist/shared/translations/locales/zh.js +99 -0
  225. package/dist/shared/translations/locales/zh.js.map +1 -0
  226. package/dist/shared/translations/locales/zhTw.d.ts +3 -0
  227. package/dist/shared/translations/locales/zhTw.js +99 -0
  228. package/dist/shared/translations/locales/zhTw.js.map +1 -0
  229. package/dist/shared/translations/types.d.ts +106 -0
  230. package/dist/shared/translations/types.js +1 -0
  231. package/dist/shared/types/index.d.ts +397 -0
  232. package/dist/shared/types/index.js +1 -0
  233. package/dist/{utils.d.ts → shared/utils.d.ts} +1 -0
  234. package/dist/shared/utils.js +13 -0
  235. package/dist/shared/utils.js.map +1 -0
  236. package/package.json +57 -34
  237. package/dist/bin/generateSpec.d.ts +0 -25
  238. package/dist/bin/generateSpec.js +0 -61
  239. package/dist/constants.d.ts +0 -1
  240. package/dist/constants.js +0 -2
  241. package/dist/endpoints/interactiveAuth.js +0 -27
  242. package/dist/endpoints/spec.d.ts +0 -5
  243. package/dist/endpoints/spec.js +0 -39
  244. package/dist/options.d.ts +0 -2
  245. package/dist/options.js +0 -45
  246. package/dist/spec/build.d.ts +0 -14
  247. package/dist/spec/build.js +0 -36
  248. package/dist/spec/buildDocument.d.ts +0 -15
  249. package/dist/spec/buildDocument.js +0 -268
  250. package/dist/spec/components.d.ts +0 -44
  251. package/dist/spec/components.js +0 -265
  252. package/dist/spec/downconvert.js +0 -74
  253. package/dist/spec/entitySchemas.d.ts +0 -15
  254. package/dist/spec/entitySchemas.js +0 -250
  255. package/dist/spec/fields.js +0 -44
  256. package/dist/spec/filters.d.ts +0 -11
  257. package/dist/spec/filters.js +0 -83
  258. package/dist/spec/names.js +0 -37
  259. package/dist/spec/params.d.ts +0 -55
  260. package/dist/spec/params.js +0 -436
  261. package/dist/spec/paths/auth.d.ts +0 -9
  262. package/dist/spec/paths/auth.js +0 -274
  263. package/dist/spec/paths/collections.d.ts +0 -9
  264. package/dist/spec/paths/collections.js +0 -278
  265. package/dist/spec/paths/custom.d.ts +0 -9
  266. package/dist/spec/paths/custom.js +0 -41
  267. package/dist/spec/paths/globals.d.ts +0 -9
  268. package/dist/spec/paths/globals.js +0 -78
  269. package/dist/spec/paths/jobs.d.ts +0 -7
  270. package/dist/spec/paths/jobs.js +0 -130
  271. package/dist/spec/paths/versions.d.ts +0 -19
  272. package/dist/spec/paths/versions.js +0 -252
  273. package/dist/spec/security.d.ts +0 -19
  274. package/dist/spec/security.js +0 -96
  275. package/dist/spec/tags.d.ts +0 -27
  276. package/dist/spec/tags.js +0 -79
  277. package/dist/translations/index.d.ts +0 -6
  278. package/dist/translations/locales/ar.d.ts +0 -2
  279. package/dist/translations/locales/ar.js +0 -81
  280. package/dist/translations/locales/az.d.ts +0 -2
  281. package/dist/translations/locales/az.js +0 -81
  282. package/dist/translations/locales/bg.d.ts +0 -2
  283. package/dist/translations/locales/bg.js +0 -81
  284. package/dist/translations/locales/bnBd.d.ts +0 -2
  285. package/dist/translations/locales/bnBd.js +0 -81
  286. package/dist/translations/locales/bnIn.d.ts +0 -2
  287. package/dist/translations/locales/bnIn.js +0 -81
  288. package/dist/translations/locales/ca.d.ts +0 -2
  289. package/dist/translations/locales/ca.js +0 -81
  290. package/dist/translations/locales/cs.d.ts +0 -2
  291. package/dist/translations/locales/cs.js +0 -81
  292. package/dist/translations/locales/da.d.ts +0 -2
  293. package/dist/translations/locales/da.js +0 -81
  294. package/dist/translations/locales/de.d.ts +0 -2
  295. package/dist/translations/locales/de.js +0 -81
  296. package/dist/translations/locales/en.d.ts +0 -2
  297. package/dist/translations/locales/en.js +0 -81
  298. package/dist/translations/locales/es.d.ts +0 -2
  299. package/dist/translations/locales/es.js +0 -81
  300. package/dist/translations/locales/et.d.ts +0 -2
  301. package/dist/translations/locales/et.js +0 -81
  302. package/dist/translations/locales/fa.d.ts +0 -2
  303. package/dist/translations/locales/fa.js +0 -81
  304. package/dist/translations/locales/fr.d.ts +0 -2
  305. package/dist/translations/locales/fr.js +0 -81
  306. package/dist/translations/locales/he.d.ts +0 -2
  307. package/dist/translations/locales/he.js +0 -81
  308. package/dist/translations/locales/hr.d.ts +0 -2
  309. package/dist/translations/locales/hr.js +0 -81
  310. package/dist/translations/locales/hu.d.ts +0 -2
  311. package/dist/translations/locales/hu.js +0 -81
  312. package/dist/translations/locales/hy.d.ts +0 -2
  313. package/dist/translations/locales/hy.js +0 -81
  314. package/dist/translations/locales/id.d.ts +0 -2
  315. package/dist/translations/locales/id.js +0 -81
  316. package/dist/translations/locales/is.d.ts +0 -2
  317. package/dist/translations/locales/is.js +0 -81
  318. package/dist/translations/locales/it.d.ts +0 -2
  319. package/dist/translations/locales/it.js +0 -81
  320. package/dist/translations/locales/ja.d.ts +0 -2
  321. package/dist/translations/locales/ja.js +0 -81
  322. package/dist/translations/locales/ko.d.ts +0 -2
  323. package/dist/translations/locales/ko.js +0 -81
  324. package/dist/translations/locales/lt.d.ts +0 -2
  325. package/dist/translations/locales/lt.js +0 -81
  326. package/dist/translations/locales/lv.d.ts +0 -2
  327. package/dist/translations/locales/lv.js +0 -81
  328. package/dist/translations/locales/my.d.ts +0 -2
  329. package/dist/translations/locales/my.js +0 -81
  330. package/dist/translations/locales/nb.d.ts +0 -2
  331. package/dist/translations/locales/nb.js +0 -81
  332. package/dist/translations/locales/nl.d.ts +0 -2
  333. package/dist/translations/locales/nl.js +0 -81
  334. package/dist/translations/locales/pl.d.ts +0 -2
  335. package/dist/translations/locales/pl.js +0 -81
  336. package/dist/translations/locales/pt.d.ts +0 -2
  337. package/dist/translations/locales/pt.js +0 -81
  338. package/dist/translations/locales/ro.d.ts +0 -2
  339. package/dist/translations/locales/ro.js +0 -81
  340. package/dist/translations/locales/rs.d.ts +0 -2
  341. package/dist/translations/locales/rs.js +0 -81
  342. package/dist/translations/locales/rsLatin.d.ts +0 -2
  343. package/dist/translations/locales/rsLatin.js +0 -81
  344. package/dist/translations/locales/ru.d.ts +0 -2
  345. package/dist/translations/locales/ru.js +0 -81
  346. package/dist/translations/locales/sk.d.ts +0 -2
  347. package/dist/translations/locales/sk.js +0 -81
  348. package/dist/translations/locales/sl.d.ts +0 -2
  349. package/dist/translations/locales/sl.js +0 -81
  350. package/dist/translations/locales/sv.d.ts +0 -2
  351. package/dist/translations/locales/sv.js +0 -81
  352. package/dist/translations/locales/ta.d.ts +0 -2
  353. package/dist/translations/locales/ta.js +0 -81
  354. package/dist/translations/locales/th.d.ts +0 -2
  355. package/dist/translations/locales/th.js +0 -81
  356. package/dist/translations/locales/tr.d.ts +0 -2
  357. package/dist/translations/locales/tr.js +0 -81
  358. package/dist/translations/locales/uk.d.ts +0 -2
  359. package/dist/translations/locales/uk.js +0 -81
  360. package/dist/translations/locales/vi.d.ts +0 -2
  361. package/dist/translations/locales/vi.js +0 -81
  362. package/dist/translations/locales/zh.d.ts +0 -2
  363. package/dist/translations/locales/zh.js +0 -81
  364. package/dist/translations/locales/zhTw.d.ts +0 -2
  365. package/dist/translations/locales/zhTw.js +0 -81
  366. package/dist/translations/types.d.ts +0 -87
  367. package/dist/translations/types.js +0 -1
  368. package/dist/types.d.ts +0 -192
  369. package/dist/types.js +0 -1
  370. package/dist/ui/createUiPlugin.d.ts +0 -14
  371. package/dist/ui/createUiPlugin.js +0 -28
  372. package/dist/ui/html.js +0 -8
  373. package/dist/ui/scalar.d.ts +0 -1
  374. package/dist/ui/scalar.js +0 -12
  375. package/dist/ui/swagger.d.ts +0 -1
  376. package/dist/ui/swagger.js +0 -12
  377. package/dist/utils.js +0 -13
@@ -0,0 +1,265 @@
1
+ import { refTo } from "./names.js";
2
+ const nullableType = (type) => ({ type: [type, "null"] });
3
+ const jsonResponse = (description, schema) => ({
4
+ description,
5
+ content: { "application/json": { schema } }
6
+ });
7
+ const jsonOk = (description, schema) => ({ "200": jsonResponse(description, schema) });
8
+ const jsonBody = (schema) => ({
9
+ required: true,
10
+ content: { "application/json": { schema } }
11
+ });
12
+ const messageResponse = (description) => jsonOk(description, {
13
+ type: "object",
14
+ properties: { message: { type: "string" } }
15
+ });
16
+ const allowed = () => ({ oneOf: [{
17
+ type: "boolean",
18
+ enum: [true]
19
+ }, {
20
+ type: "object",
21
+ properties: {
22
+ permission: { type: "boolean" },
23
+ where: {
24
+ type: "object",
25
+ additionalProperties: true
26
+ }
27
+ },
28
+ required: ["permission"]
29
+ }] });
30
+ const docAccessOperation = ({ tag, operationId, operations, bodyRef, errors, t }) => ({
31
+ tags: [tag],
32
+ operationId,
33
+ requestBody: {
34
+ description: t("docAccessBody"),
35
+ content: { "application/json": { schema: bodyRef } }
36
+ },
37
+ responses: {
38
+ ...jsonOk(t("docAccess"), {
39
+ type: "object",
40
+ properties: {
41
+ ...Object.fromEntries(operations.map((op) => [op, allowed()])),
42
+ fields: { oneOf: [{
43
+ type: "boolean",
44
+ enum: [true]
45
+ }, {
46
+ type: "object",
47
+ additionalProperties: true
48
+ }] }
49
+ }
50
+ }),
51
+ ...errorResponses(errors, t)
52
+ }
53
+ });
54
+ const validateOperation = ({ tag, operationId, parameters, requestBody, errors, security, t }) => ({
55
+ tags: [tag],
56
+ operationId,
57
+ parameters,
58
+ requestBody: {
59
+ ...requestBody,
60
+ description: [requestBody.description, t("validateBody")].filter(Boolean).join(" ")
61
+ },
62
+ responses: {
63
+ ...jsonOk(t("validateResult"), {
64
+ type: "object",
65
+ properties: {
66
+ valid: { type: "boolean" },
67
+ errors: {
68
+ type: "array",
69
+ items: {
70
+ type: "object",
71
+ properties: {
72
+ message: { type: "string" },
73
+ path: { type: "string" },
74
+ label: { oneOf: [{ type: "string" }, {
75
+ type: "object",
76
+ additionalProperties: { type: "string" }
77
+ }] },
78
+ locale: { type: "string" },
79
+ tableName: { type: "string" }
80
+ },
81
+ required: ["message", "path"]
82
+ }
83
+ }
84
+ },
85
+ required: ["valid", "errors"]
86
+ }),
87
+ ...errorResponses(errors, t)
88
+ },
89
+ security
90
+ });
91
+ const ERROR_SCHEMA_NAME = "ErrorResponse";
92
+ const ERROR_KEYS = {
93
+ "400": "error400",
94
+ "401": "error401",
95
+ "403": "error403",
96
+ "404": "error404",
97
+ "500": "error500"
98
+ };
99
+ const ERRORS = {
100
+ list: [
101
+ "400",
102
+ "403",
103
+ "500"
104
+ ],
105
+ read: [
106
+ "403",
107
+ "404",
108
+ "500"
109
+ ],
110
+ create: [
111
+ "400",
112
+ "403",
113
+ "500"
114
+ ],
115
+ update: [
116
+ "400",
117
+ "403",
118
+ "404",
119
+ "500"
120
+ ],
121
+ delete: [
122
+ "403",
123
+ "404",
124
+ "500"
125
+ ],
126
+ globalRead: ["403", "500"],
127
+ globalUpdate: [
128
+ "400",
129
+ "403",
130
+ "500"
131
+ ],
132
+ login: [
133
+ "400",
134
+ "401",
135
+ "403",
136
+ "500"
137
+ ],
138
+ session: ["401", "500"],
139
+ authAction: [
140
+ "400",
141
+ "403",
142
+ "500"
143
+ ],
144
+ versionList: [
145
+ "400",
146
+ "403",
147
+ "404",
148
+ "500"
149
+ ],
150
+ versionRead: [
151
+ "403",
152
+ "404",
153
+ "500"
154
+ ],
155
+ versionRestore: [
156
+ "403",
157
+ "404",
158
+ "500"
159
+ ]
160
+ };
161
+ const buildErrorResponseSchema = () => ({
162
+ type: "object",
163
+ properties: { errors: {
164
+ type: "array",
165
+ items: {
166
+ type: "object",
167
+ properties: {
168
+ message: { type: "string" },
169
+ name: { type: "string" },
170
+ field: { type: "string" },
171
+ data: {
172
+ type: "object",
173
+ additionalProperties: true
174
+ }
175
+ },
176
+ required: ["message"]
177
+ }
178
+ } },
179
+ required: ["errors"]
180
+ });
181
+ const errorRef = { $ref: refTo(ERROR_SCHEMA_NAME) };
182
+ const errorContent = (description) => ({
183
+ description,
184
+ content: { "application/json": { schema: errorRef } }
185
+ });
186
+ const errorResponses = (codes, t) => {
187
+ const responses = {};
188
+ for (const code of codes) responses[code] = errorContent(t(ERROR_KEYS[code]));
189
+ return responses;
190
+ };
191
+ const buildListEnvelopeSchema = (base) => ({
192
+ type: "object",
193
+ properties: {
194
+ docs: {
195
+ type: "array",
196
+ items: { $ref: refTo(base) }
197
+ },
198
+ totalDocs: { type: "integer" },
199
+ limit: { type: "integer" },
200
+ totalPages: { type: "integer" },
201
+ page: { type: "integer" },
202
+ pagingCounter: { type: "integer" },
203
+ hasPrevPage: { type: "boolean" },
204
+ hasNextPage: { type: "boolean" },
205
+ prevPage: nullableType("integer"),
206
+ nextPage: nullableType("integer")
207
+ },
208
+ required: [
209
+ "docs",
210
+ "totalDocs",
211
+ "limit",
212
+ "totalPages",
213
+ "page"
214
+ ]
215
+ });
216
+ const uploadRequestBody = ({ bodyRef, fileRequired, t }) => {
217
+ const fieldsSchemaName = bodyRef.$ref.split("/").pop() ?? "the document";
218
+ return {
219
+ required: fileRequired,
220
+ description: t("uploadBody"),
221
+ content: {
222
+ "multipart/form-data": {
223
+ schema: {
224
+ type: "object",
225
+ properties: {
226
+ file: {
227
+ type: "string",
228
+ format: "binary",
229
+ description: t("uploadFile")
230
+ },
231
+ _payload: {
232
+ allOf: [bodyRef],
233
+ description: t("uploadPayloadField", { schema: fieldsSchemaName })
234
+ }
235
+ },
236
+ ...fileRequired ? { required: ["file"] } : {}
237
+ },
238
+ encoding: {
239
+ file: { contentType: "application/octet-stream" },
240
+ _payload: { contentType: "application/json" }
241
+ }
242
+ },
243
+ "application/json": { schema: bodyRef }
244
+ }
245
+ };
246
+ };
247
+ const SECURITY_SCHEME_NAME = "PayloadToken";
248
+ const INTERACTIVE_SCHEME_NAME = "PayloadLogin";
249
+ const interactiveSecurityScheme = ({ tokenUrl, t }) => ({
250
+ type: "oauth2",
251
+ description: t("securityInteractive"),
252
+ flows: { password: {
253
+ tokenUrl,
254
+ scopes: {}
255
+ } }
256
+ });
257
+ const securityScheme = ({ cookiePrefix, t }) => ({
258
+ type: "http",
259
+ scheme: "bearer",
260
+ bearerFormat: "JWT",
261
+ description: t("securityBearer", { cookiePrefix })
262
+ });
263
+ export { ERRORS, ERROR_SCHEMA_NAME, INTERACTIVE_SCHEME_NAME, SECURITY_SCHEME_NAME, buildErrorResponseSchema, buildListEnvelopeSchema, docAccessOperation, errorResponses, interactiveSecurityScheme, jsonBody, jsonOk, jsonResponse, messageResponse, nullableType, securityScheme, uploadRequestBody, validateOperation };
264
+
265
+ //# sourceMappingURL=components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.js","names":[],"sources":["../../../src/server/spec/components.ts"],"sourcesContent":["import type {\n OperationObject,\n ParameterObject,\n ReferenceObject,\n RequestBodyObject,\n ResponseObject,\n ResponsesObject,\n SchemaObject,\n SecurityRequirementObject,\n SecuritySchemeObject,\n} from '@scalar/openapi-types/3.2'\n\nimport type { Translate } from '@/shared/translations/types.js'\n\nimport { refTo } from './names.js'\n\ntype SchemaOrRef = SchemaObject | ReferenceObject\n\nexport const nullableType = (type: 'integer' | 'string' | 'number' | 'boolean'): SchemaObject => ({\n type: [type, 'null'],\n})\n\nexport const jsonResponse = (description: string, schema: SchemaOrRef): ResponseObject => ({\n description,\n content: { 'application/json': { schema } },\n})\n\nexport const jsonOk = (description: string, schema: SchemaOrRef): ResponsesObject => ({\n '200': jsonResponse(description, schema),\n})\n\nexport const jsonBody = (schema: SchemaOrRef): RequestBodyObject => ({\n required: true,\n content: { 'application/json': { schema } },\n})\n\nexport const messageResponse = (description: string): ResponsesObject =>\n jsonOk(description, { type: 'object', properties: { message: { type: 'string' } } })\n\nexport type ErrorCode = '400' | '401' | '403' | '404' | '500'\n\nconst allowed = (): SchemaObject => ({\n oneOf: [\n { type: 'boolean', enum: [true] },\n {\n type: 'object',\n properties: { permission: { type: 'boolean' }, where: { type: 'object', additionalProperties: true } },\n required: ['permission'],\n },\n ],\n})\n\nexport const docAccessOperation = ({\n tag,\n operationId,\n operations,\n bodyRef,\n errors,\n t,\n}: {\n tag: string\n operationId: string\n operations: string[]\n bodyRef: ReferenceObject\n errors: ErrorCode[]\n t: Translate\n}): OperationObject => ({\n tags: [tag],\n operationId,\n requestBody: { description: t('docAccessBody'), content: { 'application/json': { schema: bodyRef } } },\n responses: {\n ...jsonOk(t('docAccess'), {\n type: 'object',\n properties: {\n ...Object.fromEntries(operations.map((op) => [op, allowed()])),\n fields: {\n oneOf: [\n { type: 'boolean', enum: [true] },\n { type: 'object', additionalProperties: true },\n ],\n },\n },\n }),\n ...errorResponses(errors, t),\n },\n})\n\nexport const validateOperation = ({\n tag,\n operationId,\n parameters,\n requestBody,\n errors,\n security,\n t,\n}: {\n tag: string\n operationId: string\n parameters: ParameterObject[]\n requestBody: RequestBodyObject\n errors: ErrorCode[]\n security?: SecurityRequirementObject[]\n t: Translate\n}): OperationObject => ({\n tags: [tag],\n operationId,\n parameters,\n requestBody: {\n ...requestBody,\n description: [requestBody.description, t('validateBody')].filter(Boolean).join(' '),\n },\n responses: {\n ...jsonOk(t('validateResult'), {\n type: 'object',\n properties: {\n valid: { type: 'boolean' },\n errors: {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n message: { type: 'string' },\n path: { type: 'string' },\n label: { oneOf: [{ type: 'string' }, { type: 'object', additionalProperties: { type: 'string' } }] },\n locale: { type: 'string' },\n tableName: { type: 'string' },\n },\n required: ['message', 'path'],\n },\n },\n },\n required: ['valid', 'errors'],\n }),\n ...errorResponses(errors, t),\n },\n security,\n})\n\nexport const ERROR_SCHEMA_NAME = 'ErrorResponse'\n\nconst ERROR_KEYS = {\n '400': 'error400',\n '401': 'error401',\n '403': 'error403',\n '404': 'error404',\n '500': 'error500',\n} as const\n\nexport const ERRORS = {\n list: ['400', '403', '500'] as ErrorCode[],\n read: ['403', '404', '500'] as ErrorCode[],\n create: ['400', '403', '500'] as ErrorCode[],\n update: ['400', '403', '404', '500'] as ErrorCode[],\n delete: ['403', '404', '500'] as ErrorCode[],\n globalRead: ['403', '500'] as ErrorCode[],\n globalUpdate: ['400', '403', '500'] as ErrorCode[],\n login: ['400', '401', '403', '500'] as ErrorCode[],\n session: ['401', '500'] as ErrorCode[],\n authAction: ['400', '403', '500'] as ErrorCode[],\n versionList: ['400', '403', '404', '500'] as ErrorCode[],\n versionRead: ['403', '404', '500'] as ErrorCode[],\n versionRestore: ['403', '404', '500'] as ErrorCode[],\n} as const\n\nexport const buildErrorResponseSchema = (): SchemaObject => ({\n type: 'object',\n properties: {\n errors: {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n message: { type: 'string' },\n name: { type: 'string' },\n field: { type: 'string' },\n data: { type: 'object', additionalProperties: true },\n },\n required: ['message'],\n },\n },\n },\n required: ['errors'],\n})\n\nconst errorRef: ReferenceObject = { $ref: refTo(ERROR_SCHEMA_NAME) }\n\nconst errorContent = (description: string): ResponseObject => ({\n description,\n content: { 'application/json': { schema: errorRef } },\n})\n\nexport const errorResponses = (codes: ErrorCode[], t: Translate): ResponsesObject => {\n const responses: ResponsesObject = {}\n for (const code of codes) responses[code] = errorContent(t(ERROR_KEYS[code]))\n return responses\n}\n\nexport const buildListEnvelopeSchema = (base: string): SchemaObject => ({\n type: 'object',\n properties: {\n docs: { type: 'array', items: { $ref: refTo(base) } },\n totalDocs: { type: 'integer' },\n limit: { type: 'integer' },\n totalPages: { type: 'integer' },\n page: { type: 'integer' },\n pagingCounter: { type: 'integer' },\n hasPrevPage: { type: 'boolean' },\n hasNextPage: { type: 'boolean' },\n prevPage: nullableType('integer'),\n nextPage: nullableType('integer'),\n },\n required: ['docs', 'totalDocs', 'limit', 'totalPages', 'page'],\n})\n\nexport const uploadRequestBody = ({\n bodyRef,\n fileRequired,\n t,\n}: {\n bodyRef: ReferenceObject\n fileRequired: boolean\n t: Translate\n}): RequestBodyObject => {\n const fieldsSchemaName = bodyRef.$ref.split('/').pop() ?? 'the document'\n return {\n required: fileRequired,\n description: t('uploadBody'),\n content: {\n 'multipart/form-data': {\n schema: {\n type: 'object',\n properties: {\n file: {\n type: 'string',\n format: 'binary',\n description: t('uploadFile'),\n },\n _payload: {\n allOf: [bodyRef],\n description: t('uploadPayloadField', { schema: fieldsSchemaName }),\n },\n },\n ...(fileRequired ? { required: ['file'] } : {}),\n },\n encoding: {\n file: { contentType: 'application/octet-stream' },\n _payload: { contentType: 'application/json' },\n },\n },\n 'application/json': { schema: bodyRef },\n },\n }\n}\n\nexport const SECURITY_SCHEME_NAME = 'PayloadToken'\nexport const INTERACTIVE_SCHEME_NAME = 'PayloadLogin'\n\nexport const interactiveSecurityScheme = ({\n tokenUrl,\n t,\n}: {\n tokenUrl: string\n t: Translate\n}): SecuritySchemeObject => ({\n type: 'oauth2',\n description: t('securityInteractive'),\n flows: { password: { tokenUrl, scopes: {} } },\n})\n\nexport const securityScheme = ({ cookiePrefix, t }: { cookiePrefix: string; t: Translate }): SecuritySchemeObject => ({\n type: 'http',\n scheme: 'bearer',\n bearerFormat: 'JWT',\n description: t('securityBearer', { cookiePrefix }),\n})\n"],"mappings":";AAkBA,MAAa,gBAAgB,UAAqE,EAChG,MAAM,CAAC,MAAM,MAAM,EACrB;AAEA,MAAa,gBAAgB,aAAqB,YAAyC;CACzF;CACA,SAAS,EAAE,oBAAoB,EAAE,OAAO,EAAE;AAC5C;AAEA,MAAa,UAAU,aAAqB,YAA0C,EACpF,OAAO,aAAa,aAAa,MAAM,EACzC;AAEA,MAAa,YAAY,YAA4C;CACnE,UAAU;CACV,SAAS,EAAE,oBAAoB,EAAE,OAAO,EAAE;AAC5C;AAEA,MAAa,mBAAmB,gBAC9B,OAAO,aAAa;CAAE,MAAM;CAAU,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,EAAE;AAAE,CAAC;AAIrF,MAAM,iBAA+B,EACnC,OAAO,CACL;CAAE,MAAM;CAAW,MAAM,CAAC,IAAI;AAAE,GAChC;CACE,MAAM;CACN,YAAY;EAAE,YAAY,EAAE,MAAM,UAAU;EAAG,OAAO;GAAE,MAAM;GAAU,sBAAsB;EAAK;CAAE;CACrG,UAAU,CAAC,YAAY;AACzB,CACF,EACF;AAEA,MAAa,sBAAsB,EACjC,KACA,aACA,YACA,SACA,QACA,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H,MAAM;CACN,QAAQ;CACR,cAAc;CACd,aAAa,EAAE,kBAAkB,EAAE,aAAa,CAAC;AACnD"}
@@ -1,3 +1,4 @@
1
- import type { Document } from '@scalar/openapi-types/3.2';
1
+ import { Document } from "@scalar/openapi-types/3.2";
2
2
  export declare const toOpenApi31: (doc: Document) => Document;
3
3
  export declare const toOpenApi30: (doc: Document) => Document;
4
+ //# sourceMappingURL=downconvert.d.ts.map
@@ -0,0 +1,69 @@
1
+ const NULL = "null";
2
+ const UNSUPPORTED_KEYWORDS = [
3
+ "$schema",
4
+ "$id",
5
+ "$comment",
6
+ "unevaluatedProperties",
7
+ "patternProperties",
8
+ "propertyNames"
9
+ ];
10
+ const isStringType = (type) => type === "string" || Array.isArray(type) && type.includes("string");
11
+ const downconvertTo30 = (node) => {
12
+ if (Array.isArray(node)) return node.map(downconvertTo30);
13
+ if (!node || typeof node !== "object") return node;
14
+ const out = {};
15
+ for (const [key, value] of Object.entries(node)) out[key] = downconvertTo30(value);
16
+ if (isStringType(out.type) && out.contentMediaType === "application/octet-stream") {
17
+ if (out.format === void 0) out.format = "binary";
18
+ delete out.contentMediaType;
19
+ }
20
+ if (isStringType(out.type) && out.contentEncoding === "base64") {
21
+ if (out.format === void 0) out.format = "byte";
22
+ delete out.contentEncoding;
23
+ }
24
+ if (Array.isArray(out.type)) {
25
+ const types = out.type;
26
+ const nullable = types.includes(NULL);
27
+ const rest = types.filter((t) => t !== NULL);
28
+ if (rest.length === 1) {
29
+ out.type = rest[0];
30
+ if (nullable) out.nullable = true;
31
+ } else if (rest.length > 1) {
32
+ delete out.type;
33
+ const union = rest.map((type) => nullable ? {
34
+ type,
35
+ nullable: true
36
+ } : { type });
37
+ if (out.anyOf) out.allOf = [...out.allOf ?? [], { anyOf: union }];
38
+ else out.anyOf = union;
39
+ }
40
+ }
41
+ if ("const" in out) {
42
+ out.enum = [out.const];
43
+ delete out.const;
44
+ }
45
+ if (Array.isArray(out.examples)) {
46
+ const examples = out.examples;
47
+ if (examples.length > 0) out.example = examples[0];
48
+ if (examples.length > 1) out["x-examples"] = examples;
49
+ delete out.examples;
50
+ }
51
+ if (Array.isArray(out.required) && out.required.length === 0) delete out.required;
52
+ for (const keyword of UNSUPPORTED_KEYWORDS) delete out[keyword];
53
+ return out;
54
+ };
55
+ const toOpenApi31 = (doc) => ({
56
+ ...doc,
57
+ openapi: "3.1.2",
58
+ tags: doc.tags?.map(({ kind: _kind, parent: _parent, summary: _summary, ...rest }) => rest)
59
+ });
60
+ const toOpenApi30 = (doc) => {
61
+ const converted = downconvertTo30(toOpenApi31(doc));
62
+ converted.openapi = "3.0.4";
63
+ delete converted.info.summary;
64
+ delete converted.info.license?.identifier;
65
+ return converted;
66
+ };
67
+ export { toOpenApi30, toOpenApi31 };
68
+
69
+ //# sourceMappingURL=downconvert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"downconvert.js","names":[],"sources":["../../../src/server/spec/downconvert.ts"],"sourcesContent":["import type { Document, TagObject } from '@scalar/openapi-types/3.2'\n\nconst NULL = 'null'\n\nconst UNSUPPORTED_KEYWORDS = [\n '$schema',\n '$id',\n '$comment',\n 'unevaluatedProperties',\n 'patternProperties',\n 'propertyNames',\n]\n\nconst isStringType = (type: unknown): boolean => type === 'string' || (Array.isArray(type) && type.includes('string'))\n\nconst downconvertTo30 = (node: unknown): unknown => {\n if (Array.isArray(node)) return node.map(downconvertTo30)\n if (!node || typeof node !== 'object') return node\n\n const out: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(node as Record<string, unknown>)) {\n out[key] = downconvertTo30(value)\n }\n\n if (isStringType(out.type) && out.contentMediaType === 'application/octet-stream') {\n if (out.format === undefined) out.format = 'binary'\n delete out.contentMediaType\n }\n if (isStringType(out.type) && out.contentEncoding === 'base64') {\n if (out.format === undefined) out.format = 'byte'\n delete out.contentEncoding\n }\n\n if (Array.isArray(out.type)) {\n const types = out.type as string[]\n const nullable = types.includes(NULL)\n const rest = types.filter((t) => t !== NULL)\n if (rest.length === 1) {\n out.type = rest[0]\n if (nullable) out.nullable = true\n } else if (rest.length > 1) {\n delete out.type\n const union = rest.map((type) => (nullable ? { type, nullable: true } : { type }))\n if (out.anyOf) out.allOf = [...((out.allOf as unknown[]) ?? []), { anyOf: union }]\n else out.anyOf = union\n }\n }\n\n if ('const' in out) {\n out.enum = [out.const]\n delete out.const\n }\n\n if (Array.isArray(out.examples)) {\n const examples = out.examples\n if (examples.length > 0) out.example = examples[0]\n if (examples.length > 1) out['x-examples'] = examples\n delete out.examples\n }\n\n if (Array.isArray(out.required) && out.required.length === 0) delete out.required\n\n for (const keyword of UNSUPPORTED_KEYWORDS) delete out[keyword]\n\n return out\n}\n\nexport const toOpenApi31 = (doc: Document): Document => ({\n ...doc,\n openapi: '3.1.2',\n tags: doc.tags?.map(({ kind: _kind, parent: _parent, summary: _summary, ...rest }: TagObject) => rest),\n})\n\nexport const toOpenApi30 = (doc: Document): Document => {\n const converted = downconvertTo30(toOpenApi31(doc)) as Document\n converted.openapi = '3.0.4'\n delete converted.info.summary\n delete converted.info.license?.identifier\n return converted\n}\n"],"mappings":"AAEA,MAAM,OAAO;AAEb,MAAM,uBAAuB;CAC3B;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,gBAAgB,SAA2B,SAAS,YAAa,MAAM,QAAQ,IAAI,KAAK,KAAK,SAAS,QAAQ;AAEpH,MAAM,mBAAmB,SAA2B;CAClD,IAAI,MAAM,QAAQ,IAAI,GAAG,OAAO,KAAK,IAAI,eAAe;CACxD,IAAI,CAAC,QAAQ,OAAO,SAAS,UAAU,OAAO;CAE9C,MAAM,MAA+B,CAAC;CACtC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,IAA+B,GACvE,IAAI,OAAO,gBAAgB,KAAK;CAGlC,IAAI,aAAa,IAAI,IAAI,KAAK,IAAI,qBAAqB,4BAA4B;EACjF,IAAI,IAAI,WAAW,KAAA,GAAW,IAAI,SAAS;EAC3C,OAAO,IAAI;CACb;CACA,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MAAM,YAAY,gBAAgB,YAAY,GAAG,CAAC;CAClD,UAAU,UAAU;CACpB,OAAO,UAAU,KAAK;CACtB,OAAO,UAAU,KAAK,SAAS;CAC/B,OAAO;AACT"}
@@ -0,0 +1,16 @@
1
+ import { BuildContext, Entity } from "../../shared/types/index.js";
2
+ import { Block, SanitizedConfig } from "payload";
3
+ import { SchemaObject } from "@scalar/openapi-types/3.2";
4
+ export declare const resolveLocalizedStrings: (value: unknown, ctx: BuildContext) => unknown;
5
+ export interface EntitySchemas {
6
+ read: SchemaObject;
7
+ create: SchemaObject;
8
+ update: SchemaObject;
9
+ }
10
+ export declare const buildEntitySchemas: ({ entity, config, ctx }: {
11
+ entity: Entity;
12
+ config: SanitizedConfig;
13
+ ctx: BuildContext;
14
+ }) => Promise<EntitySchemas>;
15
+ export declare const buildBlockSchema: (block: Block, config: SanitizedConfig) => SchemaObject;
16
+ //# sourceMappingURL=entitySchemas.d.ts.map
@@ -0,0 +1,207 @@
1
+ import { deepMerge, isPlainObject } from "../../shared/utils.js";
2
+ import { rewriteRefs } from "./names.js";
3
+ import { makeT } from "../../shared/translations/index.js";
4
+ import { AUTH_FIELDS, flattenFields } from "./fields.js";
5
+ import { entityToJSONSchema } from "payload";
6
+ import { getTranslation } from "@payloadcms/translations";
7
+ const READ_HIDDEN_FIELDS = /* @__PURE__ */ new Set([...AUTH_FIELDS, "collection"]);
8
+ const stripInterfaceName = (entity) => {
9
+ const { interfaceName: _omit, ...rest } = entity;
10
+ return rest;
11
+ };
12
+ const toComponentSchema = ({ config, source, idType, defs = /* @__PURE__ */ new Map(), variant }) => {
13
+ const jsonSchema = entityToJSONSchema(config, source, defs, idType, /* @__PURE__ */ new Set(), void 0, void 0, void 0, variant);
14
+ const blockSlugs = new Set((config.blocks ?? []).map((b) => b.slug));
15
+ const schema = rewriteRefs(jsonSchema, blockSlugs, defs);
16
+ delete schema.title;
17
+ return schema;
18
+ };
19
+ const fieldOpenapi = (field) => {
20
+ const meta = field.custom?.openapi;
21
+ return isPlainObject(meta) ? meta : void 0;
22
+ };
23
+ const isLocaleKeyed = (value, ctx) => {
24
+ if (!isPlainObject(value)) return false;
25
+ const keys = Object.keys(value);
26
+ return keys.length > 0 && keys.every((k) => ctx.locales.includes(k)) && Object.values(value).every((v) => typeof v === "string");
27
+ };
28
+ const LOCALIZABLE_KEYS = /* @__PURE__ */ new Set([
29
+ "description",
30
+ "title",
31
+ "summary"
32
+ ]);
33
+ const resolveTextValue = (value, ctx) => {
34
+ if (typeof value === "function") try {
35
+ const result = value({
36
+ t: ctx.i18n.t,
37
+ i18n: ctx.i18n
38
+ });
39
+ return typeof result === "string" && result.length > 0 ? result : void 0;
40
+ } catch {
41
+ return;
42
+ }
43
+ if (isLocaleKeyed(value, ctx)) return getTranslation(value, ctx.i18n);
44
+ };
45
+ const resolveLocalizedStrings = (value, ctx) => {
46
+ if (!isPlainObject(value)) return value;
47
+ const out = {};
48
+ for (const [k, v] of Object.entries(value)) {
49
+ if (LOCALIZABLE_KEYS.has(k)) {
50
+ const resolved = resolveTextValue(v, ctx);
51
+ if (resolved !== void 0) out[k] = resolved;
52
+ else if (typeof v !== "function") out[k] = resolveLocalizedStrings(v, ctx);
53
+ continue;
54
+ }
55
+ out[k] = resolveLocalizedStrings(v, ctx);
56
+ }
57
+ return out;
58
+ };
59
+ const applyFieldOverrides = ({ schema, fields, ctx }) => {
60
+ if (!schema.properties) return;
61
+ for (const field of flattenFields(fields)) {
62
+ const name = "name" in field ? field.name : void 0;
63
+ const override = fieldOpenapi(field);
64
+ if (!name || !override) continue;
65
+ const current = schema.properties[name];
66
+ if (isPlainObject(current)) {
67
+ const resolved = resolveLocalizedStrings(override, ctx);
68
+ schema.properties[name] = deepMerge(current, resolved);
69
+ }
70
+ }
71
+ };
72
+ const isRef = (value) => isPlainObject(value) && typeof value.$ref === "string";
73
+ const isBlockBranch = (branch) => {
74
+ if (isRef(branch)) return branch.$ref.startsWith("#/components/schemas/Block");
75
+ return isPlainObject(branch) && isPlainObject(branch.properties) && "blockType" in branch.properties;
76
+ };
77
+ const addBlockDiscriminators = (node) => {
78
+ if (Array.isArray(node)) {
79
+ for (const item of node) addBlockDiscriminators(item);
80
+ return;
81
+ }
82
+ if (!isPlainObject(node)) return;
83
+ const oneOf = node.oneOf;
84
+ if (Array.isArray(oneOf) && oneOf.length > 0 && oneOf.every(isBlockBranch)) node.discriminator = { propertyName: "blockType" };
85
+ for (const value of Object.values(node)) addBlockDiscriminators(value);
86
+ };
87
+ const fixPolymorphicJoinRequired = (node) => {
88
+ if (Array.isArray(node)) {
89
+ for (const item of node) fixPolymorphicJoinRequired(item);
90
+ return;
91
+ }
92
+ if (!isPlainObject(node)) return;
93
+ const { properties, required } = node;
94
+ if (isPlainObject(properties) && "relationTo" in properties && Array.isArray(required)) node.required = required.map((r) => r === "collectionSlug" ? "relationTo" : r);
95
+ for (const value of Object.values(node)) fixPolymorphicJoinRequired(value);
96
+ };
97
+ const markLocalizedFields = ({ schema, fields, ctx }) => {
98
+ if (!schema.properties || ctx.locales.length === 0) return;
99
+ for (const field of flattenFields(fields)) {
100
+ if (!("localized" in field) || !field.localized) continue;
101
+ const name = "name" in field ? field.name : void 0;
102
+ if (!name || !(name in schema.properties)) continue;
103
+ const single = schema.properties[name];
104
+ schema.properties[name] = { oneOf: [single, {
105
+ type: "object",
106
+ description: makeT(ctx.i18n)("schemaPerLocale"),
107
+ properties: Object.fromEntries(ctx.locales.map((l) => [l, single]))
108
+ }] };
109
+ }
110
+ };
111
+ const removeProps = (schema, names) => {
112
+ if (!schema.properties) return;
113
+ for (const name of names) delete schema.properties[name];
114
+ if (Array.isArray(schema.required)) {
115
+ const drop = new Set(names);
116
+ schema.required = schema.required.filter((r) => !drop.has(r));
117
+ }
118
+ };
119
+ const isConstantDeny = (access) => {
120
+ if (typeof access !== "function" || access.length > 0) return false;
121
+ try {
122
+ return access() === false;
123
+ } catch {
124
+ return false;
125
+ }
126
+ };
127
+ const deniedWrites = (fields, operation) => flattenFields(fields).filter((field) => "name" in field && "access" in field && isConstantDeny(field.access?.[operation])).map((field) => field.name);
128
+ const cloneSchema = (schema) => ({
129
+ ...schema,
130
+ properties: { ...schema.properties },
131
+ required: Array.isArray(schema.required) ? [...schema.required] : schema.required
132
+ });
133
+ const buildEntitySchemas = async ({ entity, config, ctx }) => {
134
+ const source = stripInterfaceName(entity);
135
+ const defs = /* @__PURE__ */ new Map();
136
+ const idType = ctx.defaultIDType;
137
+ const read = toComponentSchema({
138
+ config,
139
+ source,
140
+ idType,
141
+ defs
142
+ });
143
+ const write = toComponentSchema({
144
+ config,
145
+ source,
146
+ idType,
147
+ defs,
148
+ variant: "input"
149
+ });
150
+ const isAuth = "auth" in entity && Boolean(entity.auth);
151
+ for (const schema of [read, write]) {
152
+ if (isAuth) removeProps(schema, READ_HIDDEN_FIELDS);
153
+ applyFieldOverrides({
154
+ schema,
155
+ fields: entity.fields,
156
+ ctx
157
+ });
158
+ addBlockDiscriminators(schema);
159
+ }
160
+ fixPolymorphicJoinRequired(read);
161
+ const create = cloneSchema(write);
162
+ if (isAuth && create.properties) {
163
+ create.properties.password = { type: "string" };
164
+ create.required = [.../* @__PURE__ */ new Set([...create.required ?? [], "password"])];
165
+ }
166
+ removeProps(create, deniedWrites(entity.fields, "create"));
167
+ const update = cloneSchema(write);
168
+ removeProps(update, deniedWrites(entity.fields, "update"));
169
+ delete update.required;
170
+ if (update.properties) delete update.properties.id;
171
+ if (isAuth && update.properties) update.properties.password = { type: "string" };
172
+ markLocalizedFields({
173
+ schema: read,
174
+ fields: entity.fields,
175
+ ctx
176
+ });
177
+ return {
178
+ read,
179
+ create,
180
+ update
181
+ };
182
+ };
183
+ const buildBlockSchema = (block, config) => {
184
+ const schema = toComponentSchema({
185
+ config,
186
+ source: stripInterfaceName(block),
187
+ idType: "text"
188
+ });
189
+ const blockType = {
190
+ type: "string",
191
+ enum: [block.slug]
192
+ };
193
+ const properties = {
194
+ ...schema.properties,
195
+ blockType
196
+ };
197
+ const required = [.../* @__PURE__ */ new Set(["blockType", ...schema.required ?? []])];
198
+ return {
199
+ ...schema,
200
+ type: "object",
201
+ properties,
202
+ required
203
+ };
204
+ };
205
+ export { buildBlockSchema, buildEntitySchemas, resolveLocalizedStrings };
206
+
207
+ //# sourceMappingURL=entitySchemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entitySchemas.js","names":[],"sources":["../../../src/server/spec/entitySchemas.ts"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations'\nimport type { SchemaObject } from '@scalar/openapi-types/3.2'\nimport { entityToJSONSchema } from 'payload'\nimport type { Block, Field, SanitizedConfig, SchemaVariant } from 'payload'\n\nimport { makeT } from '@/shared/translations/index.js'\nimport type { BuildContext, Entity, IDType } from '@/shared/types/index.js'\nimport { deepMerge, isPlainObject } from '@/shared/utils.js'\n\nimport { AUTH_FIELDS, flattenFields } from './fields.js'\nimport { rewriteRefs } from './names.js'\n\nconst READ_HIDDEN_FIELDS = new Set<string>([...AUTH_FIELDS, 'collection'])\n\nconst stripInterfaceName = <T>(entity: T): T => {\n const { interfaceName: _omit, ...rest } = entity as T & { interfaceName?: string }\n return rest as T\n}\n\nconst toComponentSchema = ({\n config,\n source,\n idType,\n defs = new Map(),\n variant,\n}: {\n config: SanitizedConfig\n source: Entity | Block\n idType: IDType\n defs?: Map<string, unknown>\n variant?: SchemaVariant\n}): SchemaObject => {\n const jsonSchema = entityToJSONSchema(\n config,\n source as never,\n defs as never,\n idType,\n new Set(),\n undefined,\n undefined,\n undefined,\n variant,\n )\n const blockSlugs = new Set((config.blocks ?? []).map((b) => b.slug))\n const schema = rewriteRefs(jsonSchema as never, blockSlugs, defs) as unknown as SchemaObject\n delete schema.title\n return schema\n}\n\nconst fieldOpenapi = (field: Field): Record<string, unknown> | undefined => {\n const meta = (field as { custom?: { openapi?: unknown } }).custom?.openapi\n return isPlainObject(meta) ? meta : undefined\n}\n\nconst isLocaleKeyed = (value: unknown, ctx: BuildContext): value is Record<string, string> => {\n if (!isPlainObject(value)) return false\n const keys = Object.keys(value)\n return (\n keys.length > 0 &&\n keys.every((k) => ctx.locales.includes(k)) &&\n Object.values(value).every((v) => typeof v === 'string')\n )\n}\n\nconst LOCALIZABLE_KEYS = new Set(['description', 'title', 'summary'])\n\nconst resolveTextValue = (value: unknown, ctx: BuildContext): string | undefined => {\n if (typeof value === 'function') {\n try {\n const result = (value as (args: { t: unknown; i18n: unknown }) => unknown)({ t: ctx.i18n.t, i18n: ctx.i18n })\n return typeof result === 'string' && result.length > 0 ? result : undefined\n } catch {\n return undefined\n }\n }\n if (isLocaleKeyed(value, ctx)) return getTranslation(value, ctx.i18n)\n return undefined\n}\n\nexport const resolveLocalizedStrings = (value: unknown, ctx: BuildContext): unknown => {\n if (!isPlainObject(value)) return value\n const out: Record<string, unknown> = {}\n for (const [k, v] of Object.entries(value)) {\n if (LOCALIZABLE_KEYS.has(k)) {\n const resolved = resolveTextValue(v, ctx)\n if (resolved !== undefined) out[k] = resolved\n else if (typeof v !== 'function') out[k] = resolveLocalizedStrings(v, ctx)\n continue\n }\n out[k] = resolveLocalizedStrings(v, ctx)\n }\n return out\n}\n\nconst applyFieldOverrides = ({\n schema,\n fields,\n ctx,\n}: {\n schema: SchemaObject\n fields: Field[]\n ctx: BuildContext\n}): void => {\n if (!schema.properties) return\n for (const field of flattenFields(fields)) {\n const name = 'name' in field ? field.name : undefined\n const override = fieldOpenapi(field)\n if (!name || !override) continue\n const current = schema.properties[name]\n if (isPlainObject(current)) {\n const resolved = resolveLocalizedStrings(override, ctx) as Record<string, unknown>\n schema.properties[name] = deepMerge(current, resolved) as SchemaObject\n }\n }\n}\n\nconst isRef = (value: unknown): value is { $ref: string } => isPlainObject(value) && typeof value.$ref === 'string'\n\nconst isBlockBranch = (branch: unknown): boolean => {\n if (isRef(branch)) return branch.$ref.startsWith('#/components/schemas/Block')\n return isPlainObject(branch) && isPlainObject(branch.properties) && 'blockType' in branch.properties\n}\n\nconst addBlockDiscriminators = (node: unknown): void => {\n if (Array.isArray(node)) {\n for (const item of node) addBlockDiscriminators(item)\n return\n }\n if (!isPlainObject(node)) return\n const oneOf = node.oneOf\n if (Array.isArray(oneOf) && oneOf.length > 0 && oneOf.every(isBlockBranch)) {\n ;(node as SchemaObject).discriminator = { propertyName: 'blockType' }\n }\n for (const value of Object.values(node)) addBlockDiscriminators(value)\n}\n\nconst fixPolymorphicJoinRequired = (node: unknown): void => {\n if (Array.isArray(node)) {\n for (const item of node) fixPolymorphicJoinRequired(item)\n return\n }\n if (!isPlainObject(node)) return\n const { properties, required } = node as SchemaObject\n if (isPlainObject(properties) && 'relationTo' in properties && Array.isArray(required)) {\n ;(node as SchemaObject).required = required.map((r: string) => (r === 'collectionSlug' ? 'relationTo' : r))\n }\n for (const value of Object.values(node)) fixPolymorphicJoinRequired(value)\n}\n\nconst markLocalizedFields = ({\n schema,\n fields,\n ctx,\n}: {\n schema: SchemaObject\n fields: Field[]\n ctx: BuildContext\n}): void => {\n if (!schema.properties || ctx.locales.length === 0) return\n for (const field of flattenFields(fields)) {\n if (!('localized' in field) || !field.localized) continue\n const name = 'name' in field ? field.name : undefined\n if (!name || !(name in schema.properties)) continue\n const single = schema.properties[name] as SchemaObject\n schema.properties[name] = {\n oneOf: [\n single,\n {\n type: 'object',\n description: makeT(ctx.i18n)('schemaPerLocale'),\n properties: Object.fromEntries(ctx.locales.map((l) => [l, single])),\n },\n ],\n }\n }\n}\n\nconst removeProps = (schema: SchemaObject, names: Iterable<string>): void => {\n if (!schema.properties) return\n for (const name of names) delete schema.properties[name]\n if (Array.isArray(schema.required)) {\n const drop = new Set(names)\n schema.required = schema.required.filter((r: string) => !drop.has(r))\n }\n}\n\nconst isConstantDeny = (access: unknown): boolean => {\n if (typeof access !== 'function' || access.length > 0) return false\n try {\n return access() === false\n } catch {\n return false\n }\n}\n\nconst deniedWrites = (fields: Field[], operation: 'create' | 'update'): string[] =>\n flattenFields(fields)\n .filter((field) => 'name' in field && 'access' in field && isConstantDeny(field.access?.[operation]))\n .map((field) => (field as { name: string }).name)\n\nconst cloneSchema = (schema: SchemaObject): SchemaObject => ({\n ...schema,\n properties: { ...schema.properties },\n required: Array.isArray(schema.required) ? [...schema.required] : schema.required,\n})\n\nexport interface EntitySchemas {\n read: SchemaObject\n create: SchemaObject\n update: SchemaObject\n}\n\nexport const buildEntitySchemas = async ({\n entity,\n config,\n ctx,\n}: {\n entity: Entity\n config: SanitizedConfig\n ctx: BuildContext\n}): Promise<EntitySchemas> => {\n const source = stripInterfaceName(entity)\n const defs = new Map<string, unknown>()\n const idType = ctx.defaultIDType\n const read = toComponentSchema({ config, source, idType, defs })\n const write = toComponentSchema({ config, source, idType, defs, variant: 'input' })\n const isAuth = 'auth' in entity && Boolean(entity.auth)\n\n for (const schema of [read, write]) {\n if (isAuth) removeProps(schema, READ_HIDDEN_FIELDS)\n applyFieldOverrides({ schema, fields: entity.fields, ctx })\n addBlockDiscriminators(schema)\n }\n fixPolymorphicJoinRequired(read)\n\n const create = cloneSchema(write)\n if (isAuth && create.properties) {\n create.properties.password = { type: 'string' }\n create.required = [...new Set([...(create.required ?? []), 'password'])]\n }\n\n removeProps(create, deniedWrites(entity.fields, 'create'))\n\n const update = cloneSchema(write)\n removeProps(update, deniedWrites(entity.fields, 'update'))\n delete update.required\n if (update.properties) delete update.properties.id\n if (isAuth && update.properties) {\n update.properties.password = { type: 'string' }\n }\n\n markLocalizedFields({ schema: read, fields: entity.fields, ctx })\n\n return { read, create, update }\n}\n\nexport const buildBlockSchema = (block: Block, config: SanitizedConfig): SchemaObject => {\n const schema = toComponentSchema({ config, source: stripInterfaceName(block), idType: 'text' })\n const blockType: SchemaObject = { type: 'string', enum: [block.slug] }\n const properties = { ...schema.properties, blockType }\n const required = [...new Set(['blockType', ...(schema.required ?? [])])]\n return { ...schema, type: 'object', properties, required }\n}\n"],"mappings":";;;;;;AAYA,MAAM,qCAAqB,IAAI,IAAY,CAAC,GAAG,aAAa,YAAY,CAAC;AAEzE,MAAM,sBAAyB,WAAiB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AAO,YAAY,CAAC,GAAI,UAAU,CAAC,CAAC;CACzE;CAEA,YAAY,QAAQ,aAAa,OAAO,QAAQ,QAAQ,CAAC;CAEzD,MAAM,SAAS,YAAY,KAAK;CAChC,YAAY,QAAQ,aAAa,OAAO,QAAQ,QAAQ,CAAC;CACzD,OAAO,OAAO;CACd,IAAI,OAAO,YAAY,OAAO,OAAO,WAAW;CAChD,IAAI,UAAU,OAAO,YACnB,OAAO,WAAW,WAAW,EAAE,MAAM,SAAS;CAGhD,oBAAoB;EAAE,QAAQ;EAAM,QAAQ,OAAO;EAAQ;CAAI,CAAC;CAEhE,OAAO;EAAE;EAAM;EAAQ;CAAO;AAChC;AAEA,MAAa,oBAAoB,OAAc,WAA0C;CACvF,MAAM,SAAS,kBAAkB;EAAE;EAAQ,QAAQ,mBAAmB,KAAK;EAAG,QAAQ;CAAO,CAAC;CAC9F,MAAM,YAA0B;EAAE,MAAM;EAAU,MAAM,CAAC,MAAM,IAAI;CAAE;CACrE,MAAM,aAAa;EAAE,GAAG,OAAO;EAAY;CAAU;CACrD,MAAM,WAAW,CAAC,mBAAG,IAAI,IAAI,CAAC,aAAa,GAAI,OAAO,YAAY,CAAC,CAAE,CAAC,CAAC;CACvE,OAAO;EAAE,GAAG;EAAQ,MAAM;EAAU;EAAY;CAAS;AAC3D"}
@@ -1,5 +1,6 @@
1
- import type { Field } from 'payload';
1
+ import { Field } from "payload";
2
2
  export declare const isHiddenField: (field: Field) => boolean;
3
3
  export declare const AUTH_FIELDS: Set<string>;
4
4
  export declare const flattenFields: (fields: Field[]) => Field[];
5
5
  export declare const exposableFields: (fields: Field[]) => Field[];
6
+ //# sourceMappingURL=fields.d.ts.map