mtmsdk 0.0.42 → 0.0.44

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 (480) hide show
  1. package/dist/cloud-account/platform-configs.d.ts +64 -0
  2. package/dist/cloud-account/platform-configs.d.ts.map +1 -0
  3. package/dist/cloud-account/platform-configs.js +44 -0
  4. package/dist/cloud-account/platform-configs.js.map +1 -0
  5. package/dist/{gomtmapi_v2 → gomtmapi}/@tanstack/react-query.gen.d.ts +202 -8
  6. package/dist/gomtmapi/@tanstack/react-query.gen.d.ts.map +1 -0
  7. package/dist/{gomtmapi_v2 → gomtmapi}/@tanstack/react-query.gen.js +300 -10
  8. package/dist/gomtmapi/@tanstack/react-query.gen.js.map +1 -0
  9. package/dist/{opencode → gomtmapi}/client/client.gen.d.ts.map +1 -1
  10. package/dist/{opencode → gomtmapi}/client/client.gen.js.map +1 -1
  11. package/dist/{opencode → gomtmapi}/client/index.d.ts.map +1 -1
  12. package/dist/{opencode → gomtmapi}/client/index.js.map +1 -1
  13. package/dist/{opencode → gomtmapi}/client/types.gen.d.ts.map +1 -1
  14. package/dist/gomtmapi/client/types.gen.js.map +1 -0
  15. package/dist/{opencode → gomtmapi}/client/utils.gen.d.ts.map +1 -1
  16. package/dist/{opencode → gomtmapi}/client/utils.gen.js.map +1 -1
  17. package/dist/{opencode → gomtmapi}/client.gen.d.ts.map +1 -1
  18. package/dist/{opencode → gomtmapi}/client.gen.js.map +1 -1
  19. package/dist/{opencode → gomtmapi}/core/auth.gen.d.ts.map +1 -1
  20. package/dist/{opencode → gomtmapi}/core/auth.gen.js.map +1 -1
  21. package/dist/{opencode → gomtmapi}/core/bodySerializer.gen.d.ts.map +1 -1
  22. package/dist/{opencode → gomtmapi}/core/bodySerializer.gen.js.map +1 -1
  23. package/dist/{opencode → gomtmapi}/core/params.gen.d.ts.map +1 -1
  24. package/dist/{opencode → gomtmapi}/core/params.gen.js.map +1 -1
  25. package/dist/{opencode → gomtmapi}/core/pathSerializer.gen.d.ts.map +1 -1
  26. package/dist/{opencode → gomtmapi}/core/pathSerializer.gen.js.map +1 -1
  27. package/dist/{opencode → gomtmapi}/core/queryKeySerializer.gen.d.ts.map +1 -1
  28. package/dist/{opencode → gomtmapi}/core/queryKeySerializer.gen.js.map +1 -1
  29. package/dist/{opencode → gomtmapi}/core/serverSentEvents.gen.d.ts.map +1 -1
  30. package/dist/{opencode → gomtmapi}/core/serverSentEvents.gen.js.map +1 -1
  31. package/dist/{opencode → gomtmapi}/core/types.gen.d.ts.map +1 -1
  32. package/dist/gomtmapi/core/types.gen.js.map +1 -0
  33. package/dist/{opencode → gomtmapi}/core/utils.gen.d.ts.map +1 -1
  34. package/dist/{opencode → gomtmapi}/core/utils.gen.js.map +1 -1
  35. package/dist/gomtmapi/index.d.ts +3 -0
  36. package/dist/gomtmapi/index.d.ts.map +1 -0
  37. package/dist/gomtmapi/index.js +3 -0
  38. package/dist/gomtmapi/index.js.map +1 -0
  39. package/dist/{gomtmapi_v2 → gomtmapi}/schemas.gen.d.ts +337 -50
  40. package/dist/gomtmapi/schemas.gen.d.ts.map +1 -0
  41. package/dist/{gomtmapi_v2 → gomtmapi}/schemas.gen.js +355 -50
  42. package/dist/gomtmapi/schemas.gen.js.map +1 -0
  43. package/dist/gomtmapi/sdk.gen.d.ts +378 -0
  44. package/dist/gomtmapi/sdk.gen.d.ts.map +1 -0
  45. package/dist/{gomtmapi_v2 → gomtmapi}/sdk.gen.js +234 -15
  46. package/dist/gomtmapi/sdk.gen.js.map +1 -0
  47. package/dist/{gomtmapi_v2 → gomtmapi}/types.gen.d.ts +494 -50
  48. package/dist/gomtmapi/types.gen.d.ts.map +1 -0
  49. package/dist/gomtmapi/types.gen.js.map +1 -0
  50. package/dist/{gomtmapi_v2 → gomtmapi}/zod.gen.d.ts +391 -45
  51. package/dist/gomtmapi/zod.gen.d.ts.map +1 -0
  52. package/dist/{gomtmapi_v2 → gomtmapi}/zod.gen.js +270 -31
  53. package/dist/gomtmapi/zod.gen.js.map +1 -0
  54. package/dist/lib/logger/index.d.ts +3 -0
  55. package/dist/lib/logger/index.d.ts.map +1 -1
  56. package/dist/lib/schema.d.ts +14 -2
  57. package/dist/lib/schema.d.ts.map +1 -1
  58. package/dist/lib/schema.js +1 -1
  59. package/dist/lib/schema.js.map +1 -1
  60. package/dist/mtgate_api/@tanstack/react-query.gen.d.ts +29 -1
  61. package/dist/mtgate_api/@tanstack/react-query.gen.d.ts.map +1 -1
  62. package/dist/mtgate_api/@tanstack/react-query.gen.js +17 -1
  63. package/dist/mtgate_api/@tanstack/react-query.gen.js.map +1 -1
  64. package/dist/mtgate_api/index.d.ts +2 -2
  65. package/dist/mtgate_api/index.d.ts.map +1 -1
  66. package/dist/mtgate_api/index.js +1 -1
  67. package/dist/mtgate_api/index.js.map +1 -1
  68. package/dist/mtgate_api/schemas.gen.d.ts +1 -0
  69. package/dist/mtgate_api/schemas.gen.d.ts.map +1 -1
  70. package/dist/mtgate_api/schemas.gen.js +8 -1
  71. package/dist/mtgate_api/schemas.gen.js.map +1 -1
  72. package/dist/mtgate_api/sdk.gen.d.ts +5 -1
  73. package/dist/mtgate_api/sdk.gen.d.ts.map +1 -1
  74. package/dist/mtgate_api/sdk.gen.js +4 -0
  75. package/dist/mtgate_api/sdk.gen.js.map +1 -1
  76. package/dist/mtgate_api/types.gen.d.ts +7 -1
  77. package/dist/mtgate_api/types.gen.d.ts.map +1 -1
  78. package/dist/mtgate_api/zod.gen.d.ts +26 -3
  79. package/dist/mtgate_api/zod.gen.d.ts.map +1 -1
  80. package/dist/mtgate_api/zod.gen.js +12 -1
  81. package/dist/mtgate_api/zod.gen.js.map +1 -1
  82. package/dist/openclaw/client-info.d.ts +56 -0
  83. package/dist/openclaw/client-info.d.ts.map +1 -0
  84. package/dist/openclaw/client-info.js +44 -0
  85. package/dist/openclaw/client-info.js.map +1 -0
  86. package/dist/openclaw/device-auth-utils.d.ts +13 -0
  87. package/dist/openclaw/device-auth-utils.d.ts.map +1 -0
  88. package/dist/openclaw/device-auth-utils.js +20 -0
  89. package/dist/openclaw/device-auth-utils.js.map +1 -0
  90. package/dist/openclaw/device-auth.d.ts +21 -0
  91. package/dist/openclaw/device-auth.d.ts.map +1 -0
  92. package/dist/openclaw/device-auth.js +84 -0
  93. package/dist/openclaw/device-auth.js.map +1 -0
  94. package/dist/openclaw/device-identity.d.ts +8 -0
  95. package/dist/openclaw/device-identity.d.ts.map +1 -0
  96. package/dist/openclaw/device-identity.js +87 -0
  97. package/dist/openclaw/device-identity.js.map +1 -0
  98. package/dist/openclaw/gateway.d.ts +86 -0
  99. package/dist/openclaw/gateway.d.ts.map +1 -0
  100. package/dist/openclaw/gateway.js +268 -0
  101. package/dist/openclaw/gateway.js.map +1 -0
  102. package/dist/openclaw/types.d.ts +473 -0
  103. package/dist/openclaw/types.d.ts.map +1 -0
  104. package/dist/openclaw/types.js +2 -0
  105. package/dist/openclaw/types.js.map +1 -0
  106. package/dist/openclaw/uuid.d.ts +6 -0
  107. package/dist/openclaw/uuid.d.ts.map +1 -0
  108. package/dist/openclaw/uuid.js +39 -0
  109. package/dist/openclaw/uuid.js.map +1 -0
  110. package/dist/sbapi/@tanstack/react-query.gen.d.ts +3251 -6
  111. package/dist/sbapi/@tanstack/react-query.gen.d.ts.map +1 -1
  112. package/dist/sbapi/@tanstack/react-query.gen.js +6050 -6
  113. package/dist/sbapi/@tanstack/react-query.gen.js.map +1 -1
  114. package/dist/sbapi/client.gen.d.ts.map +1 -1
  115. package/dist/sbapi/client.gen.js +1 -1
  116. package/dist/sbapi/client.gen.js.map +1 -1
  117. package/dist/sbapi/index.d.ts +2 -2
  118. package/dist/sbapi/index.d.ts.map +1 -1
  119. package/dist/sbapi/index.js +1 -1
  120. package/dist/sbapi/index.js.map +1 -1
  121. package/dist/sbapi/schemas.gen.d.ts +2320 -36
  122. package/dist/sbapi/schemas.gen.d.ts.map +1 -1
  123. package/dist/sbapi/schemas.gen.js +2593 -45
  124. package/dist/sbapi/schemas.gen.js.map +1 -1
  125. package/dist/sbapi/sdk.gen.d.ts +819 -2
  126. package/dist/sbapi/sdk.gen.d.ts.map +1 -1
  127. package/dist/sbapi/sdk.gen.js +2463 -1
  128. package/dist/sbapi/sdk.gen.js.map +1 -1
  129. package/dist/sbapi/types.gen.d.ts +11701 -29
  130. package/dist/sbapi/types.gen.d.ts.map +1 -1
  131. package/dist/sbapi/zod.gen.d.ts +8134 -26
  132. package/dist/sbapi/zod.gen.d.ts.map +1 -1
  133. package/dist/sbapi/zod.gen.js +6572 -18
  134. package/dist/sbapi/zod.gen.js.map +1 -1
  135. package/dist/sbmng/@tanstack/react-query.gen.d.ts +253 -157
  136. package/dist/sbmng/@tanstack/react-query.gen.d.ts.map +1 -1
  137. package/dist/sbmng/@tanstack/react-query.gen.js +241 -145
  138. package/dist/sbmng/@tanstack/react-query.gen.js.map +1 -1
  139. package/dist/sbmng/index.d.ts +2 -2
  140. package/dist/sbmng/index.d.ts.map +1 -1
  141. package/dist/sbmng/index.js +1 -1
  142. package/dist/sbmng/index.js.map +1 -1
  143. package/dist/sbmng/schemas.gen.d.ts +1035 -917
  144. package/dist/sbmng/schemas.gen.d.ts.map +1 -1
  145. package/dist/sbmng/schemas.gen.js +1219 -1067
  146. package/dist/sbmng/schemas.gen.js.map +1 -1
  147. package/dist/sbmng/sdk.gen.d.ts +62 -38
  148. package/dist/sbmng/sdk.gen.d.ts.map +1 -1
  149. package/dist/sbmng/sdk.gen.js +140 -84
  150. package/dist/sbmng/sdk.gen.js.map +1 -1
  151. package/dist/sbmng/types.gen.d.ts +1214 -991
  152. package/dist/sbmng/types.gen.d.ts.map +1 -1
  153. package/dist/supabase/auth-provider.d.ts +4 -0
  154. package/dist/supabase/auth-provider.d.ts.map +1 -0
  155. package/dist/supabase/auth-provider.js +45 -0
  156. package/dist/supabase/auth-provider.js.map +1 -0
  157. package/dist/supabase/cursor-pagination.d.ts +92 -0
  158. package/dist/supabase/cursor-pagination.d.ts.map +1 -0
  159. package/dist/supabase/cursor-pagination.js +116 -0
  160. package/dist/supabase/cursor-pagination.js.map +1 -0
  161. package/dist/supabase/schema/browser.d.ts.map +1 -0
  162. package/dist/supabase/schema/browser.js.map +1 -0
  163. package/dist/supabase/schema/index.d.ts +29 -0
  164. package/dist/supabase/schema/index.d.ts.map +1 -0
  165. package/dist/supabase/schema/index.js +38 -0
  166. package/dist/supabase/schema/index.js.map +1 -0
  167. package/dist/supabase/supabase-client.d.ts +1912 -1128
  168. package/dist/supabase/supabase-client.d.ts.map +1 -1
  169. package/dist/supabase/supabase.d.ts +4466 -2898
  170. package/dist/supabase/supabase.d.ts.map +1 -1
  171. package/dist/supabase/supabase.js +7 -4
  172. package/dist/supabase/supabase.js.map +1 -1
  173. package/dist/supabase/use-sb-query/use-query.d.ts +1 -1
  174. package/dist/supabase/use-sb-query/use-query.d.ts.map +1 -1
  175. package/dist/supabase/use-sb-query/use-query.js +2 -6
  176. package/dist/supabase/use-sb-query/use-query.js.map +1 -1
  177. package/dist/supabase/use-sb-query/use-rpc-mutation.d.ts +61 -0
  178. package/dist/supabase/use-sb-query/use-rpc-mutation.d.ts.map +1 -0
  179. package/dist/supabase/use-sb-query/use-rpc-mutation.js +63 -0
  180. package/dist/supabase/use-sb-query/use-rpc-mutation.js.map +1 -0
  181. package/dist/supabase/use-sb-query/use-rpc-query.d.ts +124 -0
  182. package/dist/supabase/use-sb-query/use-rpc-query.d.ts.map +1 -0
  183. package/dist/supabase/use-sb-query/use-rpc-query.js +91 -0
  184. package/dist/supabase/use-sb-query/use-rpc-query.js.map +1 -0
  185. package/dist/supabase/utils.d.ts +1 -1
  186. package/dist/supabase/utils.d.ts.map +1 -1
  187. package/dist/types/database.schemas.d.ts +3911 -0
  188. package/dist/types/database.schemas.d.ts.map +1 -0
  189. package/dist/types/database.schemas.js +3180 -0
  190. package/dist/types/database.schemas.js.map +1 -0
  191. package/dist/types/database.types.d.ts +1923 -1134
  192. package/dist/types/database.types.d.ts.map +1 -1
  193. package/dist/types/database.types.js +24 -0
  194. package/dist/types/database.types.js.map +1 -1
  195. package/dist/types/index.d.ts +47 -6
  196. package/dist/types/index.d.ts.map +1 -1
  197. package/dist/types/index.js +27 -1
  198. package/dist/types/index.js.map +1 -1
  199. package/dist/types/rpc.schemas.d.ts +64 -0
  200. package/dist/types/rpc.schemas.d.ts.map +1 -0
  201. package/dist/types/rpc.schemas.js +122 -0
  202. package/dist/types/rpc.schemas.js.map +1 -0
  203. package/package.json +48 -39
  204. package/src/adk/api/client.ts +46 -0
  205. package/src/adk/core/constants/tool-icons.ts +51 -0
  206. package/src/adk/core/models/AgentBuilder.ts +80 -0
  207. package/src/adk/core/models/AgentRunRequest.ts +33 -0
  208. package/src/adk/core/models/Eval.ts +70 -0
  209. package/src/adk/core/models/LiveRequest.ts +23 -0
  210. package/src/adk/core/models/RuntimeConfig.ts +33 -0
  211. package/src/adk/core/models/Session.ts +52 -0
  212. package/src/adk/core/models/Trace.ts +42 -0
  213. package/src/adk/core/models/types.ts +255 -0
  214. package/src/api_hatchet/@tanstack/react-query.gen.ts +3025 -0
  215. package/src/api_hatchet/client/client.gen.ts +311 -0
  216. package/src/api_hatchet/client/index.ts +25 -0
  217. package/src/api_hatchet/client/types.gen.ts +241 -0
  218. package/src/api_hatchet/client/utils.gen.ts +332 -0
  219. package/{dist/opencode/client.gen.d.ts → src/api_hatchet/client.gen.ts} +6 -3
  220. package/src/api_hatchet/core/auth.gen.ts +42 -0
  221. package/src/api_hatchet/core/bodySerializer.gen.ts +100 -0
  222. package/src/api_hatchet/core/params.gen.ts +176 -0
  223. package/src/api_hatchet/core/pathSerializer.gen.ts +181 -0
  224. package/src/api_hatchet/core/queryKeySerializer.gen.ts +136 -0
  225. package/src/api_hatchet/core/serverSentEvents.gen.ts +266 -0
  226. package/src/api_hatchet/core/types.gen.ts +118 -0
  227. package/src/api_hatchet/core/utils.gen.ts +143 -0
  228. package/src/api_hatchet/index.ts +4 -0
  229. package/src/api_hatchet/schemas.gen.ts +4961 -0
  230. package/src/api_hatchet/sdk.gen.ts +1994 -0
  231. package/src/api_hatchet/types.gen.ts +7688 -0
  232. package/src/api_hatchet/zod.gen.ts +3230 -0
  233. package/src/cloud-account/platform-configs.ts +73 -0
  234. package/src/gomtmapi/@tanstack/react-query.gen.ts +757 -0
  235. package/src/gomtmapi/client/client.gen.ts +311 -0
  236. package/src/gomtmapi/client/index.ts +25 -0
  237. package/src/gomtmapi/client/types.gen.ts +241 -0
  238. package/src/gomtmapi/client/utils.gen.ts +332 -0
  239. package/src/gomtmapi/client.gen.ts +16 -0
  240. package/src/gomtmapi/core/auth.gen.ts +42 -0
  241. package/src/gomtmapi/core/bodySerializer.gen.ts +100 -0
  242. package/src/gomtmapi/core/params.gen.ts +176 -0
  243. package/src/gomtmapi/core/pathSerializer.gen.ts +181 -0
  244. package/src/gomtmapi/core/queryKeySerializer.gen.ts +136 -0
  245. package/src/gomtmapi/core/serverSentEvents.gen.ts +266 -0
  246. package/src/gomtmapi/core/types.gen.ts +118 -0
  247. package/src/gomtmapi/core/utils.gen.ts +143 -0
  248. package/src/gomtmapi/index.ts +4 -0
  249. package/src/gomtmapi/schemas.gen.ts +904 -0
  250. package/src/gomtmapi/sdk.gen.ts +541 -0
  251. package/src/gomtmapi/types.gen.ts +1456 -0
  252. package/src/gomtmapi/zod.gen.ts +758 -0
  253. package/src/index.ts +5 -0
  254. package/src/lib/aisdk/types.ts +8 -0
  255. package/src/lib/logger/index.ts +8 -0
  256. package/src/lib/schema.ts +50 -0
  257. package/src/lib/utils.ts +54 -0
  258. package/src/mtgate_api/@tanstack/react-query.gen.ts +175 -0
  259. package/src/mtgate_api/client/client.gen.ts +311 -0
  260. package/src/mtgate_api/client/index.ts +25 -0
  261. package/src/mtgate_api/client/types.gen.ts +241 -0
  262. package/src/mtgate_api/client/utils.gen.ts +332 -0
  263. package/src/mtgate_api/client.gen.ts +16 -0
  264. package/src/mtgate_api/core/auth.gen.ts +42 -0
  265. package/src/mtgate_api/core/bodySerializer.gen.ts +100 -0
  266. package/src/mtgate_api/core/params.gen.ts +176 -0
  267. package/src/mtgate_api/core/pathSerializer.gen.ts +181 -0
  268. package/src/mtgate_api/core/queryKeySerializer.gen.ts +136 -0
  269. package/src/mtgate_api/core/serverSentEvents.gen.ts +266 -0
  270. package/src/mtgate_api/core/types.gen.ts +118 -0
  271. package/src/mtgate_api/core/utils.gen.ts +143 -0
  272. package/src/mtgate_api/index.ts +4 -0
  273. package/src/mtgate_api/schemas.gen.ts +337 -0
  274. package/src/mtgate_api/sdk.gen.ts +61 -0
  275. package/src/mtgate_api/types.gen.ts +324 -0
  276. package/src/mtgate_api/zod.gen.ts +234 -0
  277. package/src/mtmai_api/@tanstack/react-query.gen.ts +1010 -0
  278. package/src/mtmai_api/client/client.gen.ts +311 -0
  279. package/src/mtmai_api/client/index.ts +25 -0
  280. package/src/mtmai_api/client/types.gen.ts +241 -0
  281. package/src/mtmai_api/client/utils.gen.ts +332 -0
  282. package/src/mtmai_api/client.gen.ts +16 -0
  283. package/src/mtmai_api/core/auth.gen.ts +42 -0
  284. package/src/mtmai_api/core/bodySerializer.gen.ts +100 -0
  285. package/src/mtmai_api/core/params.gen.ts +176 -0
  286. package/src/mtmai_api/core/pathSerializer.gen.ts +181 -0
  287. package/src/mtmai_api/core/queryKeySerializer.gen.ts +136 -0
  288. package/src/mtmai_api/core/serverSentEvents.gen.ts +266 -0
  289. package/src/mtmai_api/core/types.gen.ts +118 -0
  290. package/src/mtmai_api/core/utils.gen.ts +143 -0
  291. package/src/mtmai_api/index.ts +4 -0
  292. package/src/mtmai_api/schemas.gen.ts +9980 -0
  293. package/src/mtmai_api/sdk.gen.ts +471 -0
  294. package/src/mtmai_api/types.gen.ts +7609 -0
  295. package/src/mtmai_api/zod.gen.ts +5101 -0
  296. package/src/openclaw/client-info.ts +63 -0
  297. package/src/openclaw/device-auth-utils.ts +31 -0
  298. package/src/openclaw/device-auth.ts +96 -0
  299. package/src/openclaw/device-identity.ts +108 -0
  300. package/src/openclaw/gateway.ts +351 -0
  301. package/src/openclaw/types.ts +518 -0
  302. package/src/openclaw/uuid.ts +48 -0
  303. package/src/sbapi/@tanstack/react-query.gen.ts +6591 -0
  304. package/src/sbapi/client/client.gen.ts +311 -0
  305. package/src/sbapi/client/index.ts +25 -0
  306. package/src/sbapi/client/types.gen.ts +241 -0
  307. package/src/sbapi/client/utils.gen.ts +332 -0
  308. package/src/sbapi/client.gen.ts +16 -0
  309. package/src/sbapi/core/auth.gen.ts +42 -0
  310. package/src/sbapi/core/bodySerializer.gen.ts +100 -0
  311. package/src/sbapi/core/params.gen.ts +176 -0
  312. package/src/sbapi/core/pathSerializer.gen.ts +181 -0
  313. package/src/sbapi/core/queryKeySerializer.gen.ts +136 -0
  314. package/src/sbapi/core/serverSentEvents.gen.ts +266 -0
  315. package/src/sbapi/core/types.gen.ts +118 -0
  316. package/src/sbapi/core/utils.gen.ts +143 -0
  317. package/src/sbapi/index.ts +4 -0
  318. package/src/sbapi/schemas.gen.ts +2643 -0
  319. package/src/sbapi/sdk.gen.ts +2822 -0
  320. package/src/sbapi/types.gen.ts +12503 -0
  321. package/src/sbapi/zod.gen.ts +7021 -0
  322. package/src/sbmng/@tanstack/react-query.gen.ts +2999 -0
  323. package/src/sbmng/client/client.gen.ts +311 -0
  324. package/src/sbmng/client/index.ts +25 -0
  325. package/src/sbmng/client/types.gen.ts +241 -0
  326. package/src/sbmng/client/utils.gen.ts +332 -0
  327. package/src/sbmng/client.gen.ts +16 -0
  328. package/src/sbmng/core/auth.gen.ts +42 -0
  329. package/src/sbmng/core/bodySerializer.gen.ts +100 -0
  330. package/src/sbmng/core/params.gen.ts +176 -0
  331. package/src/sbmng/core/pathSerializer.gen.ts +181 -0
  332. package/src/sbmng/core/queryKeySerializer.gen.ts +136 -0
  333. package/src/sbmng/core/serverSentEvents.gen.ts +266 -0
  334. package/src/sbmng/core/types.gen.ts +118 -0
  335. package/src/sbmng/core/utils.gen.ts +143 -0
  336. package/src/sbmng/index.ts +4 -0
  337. package/src/sbmng/schemas.gen.ts +9680 -0
  338. package/src/sbmng/sdk.gen.ts +1771 -0
  339. package/src/sbmng/types.gen.ts +7956 -0
  340. package/src/supabase/auth-provider.tsx +67 -0
  341. package/src/supabase/context.tsx +51 -0
  342. package/src/supabase/cursor-pagination.ts +155 -0
  343. package/src/supabase/schema/browser.ts +45 -0
  344. package/src/supabase/schema/index.ts +50 -0
  345. package/src/supabase/supabase-client.ts +30 -0
  346. package/src/supabase/supabase.ts +65 -0
  347. package/src/supabase/use-sb-query/build-query-opts.ts +56 -0
  348. package/src/supabase/use-sb-query/key.ts +57 -0
  349. package/src/supabase/use-sb-query/prefetch.ts +59 -0
  350. package/src/supabase/use-sb-query/use-query.ts +340 -0
  351. package/src/supabase/use-sb-query/use-rpc-mutation.ts +83 -0
  352. package/src/supabase/use-sb-query/use-rpc-query.ts +230 -0
  353. package/src/supabase/utils.ts +75 -0
  354. package/src/types/database.schemas.ts +3804 -0
  355. package/src/types/database.types.ts +3828 -0
  356. package/src/types/index.ts +119 -0
  357. package/src/types/rpc.schemas.ts +157 -0
  358. package/dist/gomtmapi_v2/@tanstack/react-query.gen.d.ts.map +0 -1
  359. package/dist/gomtmapi_v2/@tanstack/react-query.gen.js.map +0 -1
  360. package/dist/gomtmapi_v2/client/client.gen.d.ts.map +0 -1
  361. package/dist/gomtmapi_v2/client/client.gen.js.map +0 -1
  362. package/dist/gomtmapi_v2/client/index.d.ts.map +0 -1
  363. package/dist/gomtmapi_v2/client/index.js.map +0 -1
  364. package/dist/gomtmapi_v2/client/types.gen.d.ts.map +0 -1
  365. package/dist/gomtmapi_v2/client/types.gen.js.map +0 -1
  366. package/dist/gomtmapi_v2/client/utils.gen.d.ts.map +0 -1
  367. package/dist/gomtmapi_v2/client/utils.gen.js.map +0 -1
  368. package/dist/gomtmapi_v2/client.gen.d.ts.map +0 -1
  369. package/dist/gomtmapi_v2/client.gen.js.map +0 -1
  370. package/dist/gomtmapi_v2/core/auth.gen.d.ts.map +0 -1
  371. package/dist/gomtmapi_v2/core/auth.gen.js.map +0 -1
  372. package/dist/gomtmapi_v2/core/bodySerializer.gen.d.ts.map +0 -1
  373. package/dist/gomtmapi_v2/core/bodySerializer.gen.js.map +0 -1
  374. package/dist/gomtmapi_v2/core/params.gen.d.ts.map +0 -1
  375. package/dist/gomtmapi_v2/core/params.gen.js.map +0 -1
  376. package/dist/gomtmapi_v2/core/pathSerializer.gen.d.ts.map +0 -1
  377. package/dist/gomtmapi_v2/core/pathSerializer.gen.js.map +0 -1
  378. package/dist/gomtmapi_v2/core/queryKeySerializer.gen.d.ts.map +0 -1
  379. package/dist/gomtmapi_v2/core/queryKeySerializer.gen.js.map +0 -1
  380. package/dist/gomtmapi_v2/core/serverSentEvents.gen.d.ts.map +0 -1
  381. package/dist/gomtmapi_v2/core/serverSentEvents.gen.js.map +0 -1
  382. package/dist/gomtmapi_v2/core/types.gen.d.ts.map +0 -1
  383. package/dist/gomtmapi_v2/core/types.gen.js.map +0 -1
  384. package/dist/gomtmapi_v2/core/utils.gen.d.ts.map +0 -1
  385. package/dist/gomtmapi_v2/core/utils.gen.js.map +0 -1
  386. package/dist/gomtmapi_v2/index.d.ts +0 -3
  387. package/dist/gomtmapi_v2/index.d.ts.map +0 -1
  388. package/dist/gomtmapi_v2/index.js +0 -3
  389. package/dist/gomtmapi_v2/index.js.map +0 -1
  390. package/dist/gomtmapi_v2/schemas.gen.d.ts.map +0 -1
  391. package/dist/gomtmapi_v2/schemas.gen.js.map +0 -1
  392. package/dist/gomtmapi_v2/sdk.gen.d.ts +0 -208
  393. package/dist/gomtmapi_v2/sdk.gen.d.ts.map +0 -1
  394. package/dist/gomtmapi_v2/sdk.gen.js.map +0 -1
  395. package/dist/gomtmapi_v2/types.gen.d.ts.map +0 -1
  396. package/dist/gomtmapi_v2/types.gen.js.map +0 -1
  397. package/dist/gomtmapi_v2/zod.gen.d.ts.map +0 -1
  398. package/dist/gomtmapi_v2/zod.gen.js.map +0 -1
  399. package/dist/opencode/@tanstack/react-query.gen.d.ts +0 -1903
  400. package/dist/opencode/@tanstack/react-query.gen.d.ts.map +0 -1
  401. package/dist/opencode/@tanstack/react-query.gen.js +0 -1696
  402. package/dist/opencode/@tanstack/react-query.gen.js.map +0 -1
  403. package/dist/opencode/client/client.gen.d.ts +0 -3
  404. package/dist/opencode/client/client.gen.js +0 -236
  405. package/dist/opencode/client/index.d.ts +0 -9
  406. package/dist/opencode/client/index.js +0 -7
  407. package/dist/opencode/client/types.gen.d.ts +0 -118
  408. package/dist/opencode/client/types.gen.js +0 -3
  409. package/dist/opencode/client/types.gen.js.map +0 -1
  410. package/dist/opencode/client/utils.gen.d.ts +0 -34
  411. package/dist/opencode/client/utils.gen.js +0 -232
  412. package/dist/opencode/client.gen.js +0 -4
  413. package/dist/opencode/core/auth.gen.d.ts +0 -19
  414. package/dist/opencode/core/auth.gen.js +0 -15
  415. package/dist/opencode/core/bodySerializer.gen.d.ts +0 -26
  416. package/dist/opencode/core/bodySerializer.gen.js +0 -58
  417. package/dist/opencode/core/params.gen.d.ts +0 -44
  418. package/dist/opencode/core/params.gen.js +0 -101
  419. package/dist/opencode/core/pathSerializer.gen.d.ts +0 -34
  420. package/dist/opencode/core/pathSerializer.gen.js +0 -115
  421. package/dist/opencode/core/queryKeySerializer.gen.d.ts +0 -19
  422. package/dist/opencode/core/queryKeySerializer.gen.js +0 -100
  423. package/dist/opencode/core/serverSentEvents.gen.d.ts +0 -72
  424. package/dist/opencode/core/serverSentEvents.gen.js +0 -138
  425. package/dist/opencode/core/types.gen.d.ts +0 -79
  426. package/dist/opencode/core/types.gen.js +0 -3
  427. package/dist/opencode/core/types.gen.js.map +0 -1
  428. package/dist/opencode/core/utils.gen.d.ts +0 -20
  429. package/dist/opencode/core/utils.gen.js +0 -88
  430. package/dist/opencode/index.d.ts +0 -3
  431. package/dist/opencode/index.d.ts.map +0 -1
  432. package/dist/opencode/index.js +0 -4
  433. package/dist/opencode/index.js.map +0 -1
  434. package/dist/opencode/schemas.gen.d.ts +0 -4823
  435. package/dist/opencode/schemas.gen.d.ts.map +0 -1
  436. package/dist/opencode/schemas.gen.js +0 -5816
  437. package/dist/opencode/schemas.gen.js.map +0 -1
  438. package/dist/opencode/sdk.gen.d.ts +0 -562
  439. package/dist/opencode/sdk.gen.d.ts.map +0 -1
  440. package/dist/opencode/sdk.gen.js +0 -766
  441. package/dist/opencode/sdk.gen.js.map +0 -1
  442. package/dist/opencode/types.gen.d.ts +0 -4213
  443. package/dist/opencode/types.gen.d.ts.map +0 -1
  444. package/dist/opencode/types.gen.js +0 -25
  445. package/dist/opencode/types.gen.js.map +0 -1
  446. package/dist/opencode/zod.gen.d.ts +0 -17243
  447. package/dist/opencode/zod.gen.d.ts.map +0 -1
  448. package/dist/opencode/zod.gen.js +0 -2876
  449. package/dist/opencode/zod.gen.js.map +0 -1
  450. package/dist/schema/browser.d.ts.map +0 -1
  451. package/dist/schema/browser.js.map +0 -1
  452. /package/dist/{gomtmapi_v2 → gomtmapi}/client/client.gen.d.ts +0 -0
  453. /package/dist/{gomtmapi_v2 → gomtmapi}/client/client.gen.js +0 -0
  454. /package/dist/{gomtmapi_v2 → gomtmapi}/client/index.d.ts +0 -0
  455. /package/dist/{gomtmapi_v2 → gomtmapi}/client/index.js +0 -0
  456. /package/dist/{gomtmapi_v2 → gomtmapi}/client/types.gen.d.ts +0 -0
  457. /package/dist/{gomtmapi_v2 → gomtmapi}/client/types.gen.js +0 -0
  458. /package/dist/{gomtmapi_v2 → gomtmapi}/client/utils.gen.d.ts +0 -0
  459. /package/dist/{gomtmapi_v2 → gomtmapi}/client/utils.gen.js +0 -0
  460. /package/dist/{gomtmapi_v2 → gomtmapi}/client.gen.d.ts +0 -0
  461. /package/dist/{gomtmapi_v2 → gomtmapi}/client.gen.js +0 -0
  462. /package/dist/{gomtmapi_v2 → gomtmapi}/core/auth.gen.d.ts +0 -0
  463. /package/dist/{gomtmapi_v2 → gomtmapi}/core/auth.gen.js +0 -0
  464. /package/dist/{gomtmapi_v2 → gomtmapi}/core/bodySerializer.gen.d.ts +0 -0
  465. /package/dist/{gomtmapi_v2 → gomtmapi}/core/bodySerializer.gen.js +0 -0
  466. /package/dist/{gomtmapi_v2 → gomtmapi}/core/params.gen.d.ts +0 -0
  467. /package/dist/{gomtmapi_v2 → gomtmapi}/core/params.gen.js +0 -0
  468. /package/dist/{gomtmapi_v2 → gomtmapi}/core/pathSerializer.gen.d.ts +0 -0
  469. /package/dist/{gomtmapi_v2 → gomtmapi}/core/pathSerializer.gen.js +0 -0
  470. /package/dist/{gomtmapi_v2 → gomtmapi}/core/queryKeySerializer.gen.d.ts +0 -0
  471. /package/dist/{gomtmapi_v2 → gomtmapi}/core/queryKeySerializer.gen.js +0 -0
  472. /package/dist/{gomtmapi_v2 → gomtmapi}/core/serverSentEvents.gen.d.ts +0 -0
  473. /package/dist/{gomtmapi_v2 → gomtmapi}/core/serverSentEvents.gen.js +0 -0
  474. /package/dist/{gomtmapi_v2 → gomtmapi}/core/types.gen.d.ts +0 -0
  475. /package/dist/{gomtmapi_v2 → gomtmapi}/core/types.gen.js +0 -0
  476. /package/dist/{gomtmapi_v2 → gomtmapi}/core/utils.gen.d.ts +0 -0
  477. /package/dist/{gomtmapi_v2 → gomtmapi}/core/utils.gen.js +0 -0
  478. /package/dist/{gomtmapi_v2 → gomtmapi}/types.gen.js +0 -0
  479. /package/dist/{schema → supabase/schema}/browser.d.ts +0 -0
  480. /package/dist/{schema → supabase/schema}/browser.js +0 -0
@@ -0,0 +1,67 @@
1
+ "use client";
2
+
3
+ import type { Session } from "@supabase/supabase-js";
4
+ import { createContext, useContext, useEffect, useMemo, useState, type PropsWithChildren, type ReactNode } from "react";
5
+ import { useSupabaseBrowser } from "./context";
6
+
7
+ interface SupabaseAuthContextType {
8
+ session: Session | null;
9
+ token: string | undefined;
10
+ isLoading: boolean;
11
+ }
12
+
13
+ const SupabaseAuthContext = createContext<SupabaseAuthContextType | undefined>(undefined);
14
+
15
+ export function useSupabaseAuth() {
16
+ const context = useContext(SupabaseAuthContext);
17
+ if (context === undefined) {
18
+ throw new Error("useSupabaseAuth must be used within a SupabaseAuthProvider");
19
+ }
20
+ return context;
21
+ }
22
+
23
+ export function SupabaseAuthProvider({ children }: PropsWithChildren): ReactNode {
24
+ const sb = useSupabaseBrowser();
25
+ const [session, setSession] = useState<Session | null>(null);
26
+ const [isLoading, setIsLoading] = useState(true);
27
+
28
+ useEffect(() => {
29
+ let mounted = true;
30
+
31
+ async function loadSession() {
32
+ const {
33
+ data: { session },
34
+ } = await sb.auth.getSession();
35
+ if (mounted) {
36
+ setSession(session);
37
+ setIsLoading(false);
38
+ }
39
+ }
40
+ loadSession();
41
+
42
+ const {
43
+ data: { subscription },
44
+ } = sb.auth.onAuthStateChange((_event, session) => {
45
+ if (mounted) {
46
+ setSession(session);
47
+ setIsLoading(false);
48
+ }
49
+ });
50
+
51
+ return () => {
52
+ mounted = false;
53
+ subscription.unsubscribe();
54
+ };
55
+ }, [sb]);
56
+
57
+ const value = useMemo(
58
+ () => ({
59
+ session,
60
+ token: session?.access_token,
61
+ isLoading,
62
+ }),
63
+ [session, isLoading],
64
+ );
65
+
66
+ return <SupabaseAuthContext.Provider value={value}>{children}</SupabaseAuthContext.Provider>;
67
+ }
@@ -0,0 +1,51 @@
1
+ "use client";
2
+
3
+ import { createBrowserClient } from "@supabase/ssr";
4
+ import { createContext, type ReactNode, useContext, useMemo } from "react";
5
+ import type { TypedSupabaseClient } from "../types";
6
+ import type { Database } from "../types/database.types";
7
+
8
+ let client: TypedSupabaseClient | undefined;
9
+
10
+ export function getSupabaseBrowserClient(url?: string, key?: string): TypedSupabaseClient {
11
+ if (url && key) {
12
+ return createBrowserClient<Database>(url, key);
13
+ }
14
+ if (!client) {
15
+ client = createBrowserClient<Database>(
16
+ // biome-ignore lint/style/noNonNullAssertion: .
17
+ process.env.NEXT_PUBLIC_SUPABASE_URL!,
18
+ // biome-ignore lint/style/noNonNullAssertion: .
19
+ process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
20
+ );
21
+ }
22
+ // biome-ignore lint/style/noNonNullAssertion: 已经确保了初始化
23
+ return client!;
24
+ }
25
+
26
+ export const SupabaseContext = createContext<TypedSupabaseClient | undefined>(undefined);
27
+
28
+ export function useSupabaseContext(): TypedSupabaseClient {
29
+ const ctx = useContext(SupabaseContext);
30
+ if (!ctx) {
31
+ throw new Error("useSupabaseContext must be used within a SupabaseProvider");
32
+ }
33
+ return ctx;
34
+ }
35
+ export const useSupabaseBrowser = useSupabaseContext;
36
+
37
+ interface SupabaseClientProviderProps {
38
+ children: ReactNode;
39
+ publicKey?: string;
40
+ url?: string;
41
+ }
42
+
43
+ export const SupabaseClientProvider = ({ children, publicKey, url }: SupabaseClientProviderProps): ReactNode => {
44
+ const client = useMemo(() => getSupabaseBrowserClient(url, publicKey), [url, publicKey]);
45
+
46
+ return (
47
+ <SupabaseContext.Provider value={client}>
48
+ {children}
49
+ </SupabaseContext.Provider>
50
+ );
51
+ };
@@ -0,0 +1,155 @@
1
+ /**
2
+ * 游标分页工具函数
3
+ *
4
+ * 提供类型安全的游标分页支持,配合 react-query 的 useInfiniteQuery 使用。
5
+ *
6
+ * @module mtmsdk/supabase/cursor-pagination
7
+ */
8
+
9
+ /**
10
+ * 游标类型定义
11
+ *
12
+ * 使用复合游标 (updated_at + id) 确保分页的唯一性和稳定性
13
+ */
14
+ export interface CursorPagination {
15
+ cursor: string | null; // ISO 时间戳字符串, 如 "2026-01-20T08:00:00Z"
16
+ cursorId: string | null; // UUID 字符串
17
+ }
18
+
19
+ /**
20
+ * 从数据列表中提取下一页游标
21
+ *
22
+ * @param items - 当前页的数据列表
23
+ * @param limit - 每页数量
24
+ * @param cursorField - 游标字段名 (默认 "updated_at")
25
+ * @param idField - ID 字段名 (默认 "id")
26
+ * @returns 下一页游标, 如果没有更多数据则返回 undefined
27
+ *
28
+ * @example
29
+ * ```tsx
30
+ * const { data, fetchNextPage, hasNextPage } = useInfiniteQuery({
31
+ * queryKey: ['projects', kw],
32
+ * queryFn: async ({ pageParam }) => {
33
+ * const { data } = await sb.rpc('audit_project_list_cursor', {
34
+ * p_cursor: pageParam?.cursor ?? null,
35
+ * p_cursor_id: pageParam?.cursorId ?? null,
36
+ * p_limit: 20,
37
+ * p_kw: kw
38
+ * });
39
+ * return data ?? [];
40
+ * },
41
+ * getNextPageParam: (lastPage) => getNextCursor(lastPage, 20),
42
+ * initialPageParam: null as CursorPagination | null
43
+ * });
44
+ * ```
45
+ */
46
+ export function getNextCursor<
47
+ T extends Record<string, unknown>,
48
+ >(
49
+ items: T[] | null | undefined,
50
+ limit: number,
51
+ cursorField: keyof T = "updated_at" as keyof T,
52
+ idField: keyof T = "id" as keyof T,
53
+ ): CursorPagination | undefined {
54
+ // 如果数据为空或数量小于 limit,说明已到达最后一页
55
+ if (!items || items.length < limit) {
56
+ return undefined;
57
+ }
58
+
59
+ // 获取最后一条记录
60
+ const lastItem = items[items.length - 1];
61
+ if (!lastItem) {
62
+ return undefined;
63
+ }
64
+
65
+ const cursorValue = lastItem[cursorField];
66
+ const idValue = lastItem[idField];
67
+
68
+ // 验证游标值有效性
69
+ if (cursorValue === undefined || cursorValue === null) {
70
+ return undefined;
71
+ }
72
+
73
+ return {
74
+ cursor: String(cursorValue),
75
+ cursorId: idValue != null ? String(idValue) : null,
76
+ };
77
+ }
78
+
79
+ /**
80
+ * 将所有分页数据合并为单一列表
81
+ *
82
+ * @param pages - useInfiniteQuery 返回的 pages 数组
83
+ * @returns 合并后的扁平数据列表
84
+ *
85
+ * @example
86
+ * ```tsx
87
+ * const { data } = useInfiniteQuery({ ... });
88
+ * const allProjects = flattenPages(data?.pages);
89
+ * ```
90
+ */
91
+ export function flattenPages<T>(
92
+ pages: T[][] | undefined,
93
+ ): T[] {
94
+ if (!pages) return [];
95
+ return pages.flat();
96
+ }
97
+
98
+ /**
99
+ * 无限滚动分页状态
100
+ */
101
+ export interface InfiniteScrollState {
102
+ isLoading: boolean;
103
+ isFetchingNextPage: boolean;
104
+ hasNextPage: boolean;
105
+ error: Error | null;
106
+ }
107
+
108
+ /**
109
+ * 创建 IntersectionObserver 用于无限滚动
110
+ *
111
+ * @param onIntersect - 当元素进入视口时的回调
112
+ * @param options - IntersectionObserver 配置选项
113
+ * @returns cleanup 函数
114
+ *
115
+ * @example
116
+ * ```tsx
117
+ * const loadMoreRef = useRef<HTMLDivElement>(null);
118
+ *
119
+ * useEffect(() => {
120
+ * if (!loadMoreRef.current) return;
121
+ * return createInfiniteScrollObserver(
122
+ * () => {
123
+ * if (hasNextPage && !isFetchingNextPage) {
124
+ * fetchNextPage();
125
+ * }
126
+ * },
127
+ * { root: scrollContainerRef.current }
128
+ * )(loadMoreRef.current);
129
+ * }, [hasNextPage, isFetchingNextPage, fetchNextPage]);
130
+ * ```
131
+ */
132
+ export function createInfiniteScrollObserver(
133
+ onIntersect: () => void,
134
+ options?: IntersectionObserverInit,
135
+ ): (element: Element) => () => void {
136
+ return (element: Element) => {
137
+ const observer = new IntersectionObserver((entries) => {
138
+ const [entry] = entries;
139
+ if (entry?.isIntersecting) {
140
+ onIntersect();
141
+ }
142
+ }, {
143
+ root: null,
144
+ rootMargin: "100px",
145
+ threshold: 0.1,
146
+ ...options,
147
+ });
148
+
149
+ observer.observe(element);
150
+
151
+ return () => {
152
+ observer.disconnect();
153
+ };
154
+ };
155
+ }
@@ -0,0 +1,45 @@
1
+ import z from "zod";
2
+
3
+ export const zRpcBaseResponse = z.object({
4
+ error: z.object({
5
+ message: z.string(),
6
+ }),
7
+ });
8
+ export const zBrowserUpsertArgs = z
9
+ .object({
10
+ id: z.string().nullish(),//.transform( x => x ?? undefined ),
11
+ title: z.string(),
12
+ profile_id: z.string().nullish(),//.transform( x => x ?? undefined ),
13
+ description: z.string().nullish()//.transform( x => x ?? undefined ),
14
+ })
15
+ .meta({ ref: "BrowserUpsertArgs" });
16
+
17
+ export const zBrowserListReq = z
18
+ .object({
19
+ kw: z.string().optional(),
20
+ })
21
+ .describe("BrowserListReq")
22
+ .meta({ ref: "BrowserListReq" });
23
+
24
+ const zBrowserItem = z
25
+ .object({
26
+ id: z.string(),
27
+ title: z.string(),
28
+ })
29
+ .describe("BrowserItem")
30
+ .meta({ ref: "BrowserItem" });
31
+
32
+ export const zBrowserData = z
33
+ .object({
34
+ id: z.string(),
35
+ title: z.string(),
36
+ })
37
+ .describe("BrowserData")
38
+ .meta({ ref: "BrowserData" });
39
+
40
+ export const zBrowserListResponse = zRpcBaseResponse
41
+ .extend({
42
+ data: z.array(zBrowserItem),
43
+ })
44
+ // .describe("BrowserProfileResponse")
45
+ .meta({ ref: "BrowserList" });
@@ -0,0 +1,50 @@
1
+ import z from "zod";
2
+
3
+ const singleRowPreprocessor = (val: unknown) => {
4
+ if (Array.isArray(val)) {
5
+ if (val.length === 0) return null;
6
+ if (val.length === 1) return val[0];
7
+ }
8
+ return val;
9
+ };
10
+
11
+ export const gatewayUrlConfigSchema = z.preprocess(
12
+ singleRowPreprocessor,
13
+ z
14
+ .object({
15
+ mtgate_url: z.string().url({ message: "必须是有效的 URL" }).optional().or(z.literal("")),
16
+ })
17
+ .nullable(),
18
+ );
19
+
20
+ export const domainConfigSchema = z.preprocess(
21
+ singleRowPreprocessor,
22
+ z
23
+ .object({
24
+ primary_domain: z.string().min(1, "主域名不能为空"),
25
+ worker_subdomain_prefix: z.string().optional().default(""),
26
+ })
27
+ .nullable(),
28
+ );
29
+
30
+ export const sharedServerGetSchema = z.preprocess(
31
+ singleRowPreprocessor,
32
+ z
33
+ .object({
34
+ id: z.string(),
35
+ name: z.string(),
36
+ url: z.string().nullable().optional(),
37
+ is_shared: z.boolean(),
38
+ })
39
+ .nullable(),
40
+ );
41
+
42
+ export const smsProviderConfigSchema = z.object({
43
+ default_provider: z.enum(["manual", "demo"]).optional().default("manual"),
44
+ });
45
+
46
+ export const geminiProxyConfigSchema = z.object({
47
+ default_model: z.string().optional().default("gemini-1.5-pro"),
48
+ model_mapping: z.record(z.string(), z.string()).optional().default({}),
49
+ api_version: z.enum(["v1", "v1beta"]).optional().default("v1"),
50
+ });
@@ -0,0 +1,30 @@
1
+ import { createServerClient } from "@supabase/ssr";
2
+ import type { cookies } from "next/headers";
3
+ import type { Database } from "../types/database.types";
4
+
5
+ export function useSupabaseServer(
6
+ cookieStore: Awaited<ReturnType<typeof cookies>>,
7
+ ) {
8
+ return createServerClient<Database>(
9
+ process.env.NEXT_PUBLIC_SUPABASE_URL!,
10
+ process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
11
+ {
12
+ cookies: {
13
+ getAll() {
14
+ return cookieStore.getAll();
15
+ },
16
+ setAll(cookiesToSet) {
17
+ try {
18
+ for (const co of cookiesToSet) {
19
+ cookieStore.set(co.name, co.value, co.options);
20
+ }
21
+ } catch (e) {
22
+ //!!! 提示,对于nextjs + honoapi 后端方式使用,可能出现以下错误:
23
+ // Cookies can only be modified in a Server Action or Route Handler. Read more: https://nextjs.org/docs/app/api-reference/functions/cookies#options
24
+ //可以直接忽略.
25
+ }
26
+ },
27
+ },
28
+ },
29
+ );
30
+ }
@@ -0,0 +1,65 @@
1
+ import { createServerClient, parseCookieHeader } from "@supabase/ssr";
2
+ import { createClient } from "@supabase/supabase-js";
3
+ import type { Context } from "hono";
4
+ import { setCookie } from "hono/cookie";
5
+ import type { TypedSupabaseClient } from "../types";
6
+
7
+ export const getSupabaseUrl = () => {
8
+ if (!process.env.NEXT_PUBLIC_SUPABASE_URL) {
9
+ throw new Error("NEXT_PUBLIC_SUPABASE_URL missing!");
10
+ }
11
+ return process.env.NEXT_PUBLIC_SUPABASE_URL;
12
+ };
13
+ export const getSupabasePublicKey = () => {
14
+ if (!process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY) {
15
+ throw new Error("NEXT_PUBLIC_SUPABASE_ANON_KEY missing!");
16
+ }
17
+ return process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
18
+ };
19
+
20
+ export const getSupabaseProjectRef = () => {
21
+ const uri = new URL(getSupabaseUrl());
22
+ const supabasePrject = uri.hostname.split(".")[0];
23
+ return supabasePrject;
24
+ };
25
+
26
+ export const getSupabase = (c: Context) => {
27
+ const client: TypedSupabaseClient = createServerClient(getSupabaseUrl(), getSupabasePublicKey(), {
28
+ cookies: {
29
+ //@ts-expect-error
30
+ getAll() {
31
+ return parseCookieHeader(c.req.header("Cookie") ?? "");
32
+ },
33
+ setAll(cookiesToSet) {
34
+ for (const co of cookiesToSet) {
35
+ //@ts-expect-error
36
+ setCookie(c, co.name, co.value, co.options);
37
+ }
38
+ },
39
+ },
40
+ global: {
41
+ // 由于gomtm supabase 客户端已经登录.所以这里直接传递 Authorization 头,即可.
42
+ headers: {
43
+ ...(c.req.header("Authorization") && {
44
+ Authorization: c.req.header("Authorization"),
45
+ }),
46
+ },
47
+ },
48
+ });
49
+ return client;
50
+ };
51
+
52
+ export const getSupabaseAdmin = () => {
53
+ const serviceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
54
+ if (!serviceRoleKey) {
55
+ throw new Error("require SUPABASE_SERVICE_ROLE_KEY");
56
+ }
57
+ const client: TypedSupabaseClient = createClient(getSupabaseUrl(), serviceRoleKey, {
58
+ auth: {
59
+ autoRefreshToken: false,
60
+ persistSession: false,
61
+ },
62
+ });
63
+
64
+ return client;
65
+ };
@@ -0,0 +1,56 @@
1
+ import {
2
+ type AnyPostgrestResponse,
3
+ isPostgrestBuilder,
4
+ isPostgrestTransformBuilder,
5
+ } from "@supabase-cache-helpers/postgrest-core";
6
+ import type { PostgrestError } from "@supabase/postgrest-js";
7
+ import type {
8
+ UseQueryOptions as UseReactQueryOptions,
9
+ UseSuspenseQueryOptions,
10
+ } from "@tanstack/react-query";
11
+
12
+ import { encode } from "./key";
13
+
14
+ export function buildQueryOpts<Result>(
15
+ query: PromiseLike<AnyPostgrestResponse<Result>>,
16
+ config?: Omit<
17
+ UseReactQueryOptions<AnyPostgrestResponse<Result>, PostgrestError>,
18
+ "queryKey" | "queryFn"
19
+ >,
20
+ ): UseReactQueryOptions<AnyPostgrestResponse<Result>, PostgrestError> {
21
+ return {
22
+ queryKey: encode<Result>(query, false),
23
+ queryFn: async ({ signal }) => {
24
+ if (isPostgrestTransformBuilder(query)) {
25
+ query = query.abortSignal(signal);
26
+ }
27
+ if (isPostgrestBuilder(query)) {
28
+ query = query.throwOnError();
29
+ }
30
+ return await query;
31
+ },
32
+ ...config,
33
+ };
34
+ }
35
+
36
+ export function buildSuspenseQueryOpts<Result>(
37
+ query: PromiseLike<AnyPostgrestResponse<Result>>,
38
+ config?: Omit<
39
+ UseSuspenseQueryOptions<AnyPostgrestResponse<Result>, PostgrestError>,
40
+ "queryKey" | "queryFn"
41
+ >,
42
+ ): UseSuspenseQueryOptions<AnyPostgrestResponse<Result>, PostgrestError> {
43
+ return {
44
+ queryKey: encode<Result>(query, false),
45
+ queryFn: async ({ signal }) => {
46
+ if (isPostgrestTransformBuilder(query)) {
47
+ query = query.abortSignal(signal);
48
+ }
49
+ if (isPostgrestBuilder(query)) {
50
+ query = query.throwOnError();
51
+ }
52
+ return await query;
53
+ },
54
+ ...config,
55
+ };
56
+ }
@@ -0,0 +1,57 @@
1
+ import { type DecodedKey, isPostgrestBuilder, PostgrestParser } from "@supabase-cache-helpers/postgrest-core";
2
+
3
+ export const KEY_PREFIX = "postgrest";
4
+ export const INFINITE_KEY_PREFIX = "page";
5
+
6
+ export type DecodedReactQueryKey = DecodedKey & {
7
+ isInfinite: boolean;
8
+ key: string[];
9
+ };
10
+
11
+ export const encode = <Result>(key: unknown, isInfinite: boolean): string[] => {
12
+ if (!isPostgrestBuilder<Result>(key)) {
13
+ throw new Error("Key is not a PostgrestBuilder");
14
+ }
15
+
16
+ const parser = new PostgrestParser<Result>(key);
17
+ return [
18
+ KEY_PREFIX,
19
+ isInfinite ? INFINITE_KEY_PREFIX : "null",
20
+ parser.schema,
21
+ parser.table,
22
+ parser.queryKey,
23
+ parser.bodyKey ?? "null",
24
+ `count=${parser.count}`,
25
+ `head=${parser.isHead}`,
26
+ parser.orderByKey,
27
+ ];
28
+ };
29
+
30
+ export const decode = (key: unknown): DecodedReactQueryKey | null => {
31
+ if (!Array.isArray(key)) return null;
32
+
33
+ const [prefix, infinitePrefix, schema, table, queryKey, bodyKey, count, head, orderByKey] = key;
34
+
35
+ // Exit early if not a postgrest key
36
+ if (prefix !== KEY_PREFIX) return null;
37
+
38
+ const params = new URLSearchParams(queryKey);
39
+ const limit = params.get("limit");
40
+ const offset = params.get("offset");
41
+
42
+ const countValue = count.replace("count=", "");
43
+
44
+ return {
45
+ limit: limit ? Number(limit) : undefined,
46
+ offset: offset ? Number(offset) : undefined,
47
+ bodyKey,
48
+ count: countValue === "null" ? null : countValue,
49
+ isHead: head === "head=true",
50
+ isInfinite: infinitePrefix === INFINITE_KEY_PREFIX,
51
+ key,
52
+ queryKey,
53
+ schema,
54
+ table,
55
+ orderByKey,
56
+ };
57
+ };
@@ -0,0 +1,59 @@
1
+ import { type AnyPostgrestResponse, isPostgrestBuilder } from "@supabase-cache-helpers/postgrest-core";
2
+ import type {
3
+ PostgrestError,
4
+ PostgrestMaybeSingleResponse,
5
+ PostgrestResponse,
6
+ PostgrestSingleResponse,
7
+ } from "@supabase/postgrest-js";
8
+ import type { FetchQueryOptions, QueryClient } from "@tanstack/react-query";
9
+ import { buildQueryOpts } from "./build-query-opts";
10
+ import { encode } from "./key";
11
+
12
+ function prefetchQuery<Result>(
13
+ queryClient: QueryClient,
14
+ query: PromiseLike<PostgrestSingleResponse<Result>>,
15
+ config?: Omit<FetchQueryOptions<PostgrestSingleResponse<Result>, PostgrestError>, "queryKey" | "queryFn">,
16
+ ): Promise<void>;
17
+ function prefetchQuery<Result>(
18
+ queryClient: QueryClient,
19
+ query: PromiseLike<PostgrestMaybeSingleResponse<Result>>,
20
+ config?: Omit<FetchQueryOptions<PostgrestMaybeSingleResponse<Result>, PostgrestError>, "queryKey" | "queryFn">,
21
+ ): Promise<void>;
22
+ function prefetchQuery<Result>(
23
+ queryClient: QueryClient,
24
+ query: PromiseLike<PostgrestResponse<Result>>,
25
+ config?: Omit<FetchQueryOptions<PostgrestResponse<Result>, PostgrestError>, "queryKey" | "queryFn">,
26
+ ): Promise<void>;
27
+
28
+ async function prefetchQuery<Result>(
29
+ queryClient: QueryClient,
30
+ query: PromiseLike<AnyPostgrestResponse<Result>>,
31
+ config?: Omit<FetchQueryOptions<AnyPostgrestResponse<Result>, PostgrestError>, "queryKey" | "queryFn">,
32
+ ) {
33
+ await queryClient.prefetchQuery<AnyPostgrestResponse<Result>, PostgrestError>(buildQueryOpts(query, config));
34
+ }
35
+
36
+ function fetchQueryInitialData<Result>(
37
+ query: PromiseLike<PostgrestSingleResponse<Result>>,
38
+ ): Promise<[string[], PostgrestSingleResponse<Result>]>;
39
+
40
+ function fetchQueryInitialData<Result>(
41
+ query: PromiseLike<PostgrestMaybeSingleResponse<Result>>,
42
+ ): Promise<[string[], PostgrestMaybeSingleResponse<Result>]>;
43
+
44
+ function fetchQueryInitialData<Result>(
45
+ query: PromiseLike<PostgrestResponse<Result>>,
46
+ ): Promise<[string[], PostgrestResponse<Result>]>;
47
+
48
+ async function fetchQueryInitialData<Result>(
49
+ query: PromiseLike<AnyPostgrestResponse<Result>>,
50
+ ): Promise<[string[], AnyPostgrestResponse<Result>]> {
51
+ if (!isPostgrestBuilder<Result>(query)) {
52
+ throw new Error("Query is not a PostgrestBuilder");
53
+ }
54
+
55
+ return [encode(query, false), await query.throwOnError()];
56
+ }
57
+
58
+ export { fetchQueryInitialData, prefetchQuery };
59
+