@xano/sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (336) hide show
  1. package/CHANGELOG.md +788 -0
  2. package/LICENSE +21 -0
  3. package/README.md +541 -0
  4. package/dist/.build-fingerprint +1 -0
  5. package/dist/agent-file-refresh-ZEMK33AX.js +38 -0
  6. package/dist/answer-shape-K67TAAPY.js +33 -0
  7. package/dist/backend-dir-2U53CIAL.js +39 -0
  8. package/dist/backend-slot-7QXW2QYC.js +28 -0
  9. package/dist/bin.d.ts +1 -0
  10. package/dist/bin.js +255 -0
  11. package/dist/branch-NCRNWQBQ.js +61 -0
  12. package/dist/branch-commands-ACIRCEQJ.js +79 -0
  13. package/dist/bundle.d.ts +223 -0
  14. package/dist/bundle.js +153 -0
  15. package/dist/capture-WAXPD7DR.js +41 -0
  16. package/dist/chunk-27GWNP2I.js +23 -0
  17. package/dist/chunk-2CMJZDCL.js +177 -0
  18. package/dist/chunk-2EZ3ZJZZ.js +302 -0
  19. package/dist/chunk-2GNFDZA2.js +390 -0
  20. package/dist/chunk-2MNLRIOX.js +11 -0
  21. package/dist/chunk-2TFRR6JV.js +104 -0
  22. package/dist/chunk-2ZUEE4EK.js +408 -0
  23. package/dist/chunk-36JUQZVQ.js +22 -0
  24. package/dist/chunk-3DRXWLJ5.js +83 -0
  25. package/dist/chunk-3JDU4VRL.js +137 -0
  26. package/dist/chunk-3KZCLN4Z.js +241 -0
  27. package/dist/chunk-3LDULPRE.js +168 -0
  28. package/dist/chunk-3M4LFYNQ.js +111 -0
  29. package/dist/chunk-3XI5CTUE.js +22 -0
  30. package/dist/chunk-3YW23UFH.js +50 -0
  31. package/dist/chunk-45UIT5T2.js +862 -0
  32. package/dist/chunk-4BW2SG2N.js +46 -0
  33. package/dist/chunk-4KHEMC32.js +79 -0
  34. package/dist/chunk-4POWHT2K.js +321 -0
  35. package/dist/chunk-4Q2GN7NW.js +192 -0
  36. package/dist/chunk-5A2PLKZB.js +70 -0
  37. package/dist/chunk-5FBYXK5P.js +159 -0
  38. package/dist/chunk-5HVXPTU4.js +323 -0
  39. package/dist/chunk-5QU2P5CA.js +304 -0
  40. package/dist/chunk-5V5XU32D.js +191 -0
  41. package/dist/chunk-5ZSO4T2G.js +10 -0
  42. package/dist/chunk-622HUCZT.js +10 -0
  43. package/dist/chunk-65HWOMGV.js +177 -0
  44. package/dist/chunk-6ELFRN3P.js +365 -0
  45. package/dist/chunk-6HO3NCSJ.js +1055 -0
  46. package/dist/chunk-6IUMKYWI.js +457 -0
  47. package/dist/chunk-6KEB3C3U.js +65 -0
  48. package/dist/chunk-6MR5TI5V.js +987 -0
  49. package/dist/chunk-6NNTNXN7.js +157 -0
  50. package/dist/chunk-6PBR37LN.js +97 -0
  51. package/dist/chunk-6QXLMMT3.js +155 -0
  52. package/dist/chunk-6ZGJCBZS.js +224 -0
  53. package/dist/chunk-73IVBKMA.js +250 -0
  54. package/dist/chunk-7G3CTU7I.js +286 -0
  55. package/dist/chunk-A3UDOZB6.js +222 -0
  56. package/dist/chunk-A6E77GDW.js +85 -0
  57. package/dist/chunk-AHJWCYQO.js +660 -0
  58. package/dist/chunk-AKNCFVKZ.js +36 -0
  59. package/dist/chunk-AM4FKL4J.js +237 -0
  60. package/dist/chunk-AN6BL47T.js +26 -0
  61. package/dist/chunk-AOSYVMUS.js +147 -0
  62. package/dist/chunk-APWXY5SL.js +182 -0
  63. package/dist/chunk-AWEIIR2U.js +218 -0
  64. package/dist/chunk-AWQ7BQTQ.js +73 -0
  65. package/dist/chunk-BAUZOWGX.js +393 -0
  66. package/dist/chunk-BHACRS6R.js +940 -0
  67. package/dist/chunk-BWPNT55T.js +680 -0
  68. package/dist/chunk-C6RIMRU4.js +187 -0
  69. package/dist/chunk-CGVQZXYG.js +263 -0
  70. package/dist/chunk-CIMQZRRE.js +162 -0
  71. package/dist/chunk-CJHQKJU4.js +113 -0
  72. package/dist/chunk-CTMO46PK.js +1897 -0
  73. package/dist/chunk-D53J55C5.js +106 -0
  74. package/dist/chunk-D7VGG3WS.js +90 -0
  75. package/dist/chunk-DAD3ONIS.js +245 -0
  76. package/dist/chunk-DGWHAVRG.js +162 -0
  77. package/dist/chunk-DX4QR4B2.js +483 -0
  78. package/dist/chunk-EHP3WPEG.js +21 -0
  79. package/dist/chunk-ELP2HMXC.js +432 -0
  80. package/dist/chunk-ERVIASGL.js +21 -0
  81. package/dist/chunk-ET4Y4XCB.js +865 -0
  82. package/dist/chunk-ETO6LGLD.js +4750 -0
  83. package/dist/chunk-EUUUMY7J.js +24 -0
  84. package/dist/chunk-FQJ2TTHP.js +218 -0
  85. package/dist/chunk-FQOF7E2E.js +133 -0
  86. package/dist/chunk-FWD7AL6N.js +21 -0
  87. package/dist/chunk-FXFV3KU6.js +138 -0
  88. package/dist/chunk-FXRQOWTE.js +171 -0
  89. package/dist/chunk-G554NZNI.js +210 -0
  90. package/dist/chunk-GSGDWJB5.js +13 -0
  91. package/dist/chunk-H2V3N23D.js +66 -0
  92. package/dist/chunk-H5C7MBCR.js +159 -0
  93. package/dist/chunk-HHN734BU.js +371 -0
  94. package/dist/chunk-HRVBLCVJ.js +243 -0
  95. package/dist/chunk-HVRUQXGD.js +1264 -0
  96. package/dist/chunk-I4F5TCJH.js +130 -0
  97. package/dist/chunk-IDOTCMDV.js +57 -0
  98. package/dist/chunk-IGOLHKWF.js +427 -0
  99. package/dist/chunk-JGE7CAWB.js +148 -0
  100. package/dist/chunk-JTUKLCXS.js +92 -0
  101. package/dist/chunk-JZGVVJSI.js +66 -0
  102. package/dist/chunk-K4WX6UUU.js +923 -0
  103. package/dist/chunk-K5BBGTYZ.js +217 -0
  104. package/dist/chunk-K6RXBGUB.js +427 -0
  105. package/dist/chunk-KTSDSD36.js +165 -0
  106. package/dist/chunk-L5JYN3NM.js +1038 -0
  107. package/dist/chunk-LIEOKXKD.js +354 -0
  108. package/dist/chunk-LLNZGEFK.js +51 -0
  109. package/dist/chunk-LPECSJ2J.js +55 -0
  110. package/dist/chunk-LQCMKAJ7.js +413 -0
  111. package/dist/chunk-LRN4ZJCQ.js +1145 -0
  112. package/dist/chunk-MJ4ZVHKN.js +17 -0
  113. package/dist/chunk-MXHSQOC4.js +3061 -0
  114. package/dist/chunk-N5GKCWE5.js +367 -0
  115. package/dist/chunk-NA3PXMEF.js +10 -0
  116. package/dist/chunk-NAQDMEHV.js +76 -0
  117. package/dist/chunk-NWKXM5RD.js +109 -0
  118. package/dist/chunk-NZOWWHU5.js +196 -0
  119. package/dist/chunk-OHX6MIUZ.js +184 -0
  120. package/dist/chunk-OOXWYAA4.js +15 -0
  121. package/dist/chunk-OPHB5ORL.js +1990 -0
  122. package/dist/chunk-OXA6PSZT.js +1725 -0
  123. package/dist/chunk-P2HAGF6H.js +73 -0
  124. package/dist/chunk-PTHVMXZI.js +3036 -0
  125. package/dist/chunk-PZ5AY32C.js +10 -0
  126. package/dist/chunk-Q325JKYB.js +189 -0
  127. package/dist/chunk-Q7DGTQ5G.js +255 -0
  128. package/dist/chunk-QCNYHBL7.js +601 -0
  129. package/dist/chunk-QO6BVGS5.js +145 -0
  130. package/dist/chunk-QXTKSOFI.js +76 -0
  131. package/dist/chunk-ROY4YAEQ.js +66 -0
  132. package/dist/chunk-RTJRZFFY.js +447 -0
  133. package/dist/chunk-SAVJUS2X.js +128 -0
  134. package/dist/chunk-SFLHVCKX.js +173 -0
  135. package/dist/chunk-STSFNCY4.js +127 -0
  136. package/dist/chunk-SWBF2LTK.js +170 -0
  137. package/dist/chunk-T5KELPAR.js +109 -0
  138. package/dist/chunk-TFFGOFVZ.js +1481 -0
  139. package/dist/chunk-TLHIFK4M.js +256 -0
  140. package/dist/chunk-TLQE7ZN3.js +156 -0
  141. package/dist/chunk-TPHWJ7UG.js +1981 -0
  142. package/dist/chunk-TRJCALW3.js +291 -0
  143. package/dist/chunk-TTEIYD5P.js +133 -0
  144. package/dist/chunk-U64O2MXY.js +407 -0
  145. package/dist/chunk-UCQ2VUTG.js +630 -0
  146. package/dist/chunk-UTI5G6OJ.js +44 -0
  147. package/dist/chunk-UVHDMMIP.js +188 -0
  148. package/dist/chunk-UZ6QQWJT.js +120 -0
  149. package/dist/chunk-VAX3UZOY.js +686 -0
  150. package/dist/chunk-W3HBUKFO.js +57 -0
  151. package/dist/chunk-WKQLGKCL.js +2823 -0
  152. package/dist/chunk-WQFNASK4.js +560 -0
  153. package/dist/chunk-WRBKLYSJ.js +224 -0
  154. package/dist/chunk-WTPZRR4I.js +17 -0
  155. package/dist/chunk-WZDJ2LLX.js +2385 -0
  156. package/dist/chunk-X2NL4KUO.js +14 -0
  157. package/dist/chunk-X4DVXBFY.js +38 -0
  158. package/dist/chunk-X677DMZM.js +7050 -0
  159. package/dist/chunk-XBKMWY7F.js +612 -0
  160. package/dist/chunk-XNCP4KYO.js +78 -0
  161. package/dist/chunk-XVBGLISP.js +35 -0
  162. package/dist/chunk-XW6KISBB.js +1192 -0
  163. package/dist/chunk-YGZHHAAB.js +8156 -0
  164. package/dist/chunk-YHEFQUQB.js +186 -0
  165. package/dist/chunk-YLDALTWZ.js +653 -0
  166. package/dist/chunk-YU4HSQW7.js +229 -0
  167. package/dist/chunk-ZDPP6RKB.js +27 -0
  168. package/dist/chunk-ZFDZKNGG.js +194 -0
  169. package/dist/chunk-ZIY7RNUT.js +49 -0
  170. package/dist/chunk-ZYJP6BOO.js +30 -0
  171. package/dist/cli.d.ts +1111 -0
  172. package/dist/cli.js +165 -0
  173. package/dist/codegen-command-VR2GWR6C.js +173 -0
  174. package/dist/codegen.d.ts +115 -0
  175. package/dist/codegen.js +19 -0
  176. package/dist/commands-GJMJ4XYZ.js +76 -0
  177. package/dist/completion-ZQLO6PB6.js +738 -0
  178. package/dist/config-MBYGCAFK.js +136 -0
  179. package/dist/deploy-command-JVZPWHMK.js +180 -0
  180. package/dist/deploy-source-3W45CXMP.js +81 -0
  181. package/dist/dev-env-sync-HN44K4D5.js +188 -0
  182. package/dist/diagnostics-UEAAHWVF.js +30 -0
  183. package/dist/display-name-hint-ABBPVQIR.js +46 -0
  184. package/dist/emit-CyhBDxli.d.ts +7007 -0
  185. package/dist/env-example-refresh-ET5HMMDW.js +126 -0
  186. package/dist/env-pull-command-TNMNB3CV.js +323 -0
  187. package/dist/env-target-O4HRKTGZ.js +40 -0
  188. package/dist/env-var-command-ZIRDCAZA.js +427 -0
  189. package/dist/ephemeral-P7F3PMAD.js +54 -0
  190. package/dist/ephemeral-command-CLJJKOFT.js +592 -0
  191. package/dist/ephemeral-state-PYCBSOGX.js +61 -0
  192. package/dist/file-lock-PT74GWYW.js +10 -0
  193. package/dist/generate-command-AYEOLA26.js +510 -0
  194. package/dist/gitignore-3SJ3WNRG.js +51 -0
  195. package/dist/guards-4EBNCZDC.js +162 -0
  196. package/dist/hosted-file-PSHJB3HX.js +28 -0
  197. package/dist/impersonate-command-5JAS3WSV.js +152 -0
  198. package/dist/import-EQSFU6JC.js +19 -0
  199. package/dist/index.d.ts +5470 -0
  200. package/dist/index.js +371 -0
  201. package/dist/init-command-X2FR4UAK.js +125 -0
  202. package/dist/init-modules-RY7UHAOL.js +50 -0
  203. package/dist/init-web-M4YZSZK6.js +42 -0
  204. package/dist/internal.d.ts +179 -0
  205. package/dist/internal.js +2634 -0
  206. package/dist/io-RC56QSN5.js +26 -0
  207. package/dist/keep-data-merge-7MPLVAVI.js +1119 -0
  208. package/dist/lambda-config-reconcile-OUZ4OYAB.js +116 -0
  209. package/dist/landed-753YLJ5H.js +40 -0
  210. package/dist/landing-record-SU52SKXU.js +61 -0
  211. package/dist/live-diff-YONW2VI3.js +65 -0
  212. package/dist/local-engine-choice-CH5X3W7E.js +79 -0
  213. package/dist/local-engine-command-Z3OL7VOD.js +766 -0
  214. package/dist/local-engine-config-5U3SC434.js +39 -0
  215. package/dist/local-engine-deploy-PCQ4SNPB.js +39 -0
  216. package/dist/local-engine-process-EHTE5LLU.js +63 -0
  217. package/dist/local-engine-state-A4FTRFAF.js +32 -0
  218. package/dist/local-engine-update-check-6L645VBL.js +162 -0
  219. package/dist/lock-MRRHW5GS.js +87 -0
  220. package/dist/lock-commands-2QG25HL7.js +963 -0
  221. package/dist/login-command-QPYRWOXZ.js +538 -0
  222. package/dist/logout-command-WOIQLDP6.js +56 -0
  223. package/dist/loop-ALIZLOSX.js +191 -0
  224. package/dist/marketplace-command-K5YL42NO.js +977 -0
  225. package/dist/marketplace-resolve-LY32JES5.js +40 -0
  226. package/dist/meta-client-YXGPW53C.js +244 -0
  227. package/dist/module-manifest-JFGHU2TC.js +38 -0
  228. package/dist/near-key.d.ts +13 -0
  229. package/dist/near-key.js +8 -0
  230. package/dist/node.d.ts +95 -0
  231. package/dist/node.js +969 -0
  232. package/dist/operation-outcome-TZSESNC7.js +51 -0
  233. package/dist/output-target-AL3I44GG.js +47 -0
  234. package/dist/package-manager-PRAHUSCN.js +34 -0
  235. package/dist/plan-disclosure-6G4MLZKD.js +114 -0
  236. package/dist/plugin-contributions-WRNY5ABG.js +28 -0
  237. package/dist/plugin-prompt-4VA3B4FF.js +20 -0
  238. package/dist/plugin-questions-JTSYA74Q.js +24 -0
  239. package/dist/plugin.d.ts +396 -0
  240. package/dist/plugin.js +1 -0
  241. package/dist/preflight-command-2T5Z36MI.js +321 -0
  242. package/dist/profile-command-AH3PIM4X.js +800 -0
  243. package/dist/profile-pointer-GRWJU3YD.js +31 -0
  244. package/dist/profile-select-74TRDEPD.js +23 -0
  245. package/dist/project-dependency-KSH63ODT.js +35 -0
  246. package/dist/project-sdk-REPPOIBD.js +24 -0
  247. package/dist/promote-command-PCWT5N6S.js +140 -0
  248. package/dist/prompt-II3F3LND.js +27 -0
  249. package/dist/publish-command-TTDUUJI5.js +414 -0
  250. package/dist/pull-command-VBO7C4S3.js +161 -0
  251. package/dist/pull-superseded-GJWLG7XO.js +20 -0
  252. package/dist/release-command-N4ZPKMHR.js +146 -0
  253. package/dist/release-ns-command-3KFDMZ6G.js +1745 -0
  254. package/dist/response-HlXahv4K.d.ts +925 -0
  255. package/dist/retry-command-AS5EVREX.js +34 -0
  256. package/dist/routes-manifest-SNWUVBT6.js +43 -0
  257. package/dist/runtime-XETHVF33.js +14 -0
  258. package/dist/scaffold.d.ts +1911 -0
  259. package/dist/scaffold.js +107 -0
  260. package/dist/secrets-file-LVZD6IIM.js +56 -0
  261. package/dist/secrets-fill-command-TTCPSVXN.js +218 -0
  262. package/dist/seed-VU7C3QYS.js +46 -0
  263. package/dist/sent-writes-N7X4OVXT.js +22 -0
  264. package/dist/source-resolve-S2XA3XZF.js +83 -0
  265. package/dist/static-host-B2Y6AG3W.js +352 -0
  266. package/dist/status-command-RUDXTF7I.js +554 -0
  267. package/dist/store-6VNCD4D7.js +20 -0
  268. package/dist/store-ARM6VMO5.js +98 -0
  269. package/dist/store-DuYfzKlW.d.ts +3144 -0
  270. package/dist/suggest-6FOOYKHG.js +12 -0
  271. package/dist/sveltekit.d.ts +154 -0
  272. package/dist/sveltekit.js +109 -0
  273. package/dist/sync-contributions-UCEROO26.js +415 -0
  274. package/dist/table-ENAVMITR.js +42 -0
  275. package/dist/tables-command-GUPXXSB5.js +156 -0
  276. package/dist/tenant-IIHPOHGP.js +42 -0
  277. package/dist/tenant-command-D5HGI2X4.js +965 -0
  278. package/dist/test-command-TIKZMDPZ.js +476 -0
  279. package/dist/tests-BGGIOK3L.js +26 -0
  280. package/dist/token-NICJUTMT.js +72 -0
  281. package/dist/toolchain-hooks-GHKLUJOH.js +96 -0
  282. package/dist/toolchain-modules-5EAZUONB.js +24 -0
  283. package/dist/tracked-backend-EIBUMDZA.js +80 -0
  284. package/dist/update-check-2W2NLDTC.js +136 -0
  285. package/dist/upgrade-command-QHNFWM7O.js +531 -0
  286. package/dist/verify-rollout-DRCK5TDD.js +61 -0
  287. package/dist/whoami-command-STGINTXH.js +51 -0
  288. package/dist/workspace-2CLHU2LK.js +93 -0
  289. package/dist/workspace-binding-56PIIPCP.js +54 -0
  290. package/dist/workspace-command-JEXQETJD.js +535 -0
  291. package/dist/workspace-env-F2RFMSC5.js +70 -0
  292. package/dist/workspace-export-OJSH2HIW.js +21 -0
  293. package/dist/writable-VA7OISSK.js +25 -0
  294. package/dist/xano-ICFUSPFR.js +42 -0
  295. package/dist/xanosdk-import-GN42TO2B.js +56 -0
  296. package/dist/xanosdk-project-S6DXJONQ.js +41 -0
  297. package/dist/xdo-CxDr2Q1C.d.ts +1371 -0
  298. package/guides/README.md +33 -0
  299. package/guides/authoring.md +921 -0
  300. package/guides/cli.md +401 -0
  301. package/guides/codegen.md +177 -0
  302. package/guides/codes.md +404 -0
  303. package/guides/coverage.md +74 -0
  304. package/guides/deploying.md +1525 -0
  305. package/guides/environment.md +400 -0
  306. package/guides/marketplace.md +415 -0
  307. package/guides/module-contract.md +558 -0
  308. package/guides/object-kinds.md +433 -0
  309. package/guides/project-structure.md +43 -0
  310. package/guides/scaffold.md +351 -0
  311. package/guides/typed-frontend.md +242 -0
  312. package/llms/client.md +63 -0
  313. package/llms/errors.md +56 -0
  314. package/llms/fields.md +176 -0
  315. package/llms/filters.md +183 -0
  316. package/llms/kinds-agent-mcp.md +30 -0
  317. package/llms/kinds-core.md +100 -0
  318. package/llms/kinds-knowledge.md +20 -0
  319. package/llms/kinds-realtime.md +76 -0
  320. package/llms/lambda.md +94 -0
  321. package/llms/legacy.md +44 -0
  322. package/llms/lock.md +40 -0
  323. package/llms/object-kinds.md +34 -0
  324. package/llms/statements-calls.md +62 -0
  325. package/llms/statements-catalog.md +320 -0
  326. package/llms/statements-data.md +66 -0
  327. package/llms/statements-runtime.md +68 -0
  328. package/llms/tests.md +59 -0
  329. package/llms/toolchain.md +16 -0
  330. package/llms/triggers.md +36 -0
  331. package/llms/values.md +29 -0
  332. package/llms-full.txt +2085 -0
  333. package/llms.txt +493 -0
  334. package/manifest.json +11224 -0
  335. package/package.json +162 -0
  336. package/types/lambda-globals.d.ts +129 -0
@@ -0,0 +1,447 @@
1
+ import {
2
+ parsePathParams,
3
+ pathSegment
4
+ } from "./chunk-6IUMKYWI.js";
5
+
6
+ // src/emit/routes-manifest.ts
7
+ var RouteManifestError = class extends Error {
8
+ };
9
+ function routeKey(route) {
10
+ return `${route.verb} ${route.name}`;
11
+ }
12
+ function qualifiedRouteKey(route) {
13
+ return `${route.group}:${routeKey(route)}`;
14
+ }
15
+ function literal(value) {
16
+ return JSON.stringify(value);
17
+ }
18
+ function objectLiteral(rows) {
19
+ return rows.length === 0 ? "{}" : `{
20
+ ${rows.join("\n")}
21
+ }`;
22
+ }
23
+ function overloadsFor(fn, rows) {
24
+ return rows.map(
25
+ (r) => r.params.length === 0 ? `export function ${fn}(name: ${literal(r.name)}): string;` : `export function ${fn}(name: ${literal(r.name)}, params: { ${r.params.map((p) => `${literal(p)}: string | number`).join("; ")} }): string;`
26
+ ).join("\n");
27
+ }
28
+ function renderRealtime(realtime) {
29
+ const servers = [...realtime.servers].sort((a, b) => a.name.localeCompare(b.name));
30
+ const known = new Map(servers.map((s) => [s.name, s]));
31
+ const seenServer = /* @__PURE__ */ new Set();
32
+ for (const server of servers) {
33
+ if (seenServer.has(server.name)) {
34
+ throw new RouteManifestError(
35
+ `Two realtime servers are both named "${server.name}". The manifest keys on the server name, so the names must be unique. Rename one.`
36
+ );
37
+ }
38
+ seenServer.add(server.name);
39
+ }
40
+ const holders = /* @__PURE__ */ new Map();
41
+ for (const channel of realtime.channels) holders.set(channel.name, (holders.get(channel.name) ?? 0) + 1);
42
+ const ambiguous = /* @__PURE__ */ new Map();
43
+ const seenChannel = /* @__PURE__ */ new Set();
44
+ const channels = [...realtime.channels].sort((a, b) => a.name.localeCompare(b.name) || a.server.localeCompare(b.server)).map((channel) => {
45
+ if (!known.has(channel.server)) {
46
+ throw new RouteManifestError(
47
+ `The channel "${channel.name}" names the realtime server "${channel.server}", which is not in this workspace. A channel's socket URL comes from its server's canonical, so the server must be registered too.`
48
+ );
49
+ }
50
+ const key = holders.get(channel.name) > 1 ? `${channel.server}:${channel.name}` : channel.name;
51
+ if (seenChannel.has(key)) {
52
+ throw new RouteManifestError(
53
+ `The realtime server "${channel.server}" has two channels both named "${channel.name}". Rename one.`
54
+ );
55
+ }
56
+ seenChannel.add(key);
57
+ if (key !== channel.name) ambiguous.set(channel.name, [...ambiguous.get(channel.name) ?? [], key]);
58
+ return { ...channel, key, params: parsePathParams(`channel "${key}"`, channel.name) };
59
+ });
60
+ const serverRows = servers.map(
61
+ (s) => ` ${literal(s.name)}: { canonical: ${literal(s.canonical)} },`
62
+ );
63
+ const channelRows = channels.map(
64
+ (c) => ` ${literal(c.key)}: { server: ${literal(c.server)}${c.key === c.name ? "" : `, path: ${literal(c.name)}`} },`
65
+ );
66
+ const ambiguousKeys = [...ambiguous.keys()].sort();
67
+ const ambiguousOverloads = ambiguousKeys.map((path) => {
68
+ const fix = `${path} is on more than one realtime server - use ${ambiguous.get(path).join(" or ")}`;
69
+ return `export function channelPath(name: ${literal(path)} & { readonly ${literal(fix)}: never }, params?: never): never;
70
+ `;
71
+ }).join("");
72
+ const ambiguousSection = ambiguousKeys.length === 0 ? "" : `
73
+ /** Channel paths on more than one realtime server. Each is keyed "<server>:<path>" in CHANNELS instead. */
74
+ const AMBIGUOUS_CHANNELS: Record<string, readonly string[]> = ${objectLiteral(
75
+ ambiguousKeys.map((path) => ` ${literal(path)}: [${ambiguous.get(path).map(literal).join(", ")}],`)
76
+ )};
77
+ `;
78
+ return `
79
+ /** Every realtime server in this workspace, by name, with its resolved canonical. */
80
+ export const REALTIME_SERVERS = ${objectLiteral(serverRows)} as const;
81
+
82
+ /** Every realtime server name in this workspace. */
83
+ export type RealtimeServerName = keyof typeof REALTIME_SERVERS;
84
+ ${ambiguousSection}
85
+ /** Every realtime channel in this workspace, by path, with its owning server. */
86
+ export const CHANNELS = ${objectLiteral(channelRows)} as const;
87
+
88
+ /** Every realtime channel path in this workspace. */
89
+ export type ChannelName = keyof typeof CHANNELS;
90
+
91
+ ${ambiguousOverloads}${overloadsFor("channelPath", channels.map((c) => ({ name: c.key, params: c.params })))}
92
+ ${realtimeImplementation(ambiguousKeys.length > 0)}`;
93
+ }
94
+ function renderRouteManifest(routes, realtime) {
95
+ const sorted = [...routes].sort(
96
+ (a, b) => a.canonical.localeCompare(b.canonical) || a.name.localeCompare(b.name) || a.verb.localeCompare(b.verb)
97
+ );
98
+ const holders = /* @__PURE__ */ new Map();
99
+ for (const route of sorted) holders.set(routeKey(route), (holders.get(routeKey(route)) ?? 0) + 1);
100
+ const ambiguous = /* @__PURE__ */ new Map();
101
+ const seen = /* @__PURE__ */ new Map();
102
+ const rows = sorted.map((route) => {
103
+ const short = routeKey(route);
104
+ const group = route.group ?? route.canonical;
105
+ const key = holders.get(short) > 1 ? qualifiedRouteKey({ ...route, group }) : short;
106
+ const clash = seen.get(key);
107
+ if (clash !== void 0) {
108
+ throw new RouteManifestError(
109
+ `Two endpoints are both "${short}" in api groups named "${group}" \u2014 one whose canonical is "${clash}", one "${route.canonical}". The route manifest keys such an endpoint "<group>:<VERB> <name>", so the group names must differ. Rename one group or endpoint, or give it a different verb.`
110
+ );
111
+ }
112
+ seen.set(key, route.canonical);
113
+ if (key !== short) ambiguous.set(short, [...ambiguous.get(short) ?? [], key]);
114
+ const params = parsePathParams(`route "${key}"`, route.name);
115
+ const path = `/api:${route.canonical}/${route.name.replace(/^\/+/, "")}`;
116
+ return { ...route, key, params, path };
117
+ });
118
+ const entries = rows.map(
119
+ (r) => ` ${literal(r.key)}: { verb: ${literal(r.verb)}, path: ${literal(r.path)} },`
120
+ );
121
+ const ambiguousKeys = [...ambiguous.keys()].sort();
122
+ const ambiguousOverloads = ambiguousKeys.map((short) => {
123
+ const fix = `${short} is in more than one api group - use ${ambiguous.get(short).join(" or ")}`;
124
+ return `export function routePath(name: ${literal(short)} & { readonly ${literal(fix)}: never }, params?: never): never;`;
125
+ }).join("\n");
126
+ const ambiguousSection = ambiguousKeys.length === 0 ? "" : `
127
+ /**
128
+ * Endpoints whose "<VERB> <name>" is in more than one api group. Each is keyed
129
+ * "<group>:<VERB> <name>" in ROUTES instead \u2014 e.g. ${literal(ambiguous.get(ambiguousKeys[0])[0])}.
130
+ */
131
+ const AMBIGUOUS: Record<string, readonly string[]> = ${objectLiteral(
132
+ ambiguousKeys.map((short) => ` ${literal(short)}: [${ambiguous.get(short).map(literal).join(", ")}],`)
133
+ )};
134
+ `;
135
+ const realtimeSection = realtime && (realtime.servers.length > 0 || realtime.channels.length > 0) ? renderRealtime(realtime) : "";
136
+ return `${HEADER}${FILL_PARAMS}${ambiguousSection}
137
+ export const ROUTES = ${objectLiteral(entries)} as const;
138
+
139
+ /**
140
+ * Every endpoint in this workspace, keyed \`"<VERB> <name>"\` (e.g. \`"GET listings"\`),
141
+ * or \`"<group>:<VERB> <name>"\` when that pair is in more than one api group.
142
+ */
143
+ export type RouteName = keyof typeof ROUTES;
144
+ ${rows.length > 1 ? MANY_ROUTES : ""}
145
+ ${rows.length > 1 ? UNION_OVERLOAD : ""}${ambiguousOverloads ? `${ambiguousOverloads}
146
+ ` : ""}${overloadsFor("routePath", rows.map((r) => ({ name: r.key, params: r.params })))}
147
+ ${implementation(ambiguousKeys.length > 0)}${realtimeSection}`;
148
+ }
149
+ var UNION_OVERLOAD = `/** A union of route names (e.g. a \`key: RouteName\` parameter): params checked at runtime. */
150
+ export function routePath<N extends RouteName>(name: ManyRoutes<N>, params?: Record<string, string | number>): string;
151
+ `;
152
+ var MANY_ROUTES = `
153
+ /** \`N\` when it is a union of two or more route names, else \`never\`. */
154
+ type ManyRoutes<N> = [(N extends unknown ? (x: N) => void : never) extends (x: infer I) => void ? I : never] extends [never] ? N : never;
155
+ `;
156
+ var HEADER = `/**
157
+ * GENERATED by \`xanosdk routes --emit\`. Do not edit.
158
+ *
159
+ * Plain data plus one interpolator \u2014 this file imports nothing, so a frontend
160
+ * gets the typed path/verb (and socket) contract without pulling the SDK runtime
161
+ * into its bundle. Regenerate after changing an endpoint's name, verb, or api
162
+ * group, or a realtime server's or channel's name.
163
+ */
164
+ `;
165
+ var FILL_PARAMS = `
166
+ /**
167
+ * An own key only. Every lookup here is keyed by a caller's string, and a plain
168
+ * object answers \`toString\`, \`constructor\` or \`hasOwnProperty\` from its
169
+ * prototype \u2014 a name no route, channel or param carries would read as one.
170
+ */
171
+ function own<T>(record: Record<string, T>, key: string): T | undefined {
172
+ return Object.prototype.hasOwnProperty.call(record, key) ? record[key] : undefined;
173
+ }
174
+
175
+ function fillParams(
176
+ label: string,
177
+ noun: string,
178
+ template: string,
179
+ params?: Record<string, string | number>,
180
+ encode = false,
181
+ ): string {
182
+ const declared = [...template.matchAll(/\\{([^/{}]+)\\}/g)].map((m) => m[1]!);
183
+ for (const key of Object.keys(params ?? {})) {
184
+ if (!declared.includes(key)) {
185
+ throw new Error(
186
+ \`\${label}: \\\`\${key}\\\` is not a {param} of this \${noun}.\` +
187
+ (declared.length ? \` Expected: \${declared.join(", ")}.\` : \` This \${noun} is static.\`),
188
+ );
189
+ }
190
+ }
191
+ const raw: Record<string, string> = {};
192
+ const filled = template.replace(/\\{([^/{}]+)\\}/g, (_all, key: string) => {
193
+ const value = own(params ?? {}, key);
194
+ if (value === undefined || value === null || value === "") {
195
+ throw new Error(\`\${label}: missing a value for the path param \\\`\${key}\\\`.\`);
196
+ }
197
+ if (typeof value === "number" && !Number.isFinite(value)) {
198
+ throw new Error(\`\${label}: the path param \\\`\${key}\\\` is \${value}.\`);
199
+ }
200
+ const text = String(value);
201
+ if (text.includes("/")) {
202
+ throw new Error(
203
+ \`\${label}: the path param \\\`\${key}\\\` cannot contain "/" \u2014 \` +
204
+ \`it would address a different \${noun}.\`,
205
+ );
206
+ }
207
+ if (!encode) {
208
+ if (!/^[A-Za-z0-9_-]+$/.test(text)) {
209
+ throw new Error(
210
+ \`\${label}: the path param \\\`\${key}\\\` is "\${text}" \u2014 a \${noun} segment holds only \` +
211
+ \`letters, digits, "_" and "-".\`,
212
+ );
213
+ }
214
+ return text;
215
+ }
216
+ raw[key] = encodeURIComponent(text);
217
+ return raw[key];
218
+ });
219
+ // A "." or ".." SEGMENT is REMOVED before routing (and takes the segment
220
+ // before it), and the URL standard reads "%2e" as a dot for that check too.
221
+ // Judged on the segment as sent, values encoded.
222
+ if (encode) {
223
+ for (const segment of template.split("/")) {
224
+ if (!segment.includes("{")) continue;
225
+ const assembled = segment.replace(/\\{([^/{}]+)\\}/g, (_all, key: string) => raw[key] ?? "");
226
+ if (/^(\\.|%2e){1,2}$/i.test(assembled)) {
227
+ throw new Error(
228
+ \`\${label}: the path segment "\${segment}" cannot be "\${assembled}" \u2014 \` +
229
+ \`a "." or ".." segment addresses a different \${noun}.\`,
230
+ );
231
+ }
232
+ }
233
+ }
234
+ return filled;
235
+ }
236
+ `;
237
+ function implementation(ambiguous) {
238
+ const params = ambiguous ? "params?: Record<string, string | number> | string" : "params?: Record<string, string | number>";
239
+ const hint = ambiguous ? `
240
+ const qualified = own(AMBIGUOUS, name);
241
+ if (qualified) {
242
+ throw new Error(
243
+ \`routePath: "\${String(name)}" is in more than one api group \u2014 use \${qualified.map((k) => \`"\${k}"\`).join(" or ")}.\`,
244
+ );
245
+ }` : "";
246
+ return `
247
+ export function routePath(name: ${ambiguous ? "string" : "RouteName"}, ${params}): string {${hint}
248
+ // Read through a widened view: a workspace with no endpoints at all makes
249
+ // \`RouteName\` \`never\`, which cannot index the literal type.
250
+ const route = own(ROUTES as Record<string, { verb: string; path: string }>, name);
251
+ if (!route) {
252
+ throw new Error(
253
+ \`routePath: unknown route "\${String(name)}". Routes are keyed "<VERB> <name>", \` +
254
+ 'e.g. "GET listings" \u2014 regenerate the manifest if the endpoint is new.',
255
+ );
256
+ }
257
+ return fillParams(\`routePath("\${String(name)}")\`, "route", route.path, params${ambiguous ? " as Record<string, string | number> | undefined" : ""}, true);
258
+ }
259
+ `;
260
+ }
261
+ function realtimeImplementation(ambiguous) {
262
+ if (!ambiguous) {
263
+ return `
264
+ export function channelPath(name: ChannelName, params?: Record<string, string | number>): string {
265
+ if (!own(CHANNELS as Record<string, unknown>, name)) {
266
+ throw new Error(\`channelPath: unknown channel "\${String(name)}".\`);
267
+ }
268
+ return fillParams(\`channelPath("\${String(name)}")\`, "channel", String(name), params);
269
+ }
270
+ ${REALTIME_IMPLEMENTATION}`;
271
+ }
272
+ return `
273
+ export function channelPath(name: string, params?: Record<string, string | number>): string {
274
+ const qualified = own(AMBIGUOUS_CHANNELS, name);
275
+ if (qualified) {
276
+ throw new Error(
277
+ \`channelPath: "\${String(name)}" is on more than one realtime server \u2014 use \${qualified.map((k) => \`"\${k}"\`).join(" or ")}.\`,
278
+ );
279
+ }
280
+ const channel = own(CHANNELS as Record<string, { server: string; path?: string }>, name);
281
+ if (!channel) {
282
+ throw new Error(\`channelPath: unknown channel "\${String(name)}".\`);
283
+ }
284
+ return fillParams(\`channelPath("\${String(name)}")\`, "channel", channel.path ?? String(name), params);
285
+ }
286
+ ${REALTIME_IMPLEMENTATION}`;
287
+ }
288
+ var REALTIME_IMPLEMENTATION = `
289
+ /** Reject a tenant name that would break the \\\`<tenant>:<canonical>\\\` split. */
290
+ function assertTenant(tenant: string): string {
291
+ if (!/^[A-Za-z0-9-]+$/.test(tenant)) {
292
+ throw new Error(
293
+ \`socketUrl: invalid \\\`tenant\\\` \${JSON.stringify(tenant)} \u2014 a tenant name is alphanumeric with \` +
294
+ \`dashes (e.g. "xxxx-xxxx-xxxx"). It rides as a "<tenant>:<canonical>" prefix, so ":" and "/" \` +
295
+ "cannot appear in it.",
296
+ );
297
+ }
298
+ return tenant;
299
+ }
300
+
301
+ /** The websocket PATH \u2014 \\\`/ws/<canonical>\\\`, or \\\`/ws/<tenant>:<canonical>\\\`. */
302
+ export function socketPath(server: RealtimeServerName, opts?: { tenant?: string | undefined }): string {
303
+ const entry = own(REALTIME_SERVERS as Record<string, { canonical: string }>, server);
304
+ if (!entry) throw new Error(\`socketPath: unknown realtime server "\${String(server)}".\`);
305
+ const prefix = opts?.tenant ? \`\${assertTenant(opts.tenant)}:\` : "";
306
+ return \`/ws/\${prefix}\${entry.canonical}\`;
307
+ }
308
+
309
+ /** The absolute websocket URL \u2014 \\\`baseUrl\\\` + {@link socketPath}, scheme normalized to ws/wss. */
310
+ export function socketUrl(
311
+ server: RealtimeServerName,
312
+ baseUrl: string,
313
+ opts?: { tenant?: string | undefined },
314
+ ): string {
315
+ if (!own(REALTIME_SERVERS as Record<string, unknown>, server)) {
316
+ throw new Error(\`socketUrl: unknown realtime server "\${String(server)}".\`);
317
+ }
318
+ const base = (baseUrl ?? "").trim().replace(/\\/+$/, "");
319
+ if (!base) throw new Error('socketUrl: needs a base URL (e.g. "https://x.dev.xano.io").');
320
+ const socketBase = /^wss?:\\/\\//i.test(base)
321
+ ? base
322
+ : /^https?:\\/\\//i.test(base)
323
+ ? base.replace(/^http/i, "ws")
324
+ : \`wss://\${base}\`;
325
+ // A base URL ending in \\\`/ws/<something>\\\` is this function's own output fed back
326
+ // in. Appending a second \\\`/ws/<canonical>\\\` is wrong twice: the extra segments
327
+ // join the connection hash, and the tenant is dropped (the first call already
328
+ // consumed the \\\`/tenant/<name>\\\` prefix). Refuse rather than dial a bad URL.
329
+ if (/\\/ws\\/[^/]+$/i.test(socketBase)) {
330
+ throw new Error(
331
+ \`socketUrl: \\\`baseUrl\\\` already carries a socket path (\${base}). Pass the http(s) \` +
332
+ "INSTANCE base URL, not the result of a previous socketUrl()/getUrl() \u2014 resolving twice " +
333
+ 'appends a second "/ws/<canonical>" and drops the tenant.',
334
+ );
335
+ }
336
+ // A query, a fragment or an API group's \\\`/api:<\u2026>\\\` path is not an instance
337
+ // base: the socket path appended after it never reaches the server.
338
+ if (/[?#]/.test(base) || /\\/api:/i.test(base)) {
339
+ throw new Error(
340
+ \`socketUrl: \\\`baseUrl\\\` is not an instance base URL (\${base}). Pass "https://<host>" or \` +
341
+ '"https://<host>/tenant/<name>" \u2014 no query, fragment or /api:<\u2026> path.',
342
+ );
343
+ }
344
+ // A tenant base URL names its tenant as its own path segment; the socket glues
345
+ // it to the canonical inside one segment. Translate rather than concatenate \u2014
346
+ // the concatenated form never upgrades at all.
347
+ const lifted = /^(wss?:\\/\\/[^/]+)\\/tenant\\/([^/]+)(\\/.*)?$/i.exec(socketBase);
348
+ let origin = socketBase;
349
+ let tenant = opts?.tenant;
350
+ if (lifted) {
351
+ const fromBase = lifted[2]!;
352
+ if (tenant !== undefined && tenant !== fromBase) {
353
+ throw new Error(
354
+ \`socketUrl: given tenant \${JSON.stringify(tenant)} but the base URL names \` +
355
+ \`\${JSON.stringify(fromBase)} (".../tenant/\${fromBase}"). Refusing to guess which one you \` +
356
+ "meant \u2014 pass the matching tenant, or a base URL without the \\"/tenant/<name>\\" prefix.",
357
+ );
358
+ }
359
+ origin = \`\${lifted[1]!}\${lifted[3] ?? ""}\`;
360
+ tenant = assertTenant(fromBase);
361
+ }
362
+ return \`\${origin}\${socketPath(server, { tenant })}\`;
363
+ }
364
+ `;
365
+ var ROUTES_MANIFEST_BASENAME = "routes.gen.ts";
366
+ function planRouteManifest(payload, locked = () => void 0) {
367
+ const list = (key) => Array.isArray(payload[key]) ? payload[key].filter(
368
+ (r) => r !== null && typeof r === "object"
369
+ ) : [];
370
+ const text = (v) => typeof v === "string" && v !== "" ? v : void 0;
371
+ const ref = (v) => v !== null && typeof v === "object" ? text(v.id) : void 0;
372
+ const canonicalByGuid = /* @__PURE__ */ new Map();
373
+ const groupByGuid = /* @__PURE__ */ new Map();
374
+ for (const a of list("app")) {
375
+ const guid = text(a.guid);
376
+ if (guid === void 0) continue;
377
+ const name = text(a.name);
378
+ if (name !== void 0) groupByGuid.set(guid, name);
379
+ const resolved = text(a.canonical) ?? (name !== void 0 ? locked("app", name) : void 0);
380
+ if (resolved) canonicalByGuid.set(guid, resolved);
381
+ }
382
+ const rows = list("query").map((q) => {
383
+ const group = ref(q.app);
384
+ return {
385
+ verb: q.verb,
386
+ // already an uppercase HttpVerb in the bundle
387
+ // Match getPath(): the path segment drops any leading slash on the name.
388
+ name: pathSegment(typeof q.name === "string" ? q.name : ""),
389
+ canonical: group !== void 0 ? canonicalByGuid.get(group) : void 0,
390
+ ...group !== void 0 && groupByGuid.has(group) ? { group: groupByGuid.get(group) } : {}
391
+ };
392
+ });
393
+ rows.sort((a, b) => (a.canonical ?? "").localeCompare(b.canonical ?? "") || a.name.localeCompare(b.name));
394
+ const serverNameByGuid = /* @__PURE__ */ new Map();
395
+ const serverRows = list("realtime_server").flatMap((s) => {
396
+ const name = text(s.name);
397
+ if (name === void 0) return [];
398
+ const guid = text(s.guid);
399
+ if (guid !== void 0) serverNameByGuid.set(guid, name);
400
+ return [{ name, canonical: text(s.canonical) ?? locked("realtime_server", name) }];
401
+ });
402
+ const servers = serverRows.flatMap((s) => s.canonical ? [{ name: s.name, canonical: s.canonical }] : []);
403
+ const describable = new Set(servers.map((s) => s.name));
404
+ const channels = list("channel").flatMap((c) => {
405
+ const name = text(c.name);
406
+ if (name === void 0) return [];
407
+ const serverGuid = ref(c.server);
408
+ const server = serverGuid !== void 0 ? serverNameByGuid.get(serverGuid) : void 0;
409
+ if (server === void 0 || !describable.has(server)) return [];
410
+ return [{ name, server }];
411
+ });
412
+ return {
413
+ rows,
414
+ resolved: rows.flatMap(
415
+ (r) => r.canonical ? [{ name: r.name, verb: r.verb, canonical: r.canonical, ...r.group !== void 0 ? { group: r.group } : {} }] : []
416
+ ),
417
+ unresolved: rows.filter((r) => !r.canonical),
418
+ servers,
419
+ unresolvedServers: serverRows.filter((s) => !s.canonical).map((s) => s.name),
420
+ channels
421
+ };
422
+ }
423
+ function unresolvedCanonicalMessage(unresolved, entry) {
424
+ const names = unresolved.map((r) => `"${r.name}"`).join(", ");
425
+ const nul = process.platform === "win32" ? "NUL" : "/dev/null";
426
+ return `cannot resolve the api group's canonical URL token for ${unresolved.length === 1 ? "the query" : `${unresolved.length} queries`} ${names}. Set an explicit \`apiGroup({ canonical })\`, or run \`xanosdk export ${entry} --out ${nul}\` once (it mints a unique canonical and freezes it in xano.lock, and writes the bundle nowhere), then re-run \`xanosdk routes\`.`;
427
+ }
428
+ function renderPlannedManifest(plan, entry = "<entry>") {
429
+ if (plan.unresolved.length > 0) throw new RouteManifestError(unresolvedCanonicalMessage(plan.unresolved, entry));
430
+ if (plan.resolved.length === 0 && plan.servers.length === 0) return void 0;
431
+ return renderRouteManifest(
432
+ plan.resolved,
433
+ plan.servers.length > 0 ? { servers: plan.servers, channels: plan.channels } : void 0
434
+ );
435
+ }
436
+
437
+ export {
438
+ RouteManifestError,
439
+ routeKey,
440
+ qualifiedRouteKey,
441
+ renderRouteManifest,
442
+ ROUTES_MANIFEST_BASENAME,
443
+ planRouteManifest,
444
+ unresolvedCanonicalMessage,
445
+ renderPlannedManifest
446
+ };
447
+ //# sourceMappingURL=chunk-RTJRZFFY.js.map
@@ -0,0 +1,128 @@
1
+ import {
2
+ ensureExportGitignored
3
+ } from "./chunk-YHEFQUQB.js";
4
+ import {
5
+ andList
6
+ } from "./chunk-622HUCZT.js";
7
+ import {
8
+ UsageError,
9
+ warn
10
+ } from "./chunk-PTHVMXZI.js";
11
+
12
+ // src/emit/output-target.ts
13
+ import { accessSync, chmodSync, constants, mkdirSync, statSync, writeFileSync } from "fs";
14
+ import { dirname, isAbsolute, join, resolve, sep } from "path";
15
+ function resolveOutputTarget(opts) {
16
+ const { path, name, ext } = opts;
17
+ if (path === "-") return { kind: "stdout" };
18
+ if (path === void 0 || path === "") {
19
+ return { kind: "file", path: resolve(deriveExportBasename(name, ext)) };
20
+ }
21
+ const endsWithSep = path.endsWith("/") || path.endsWith("\\");
22
+ const isDir = statSync(path, { throwIfNoEntry: false })?.isDirectory() ?? false;
23
+ if (endsWithSep || isDir) {
24
+ return { kind: "file", path: resolve(join(path, deriveExportBasename(name, ext))) };
25
+ }
26
+ return { kind: "file", path: resolve(path) };
27
+ }
28
+ function deriveExportBasename(name, ext) {
29
+ if (name.trim() === "") {
30
+ throw new UsageError(
31
+ `An export derives its filename from the name it was given, and this one is empty.
32
+ The file would be written as \`.${ext}\` \u2014 a dotfile with no name at all, in a directory the reader is not looking at it in.
33
+ Name the export, or pass \`--path <file>\` to write to a filename of your choosing.`
34
+ );
35
+ }
36
+ if (name.includes("/") || name.includes("\\") || name.includes(":")) {
37
+ throw new UsageError(
38
+ `"${name}" is a path, not a name \u2014 an export derives its filename from it.
39
+ \`/\`, \`\\\` and \`:\` each address a LOCATION rather than name a file, so writing this as given would land the file somewhere the command was never pointed at: outside the invocation directory when the name traverses up, and on another drive entirely when it begins \`C:\` on Windows.
40
+ To write somewhere else on purpose, pass \`--path <file>\` naming the file. A \`--path\` that names a DIRECTORY derives this same basename inside it, so it does not sidestep this.`
41
+ );
42
+ }
43
+ if (name.startsWith(".")) {
44
+ throw new UsageError(
45
+ `"${name}" begins with a dot, so an export would derive a filename from it that addresses a directory (\`.\`, \`..\`) or hides the file from the reader who asked for it.
46
+ Pass \`--path <file>\` to write to a dotted filename on purpose.`
47
+ );
48
+ }
49
+ const file = `${name}.${ext}`;
50
+ if (Buffer.byteLength(file, "utf8") > MAX_BASENAME_BYTES) {
51
+ throw new UsageError(
52
+ `"${name.length > 40 ? `${name.slice(0, 40)}\u2026` : name}" is too long to be a filename (${Buffer.byteLength(file, "utf8")} bytes; a filesystem allows ${MAX_BASENAME_BYTES}).
53
+ Pass \`--path <file>\` to write it under a shorter name.`
54
+ );
55
+ }
56
+ return file;
57
+ }
58
+ var MAX_BASENAME_BYTES = 255;
59
+ function writeExportFile(path, content, secrets = [], flag = "--path", written = "Nothing was written") {
60
+ let regular = true;
61
+ try {
62
+ mkdirSync(dirname(path), { recursive: true });
63
+ if (secrets.length > 0) {
64
+ writeFileSync(path, content, { encoding: "utf8", mode: 384 });
65
+ regular = statSync(path).isFile();
66
+ if (regular) chmodSync(path, 384);
67
+ } else {
68
+ writeFileSync(path, content, "utf8");
69
+ }
70
+ } catch (err) {
71
+ throw unwritable(path, err, flag, written);
72
+ }
73
+ if (secrets.length > 0 && regular) {
74
+ const notice = `${path} carries ${secretsPhrase(secrets)} in cleartext \u2014 written owner-only (0600); do not commit it.`;
75
+ warn(notice, "secrets.cleartext-export");
76
+ ensureExportGitignored(path);
77
+ }
78
+ }
79
+ function secretsPhrase(secrets) {
80
+ return andList(secrets.map((s) => s === "documentation token" ? "a documentation token" : s));
81
+ }
82
+ function assertWritableTarget(path, flag = "--path") {
83
+ const target = isAbsolute(path) ? path : process.cwd() + sep + path;
84
+ try {
85
+ const existing = statOrUndefined(target);
86
+ if (existing !== void 0) {
87
+ if (existing.isDirectory()) throw Object.assign(new Error("EISDIR"), { code: "EISDIR" });
88
+ accessSync(target, constants.W_OK);
89
+ return;
90
+ }
91
+ let dir = dirname(target);
92
+ for (; ; ) {
93
+ const st = statOrUndefined(dir);
94
+ if (st !== void 0) {
95
+ if (!st.isDirectory()) throw Object.assign(new Error("ENOTDIR"), { code: "ENOTDIR" });
96
+ accessSync(dir, constants.W_OK);
97
+ return;
98
+ }
99
+ const parent = dirname(dir);
100
+ if (parent === dir) return;
101
+ dir = parent;
102
+ }
103
+ } catch (err) {
104
+ throw unwritable(path, err, flag);
105
+ }
106
+ }
107
+ function statOrUndefined(path) {
108
+ try {
109
+ return statSync(path);
110
+ } catch (err) {
111
+ if (err.code === "ENOENT") return void 0;
112
+ throw err;
113
+ }
114
+ }
115
+ function unwritable(path, err, flag, written = "Nothing was written") {
116
+ const code = err?.code;
117
+ const why = code === "EEXIST" || code === "ENOTDIR" ? "a FILE sits where one of its parent directories would have to be" : code === "EISDIR" ? "it is a directory" : code === "ENAMETOOLONG" ? "the path is longer than the filesystem allows" : code === "EACCES" || code === "EPERM" ? "this user may not write there" : code === "EROFS" ? "the filesystem there is read-only" : code === "ENOENT" ? "its parent directory does not exist and cannot be created there" : void 0;
118
+ if (why === void 0) return err;
119
+ return new UsageError(`Cannot write ${path}: ${why}. ${written}. Pass a different \`${flag}\`.`);
120
+ }
121
+
122
+ export {
123
+ resolveOutputTarget,
124
+ writeExportFile,
125
+ secretsPhrase,
126
+ assertWritableTarget
127
+ };
128
+ //# sourceMappingURL=chunk-SAVJUS2X.js.map