@tencent-rtc/mcp 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 (286) hide show
  1. package/@tencent/aegis-node-sdk/CHANGELOG.md +8 -0
  2. package/@tencent/aegis-node-sdk/LICENSE +21 -0
  3. package/@tencent/aegis-node-sdk/README.md +562 -0
  4. package/@tencent/aegis-node-sdk/lib/aegis.min.js +1 -0
  5. package/@tencent/aegis-node-sdk/lib/packages/core/src/constant/config.d.ts +14 -0
  6. package/@tencent/aegis-node-sdk/lib/packages/core/src/constant/global.d.ts +1 -0
  7. package/@tencent/aegis-node-sdk/lib/packages/core/src/constant/index.d.ts +9 -0
  8. package/@tencent/aegis-node-sdk/lib/packages/core/src/constant/report-ignore.d.ts +2 -0
  9. package/@tencent/aegis-node-sdk/lib/packages/core/src/core.d.ts +85 -0
  10. package/@tencent/aegis-node-sdk/lib/packages/core/src/hooks/afterRequestHooks.d.ts +3 -0
  11. package/@tencent/aegis-node-sdk/lib/packages/core/src/hooks/beforeRequestHooks.d.ts +9 -0
  12. package/@tencent/aegis-node-sdk/lib/packages/core/src/hooks/modifyRequestHooks.d.ts +3 -0
  13. package/@tencent/aegis-node-sdk/lib/packages/core/src/index.d.ts +9 -0
  14. package/@tencent/aegis-node-sdk/lib/packages/core/src/interface/config.d.ts +62 -0
  15. package/@tencent/aegis-node-sdk/lib/packages/core/src/interface/env.d.ts +11 -0
  16. package/@tencent/aegis-node-sdk/lib/packages/core/src/interface/index.d.ts +4 -0
  17. package/@tencent/aegis-node-sdk/lib/packages/core/src/interface/log.d.ts +130 -0
  18. package/@tencent/aegis-node-sdk/lib/packages/core/src/interface/send.d.ts +34 -0
  19. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/format.d.ts +2 -0
  20. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/index.d.ts +18 -0
  21. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/length-limit.d.ts +8 -0
  22. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/pv.d.ts +8 -0
  23. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/remove-payload.d.ts +2 -0
  24. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/repeat-limit.d.ts +4 -0
  25. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/report.d.ts +10 -0
  26. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/sample.d.ts +3 -0
  27. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/throttle.d.ts +3 -0
  28. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/trace/index.d.ts +34 -0
  29. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/trace/jwt.d.ts +12 -0
  30. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/trace/ot-js.d.ts +14 -0
  31. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/trace/uuid.d.ts +2 -0
  32. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/whitelist.d.ts +12 -0
  33. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/write-before.d.ts +3 -0
  34. package/@tencent/aegis-node-sdk/lib/packages/core/src/plugin.d.ts +33 -0
  35. package/@tencent/aegis-node-sdk/lib/packages/core/src/polyfill.d.ts +0 -0
  36. package/@tencent/aegis-node-sdk/lib/packages/core/src/util/destroy.d.ts +2 -0
  37. package/@tencent/aegis-node-sdk/lib/packages/core/src/util/event-emitter.d.ts +18 -0
  38. package/@tencent/aegis-node-sdk/lib/packages/core/src/util/index.d.ts +60 -0
  39. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/index.d.ts +15 -0
  40. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/interface/selector.d.ts +5 -0
  41. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/pipes/batch-report-pipe.d.ts +6 -0
  42. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/protocol/protocol_base.d.ts +18 -0
  43. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/protocol/protocol_http.d.ts +12 -0
  44. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/selector/ip_selector.d.ts +10 -0
  45. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/selector/polaris_selector.d.ts +20 -0
  46. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/selector/selector_base.d.ts +27 -0
  47. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/util/eval_require.d.ts +2 -0
  48. package/@tencent/aegis-node-sdk/package.json +19 -0
  49. package/@tencent/polaris/README.md +407 -0
  50. package/@tencent/polaris/dist/consumer/health.d.ts +126 -0
  51. package/@tencent/polaris/dist/consumer/health.js +283 -0
  52. package/@tencent/polaris/dist/consumer/health.js.map +1 -0
  53. package/@tencent/polaris/dist/consumer/index.d.ts +120 -0
  54. package/@tencent/polaris/dist/consumer/index.js +348 -0
  55. package/@tencent/polaris/dist/consumer/index.js.map +1 -0
  56. package/@tencent/polaris/dist/consumer/monitor.d.ts +145 -0
  57. package/@tencent/polaris/dist/consumer/monitor.js +343 -0
  58. package/@tencent/polaris/dist/consumer/monitor.js.map +1 -0
  59. package/@tencent/polaris/dist/consumer/selector.d.ts +73 -0
  60. package/@tencent/polaris/dist/consumer/selector.js +316 -0
  61. package/@tencent/polaris/dist/consumer/selector.js.map +1 -0
  62. package/@tencent/polaris/dist/errors.d.ts +373 -0
  63. package/@tencent/polaris/dist/errors.js +154 -0
  64. package/@tencent/polaris/dist/errors.js.map +1 -0
  65. package/@tencent/polaris/dist/global.d.ts +16 -0
  66. package/@tencent/polaris/dist/global.js +18 -0
  67. package/@tencent/polaris/dist/global.js.map +1 -0
  68. package/@tencent/polaris/dist/index.d.ts +62 -0
  69. package/@tencent/polaris/dist/index.js +145 -0
  70. package/@tencent/polaris/dist/index.js.map +1 -0
  71. package/@tencent/polaris/dist/instance.d.ts +109 -0
  72. package/@tencent/polaris/dist/instance.js +38 -0
  73. package/@tencent/polaris/dist/instance.js.map +1 -0
  74. package/@tencent/polaris/dist/limiter/bucket.d.ts +51 -0
  75. package/@tencent/polaris/dist/limiter/bucket.js +152 -0
  76. package/@tencent/polaris/dist/limiter/bucket.js.map +1 -0
  77. package/@tencent/polaris/dist/limiter/index.d.ts +73 -0
  78. package/@tencent/polaris/dist/limiter/index.js +149 -0
  79. package/@tencent/polaris/dist/limiter/index.js.map +1 -0
  80. package/@tencent/polaris/dist/limiter/ratelimit.d.ts +27 -0
  81. package/@tencent/polaris/dist/limiter/ratelimit.js +134 -0
  82. package/@tencent/polaris/dist/limiter/ratelimit.js.map +1 -0
  83. package/@tencent/polaris/dist/limiter/ratelimiter/base.d.ts +17 -0
  84. package/@tencent/polaris/dist/limiter/ratelimiter/base.js +15 -0
  85. package/@tencent/polaris/dist/limiter/ratelimiter/base.js.map +1 -0
  86. package/@tencent/polaris/dist/limiter/ratelimiter/global.d.ts +59 -0
  87. package/@tencent/polaris/dist/limiter/ratelimiter/global.js +397 -0
  88. package/@tencent/polaris/dist/limiter/ratelimiter/global.js.map +1 -0
  89. package/@tencent/polaris/dist/limiter/ratelimiter/index.d.ts +3 -0
  90. package/@tencent/polaris/dist/limiter/ratelimiter/index.js +19 -0
  91. package/@tencent/polaris/dist/limiter/ratelimiter/index.js.map +1 -0
  92. package/@tencent/polaris/dist/limiter/ratelimiter/local.d.ts +17 -0
  93. package/@tencent/polaris/dist/limiter/ratelimiter/local.js +52 -0
  94. package/@tencent/polaris/dist/limiter/ratelimiter/local.js.map +1 -0
  95. package/@tencent/polaris/dist/location.d.ts +48 -0
  96. package/@tencent/polaris/dist/location.js +67 -0
  97. package/@tencent/polaris/dist/location.js.map +1 -0
  98. package/@tencent/polaris/dist/logging.d.ts +106 -0
  99. package/@tencent/polaris/dist/logging.js +130 -0
  100. package/@tencent/polaris/dist/logging.js.map +1 -0
  101. package/@tencent/polaris/dist/metadata.d.ts +78 -0
  102. package/@tencent/polaris/dist/metadata.js +119 -0
  103. package/@tencent/polaris/dist/metadata.js.map +1 -0
  104. package/@tencent/polaris/dist/plugins/breaker/polaris.d.ts +47 -0
  105. package/@tencent/polaris/dist/plugins/breaker/polaris.js +162 -0
  106. package/@tencent/polaris/dist/plugins/breaker/polaris.js.map +1 -0
  107. package/@tencent/polaris/dist/plugins/lb/base.d.ts +24 -0
  108. package/@tencent/polaris/dist/plugins/lb/base.js +32 -0
  109. package/@tencent/polaris/dist/plugins/lb/base.js.map +1 -0
  110. package/@tencent/polaris/dist/plugins/lb/edf.d.ts +24 -0
  111. package/@tencent/polaris/dist/plugins/lb/edf.js +77 -0
  112. package/@tencent/polaris/dist/plugins/lb/edf.js.map +1 -0
  113. package/@tencent/polaris/dist/plugins/lb/hashring.d.ts +24 -0
  114. package/@tencent/polaris/dist/plugins/lb/hashring.js +53 -0
  115. package/@tencent/polaris/dist/plugins/lb/hashring.js.map +1 -0
  116. package/@tencent/polaris/dist/plugins/lb/sticky.d.ts +31 -0
  117. package/@tencent/polaris/dist/plugins/lb/sticky.js +88 -0
  118. package/@tencent/polaris/dist/plugins/lb/sticky.js.map +1 -0
  119. package/@tencent/polaris/dist/plugins/lb/swrr.d.ts +25 -0
  120. package/@tencent/polaris/dist/plugins/lb/swrr.js +72 -0
  121. package/@tencent/polaris/dist/plugins/lb/swrr.js.map +1 -0
  122. package/@tencent/polaris/dist/plugins/lb/wr.d.ts +17 -0
  123. package/@tencent/polaris/dist/plugins/lb/wr.js +50 -0
  124. package/@tencent/polaris/dist/plugins/lb/wr.js.map +1 -0
  125. package/@tencent/polaris/dist/plugins/lb/wrr.d.ts +19 -0
  126. package/@tencent/polaris/dist/plugins/lb/wrr.js +81 -0
  127. package/@tencent/polaris/dist/plugins/lb/wrr.js.map +1 -0
  128. package/@tencent/polaris/dist/plugins/logging/console.d.ts +10 -0
  129. package/@tencent/polaris/dist/plugins/logging/console.js +38 -0
  130. package/@tencent/polaris/dist/plugins/logging/console.js.map +1 -0
  131. package/@tencent/polaris/dist/plugins/naming/local-server/index.d.ts +32 -0
  132. package/@tencent/polaris/dist/plugins/naming/local-server/index.js +88 -0
  133. package/@tencent/polaris/dist/plugins/naming/local-server/index.js.map +1 -0
  134. package/@tencent/polaris/dist/plugins/naming/polaris-server/adapter/base.d.ts +124 -0
  135. package/@tencent/polaris/dist/plugins/naming/polaris-server/adapter/base.js +398 -0
  136. package/@tencent/polaris/dist/plugins/naming/polaris-server/adapter/base.js.map +1 -0
  137. package/@tencent/polaris/dist/plugins/naming/polaris-server/adapter/discover.d.ts +27 -0
  138. package/@tencent/polaris/dist/plugins/naming/polaris-server/adapter/discover.js +287 -0
  139. package/@tencent/polaris/dist/plugins/naming/polaris-server/adapter/discover.js.map +1 -0
  140. package/@tencent/polaris/dist/plugins/naming/polaris-server/adapter/index.d.ts +15 -0
  141. package/@tencent/polaris/dist/plugins/naming/polaris-server/adapter/index.js +43 -0
  142. package/@tencent/polaris/dist/plugins/naming/polaris-server/adapter/index.js.map +1 -0
  143. package/@tencent/polaris/dist/plugins/naming/polaris-server/adapter/monitor.d.ts +28 -0
  144. package/@tencent/polaris/dist/plugins/naming/polaris-server/adapter/monitor.js +249 -0
  145. package/@tencent/polaris/dist/plugins/naming/polaris-server/adapter/monitor.js.map +1 -0
  146. package/@tencent/polaris/dist/plugins/naming/polaris-server/adapter/ratelimit.d.ts +19 -0
  147. package/@tencent/polaris/dist/plugins/naming/polaris-server/adapter/ratelimit.js +222 -0
  148. package/@tencent/polaris/dist/plugins/naming/polaris-server/adapter/ratelimit.js.map +1 -0
  149. package/@tencent/polaris/dist/plugins/naming/polaris-server/connector/grpc/bidi.d.ts +26 -0
  150. package/@tencent/polaris/dist/plugins/naming/polaris-server/connector/grpc/bidi.js +99 -0
  151. package/@tencent/polaris/dist/plugins/naming/polaris-server/connector/grpc/bidi.js.map +1 -0
  152. package/@tencent/polaris/dist/plugins/naming/polaris-server/connector/grpc/index.d.ts +60 -0
  153. package/@tencent/polaris/dist/plugins/naming/polaris-server/connector/grpc/index.js +259 -0
  154. package/@tencent/polaris/dist/plugins/naming/polaris-server/connector/grpc/index.js.map +1 -0
  155. package/@tencent/polaris/dist/plugins/naming/polaris-server/connector/grpc/pb/discover.proto +24 -0
  156. package/@tencent/polaris/dist/plugins/naming/polaris-server/connector/grpc/pb/monitor.proto +18 -0
  157. package/@tencent/polaris/dist/plugins/naming/polaris-server/connector/grpc/pb/ratelimit.proto +12 -0
  158. package/@tencent/polaris/dist/plugins/naming/polaris-server/connector/http/index.d.ts +39 -0
  159. package/@tencent/polaris/dist/plugins/naming/polaris-server/connector/http/index.js +115 -0
  160. package/@tencent/polaris/dist/plugins/naming/polaris-server/connector/http/index.js.map +1 -0
  161. package/@tencent/polaris/dist/plugins/naming/polaris-server/discover-pb/api.proto +24 -0
  162. package/@tencent/polaris/dist/plugins/naming/polaris-server/discover-pb/client.proto +22 -0
  163. package/@tencent/polaris/dist/plugins/naming/polaris-server/discover-pb/model.proto +28 -0
  164. package/@tencent/polaris/dist/plugins/naming/polaris-server/discover-pb/ratelimit.proto +80 -0
  165. package/@tencent/polaris/dist/plugins/naming/polaris-server/discover-pb/request.proto +18 -0
  166. package/@tencent/polaris/dist/plugins/naming/polaris-server/discover-pb/response.proto +65 -0
  167. package/@tencent/polaris/dist/plugins/naming/polaris-server/discover-pb/routing.proto +66 -0
  168. package/@tencent/polaris/dist/plugins/naming/polaris-server/discover-pb/service.proto +95 -0
  169. package/@tencent/polaris/dist/plugins/naming/polaris-server/discover-pb/types.d.ts +1568 -0
  170. package/@tencent/polaris/dist/plugins/naming/polaris-server/index.d.ts +36 -0
  171. package/@tencent/polaris/dist/plugins/naming/polaris-server/index.js +51 -0
  172. package/@tencent/polaris/dist/plugins/naming/polaris-server/index.js.map +1 -0
  173. package/@tencent/polaris/dist/plugins/naming/polaris-server/monitor-pb/api.proto +18 -0
  174. package/@tencent/polaris/dist/plugins/naming/polaris-server/monitor-pb/circuitbreak.proto +67 -0
  175. package/@tencent/polaris/dist/plugins/naming/polaris-server/monitor-pb/request.proto +82 -0
  176. package/@tencent/polaris/dist/plugins/naming/polaris-server/monitor-pb/response.proto +11 -0
  177. package/@tencent/polaris/dist/plugins/naming/polaris-server/monitor-pb/sdkcache.proto +46 -0
  178. package/@tencent/polaris/dist/plugins/naming/polaris-server/monitor-pb/sdkconfiguration.proto +16 -0
  179. package/@tencent/polaris/dist/plugins/naming/polaris-server/monitor-pb/sdktoken.proto +10 -0
  180. package/@tencent/polaris/dist/plugins/naming/polaris-server/monitor-pb/types.d.ts +1102 -0
  181. package/@tencent/polaris/dist/plugins/naming/polaris-server/pool.d.ts +29 -0
  182. package/@tencent/polaris/dist/plugins/naming/polaris-server/pool.js +77 -0
  183. package/@tencent/polaris/dist/plugins/naming/polaris-server/pool.js.map +1 -0
  184. package/@tencent/polaris/dist/plugins/naming/polaris-server/ratelimit-pb/api.proto +12 -0
  185. package/@tencent/polaris/dist/plugins/naming/polaris-server/ratelimit-pb/ratelimit.proto +28 -0
  186. package/@tencent/polaris/dist/plugins/naming/polaris-server/ratelimit-pb/types.d.ts +395 -0
  187. package/@tencent/polaris/dist/plugins/naming/polaris-server/rules.d.ts +13 -0
  188. package/@tencent/polaris/dist/plugins/naming/polaris-server/rules.js +116 -0
  189. package/@tencent/polaris/dist/plugins/naming/polaris-server/rules.js.map +1 -0
  190. package/@tencent/polaris/dist/plugins/naming/polaris-server/types.d.ts +67 -0
  191. package/@tencent/polaris/dist/plugins/naming/polaris-server/types.js +67 -0
  192. package/@tencent/polaris/dist/plugins/naming/polaris-server/types.js.map +1 -0
  193. package/@tencent/polaris/dist/plugins/naming/polaris-server/utils.d.ts +99 -0
  194. package/@tencent/polaris/dist/plugins/naming/polaris-server/utils.js +217 -0
  195. package/@tencent/polaris/dist/plugins/naming/polaris-server/utils.js.map +1 -0
  196. package/@tencent/polaris/dist/plugins/registry/memory.d.ts +10 -0
  197. package/@tencent/polaris/dist/plugins/registry/memory.js +50 -0
  198. package/@tencent/polaris/dist/plugins/registry/memory.js.map +1 -0
  199. package/@tencent/polaris/dist/plugins/router/polaris/nearby.d.ts +51 -0
  200. package/@tencent/polaris/dist/plugins/router/polaris/nearby.js +145 -0
  201. package/@tencent/polaris/dist/plugins/router/polaris/nearby.js.map +1 -0
  202. package/@tencent/polaris/dist/plugins/router/polaris/rule.d.ts +11 -0
  203. package/@tencent/polaris/dist/plugins/router/polaris/rule.js +174 -0
  204. package/@tencent/polaris/dist/plugins/router/polaris/rule.js.map +1 -0
  205. package/@tencent/polaris/dist/plugins/router/trpc/canary.d.ts +25 -0
  206. package/@tencent/polaris/dist/plugins/router/trpc/canary.js +36 -0
  207. package/@tencent/polaris/dist/plugins/router/trpc/canary.js.map +1 -0
  208. package/@tencent/polaris/dist/plugins/router/trpc/env.d.ts +10 -0
  209. package/@tencent/polaris/dist/plugins/router/trpc/env.js +34 -0
  210. package/@tencent/polaris/dist/plugins/router/trpc/env.js.map +1 -0
  211. package/@tencent/polaris/dist/plugins/router/trpc/set.d.ts +56 -0
  212. package/@tencent/polaris/dist/plugins/router/trpc/set.js +106 -0
  213. package/@tencent/polaris/dist/plugins/router/trpc/set.js.map +1 -0
  214. package/@tencent/polaris/dist/plugins/shaping/unirate.d.ts +31 -0
  215. package/@tencent/polaris/dist/plugins/shaping/unirate.js +124 -0
  216. package/@tencent/polaris/dist/plugins/shaping/unirate.js.map +1 -0
  217. package/@tencent/polaris/dist/plugins/shaping/warmup.d.ts +61 -0
  218. package/@tencent/polaris/dist/plugins/shaping/warmup.js +171 -0
  219. package/@tencent/polaris/dist/plugins/shaping/warmup.js.map +1 -0
  220. package/@tencent/polaris/dist/plugins/weight/polaris.d.ts +23 -0
  221. package/@tencent/polaris/dist/plugins/weight/polaris.js +159 -0
  222. package/@tencent/polaris/dist/plugins/weight/polaris.js.map +1 -0
  223. package/@tencent/polaris/dist/plugins.d.ts +619 -0
  224. package/@tencent/polaris/dist/plugins.js +91 -0
  225. package/@tencent/polaris/dist/plugins.js.map +1 -0
  226. package/@tencent/polaris/dist/polaris.d.ts +33 -0
  227. package/@tencent/polaris/dist/polaris.js +59 -0
  228. package/@tencent/polaris/dist/polaris.js.map +1 -0
  229. package/@tencent/polaris/dist/provider/index.d.ts +102 -0
  230. package/@tencent/polaris/dist/provider/index.js +168 -0
  231. package/@tencent/polaris/dist/provider/index.js.map +1 -0
  232. package/@tencent/polaris/dist/registry.d.ts +174 -0
  233. package/@tencent/polaris/dist/registry.js +660 -0
  234. package/@tencent/polaris/dist/registry.js.map +1 -0
  235. package/@tencent/polaris/dist/rules.d.ts +163 -0
  236. package/@tencent/polaris/dist/rules.js +24 -0
  237. package/@tencent/polaris/dist/rules.js.map +1 -0
  238. package/@tencent/polaris/dist/scripts/postinstall.d.ts +1 -0
  239. package/@tencent/polaris/dist/scripts/postinstall.js +71 -0
  240. package/@tencent/polaris/dist/scripts/postinstall.js.map +1 -0
  241. package/@tencent/polaris/dist/service.d.ts +18 -0
  242. package/@tencent/polaris/dist/service.js +3 -0
  243. package/@tencent/polaris/dist/service.js.map +1 -0
  244. package/@tencent/polaris/dist/skeleton.d.ts +87 -0
  245. package/@tencent/polaris/dist/skeleton.js +282 -0
  246. package/@tencent/polaris/dist/skeleton.js.map +1 -0
  247. package/@tencent/polaris/dist/utils.d.ts +36 -0
  248. package/@tencent/polaris/dist/utils.js +74 -0
  249. package/@tencent/polaris/dist/utils.js.map +1 -0
  250. package/@tencent/polaris/dist/weak.d.ts +11 -0
  251. package/@tencent/polaris/dist/weak.js +44 -0
  252. package/@tencent/polaris/dist/weak.js.map +1 -0
  253. package/@tencent/polaris/package.json +114 -0
  254. package/README.md +61 -0
  255. package/cursor-setting.png +0 -0
  256. package/index.js +16 -0
  257. package/index.js.map +1 -0
  258. package/mcp-server-prompt.png +0 -0
  259. package/mcp.json +8 -0
  260. package/package.json +49 -0
  261. package/resource/doc/tuicallkit/android/.gitkeep +0 -0
  262. package/resource/doc/tuicallkit/android/api_TUICallKit.md +610 -0
  263. package/resource/doc/tuicallkit/android/api_TUICallObserver.md +784 -0
  264. package/resource/doc/tuicallkit/android/how_to_integrated_android_callkit.md +286 -0
  265. package/resource/doc/tuicallkit/faq/faq.md +127 -0
  266. package/resource/doc/tuicallkit/flutter/api_TUICallDefine.md +938 -0
  267. package/resource/doc/tuicallkit/flutter/api_TUICallKit.md +469 -0
  268. package/resource/doc/tuicallkit/flutter/api_TUICallObserver.md +897 -0
  269. package/resource/doc/tuicallkit/flutter/how_to_integrated_flutter_callkit.md +226 -0
  270. package/resource/doc/tuicallkit/flutter/how_to_run_flutter_callkit_demo.md +101 -0
  271. package/resource/doc/tuicallkit/iOS/api_TUICallKit.md +398 -0
  272. package/resource/doc/tuicallkit/iOS/api_TUICallObserver.md +781 -0
  273. package/resource/doc/tuicallkit/iOS/how_to_integrated_iOS_callkit.md +268 -0
  274. package/resource/doc/tuicallkit/iOS/how_to_run_iOS_callkit_demo.md +98 -0
  275. package/resource/doc/tuicallkit/react/.gitkeep +0 -0
  276. package/resource/doc/tuicallkit/react/api_TUICallKit.md +354 -0
  277. package/resource/doc/tuicallkit/react/how_to_integrated_react_callkit.md +166 -0
  278. package/resource/doc/tuicallkit/react/how_to_run_react_callkit_demo.md +61 -0
  279. package/resource/doc/tuicallkit/vue/.gitkeep +0 -0
  280. package/resource/doc/tuicallkit/vue/api_TUICallKit.md +354 -0
  281. package/resource/doc/tuicallkit/vue/how_to_integrated_vue_callkit.md +187 -0
  282. package/resource/doc/tuicallkit/vue/how_to_run_vue_callkit_demo.md +61 -0
  283. package/server.js +132 -0
  284. package/server.js.map +1 -0
  285. package/streamableHttp.js +74 -0
  286. package/streamableHttp.js.map +1 -0
@@ -0,0 +1,660 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalRegistry = void 0;
4
+ const events_1 = require("events");
5
+ const process_1 = require("process");
6
+ const errors_1 = require("./errors");
7
+ const instance_1 = require("./instance");
8
+ const location_1 = require("./location");
9
+ const plugins_1 = require("./plugins");
10
+ const utils_1 = require("./utils");
11
+ var EntryStatus;
12
+ (function (EntryStatus) {
13
+ /** 正常 */
14
+ EntryStatus[EntryStatus["Normal"] = 0] = "Normal";
15
+ /** 过期 */
16
+ EntryStatus[EntryStatus["Outdated"] = 1] = "Outdated";
17
+ /** 更新中 */
18
+ EntryStatus[EntryStatus["Updating"] = 2] = "Updating";
19
+ /** 已释放 */
20
+ EntryStatus[EntryStatus["Released"] = 3] = "Released";
21
+ })(EntryStatus || (EntryStatus = {}));
22
+ const kDefaultOptions = {
23
+ // #region Time
24
+ /**
25
+ * 过期时间
26
+ * 超过此时间,会 __异步__ 请求新数据
27
+ * _也就是说,返回值可能为旧数据_
28
+ */
29
+ expireTime: {
30
+ /** 实例过期时间 */
31
+ [plugins_1.RegistryCategory.Instance]: 2 * utils_1.kSeconds,
32
+ /** 规则过期时间 */
33
+ [plugins_1.RegistryCategory.Rule]: 2 * utils_1.kSeconds,
34
+ /** 限流规则过期时间 */
35
+ [plugins_1.RegistryCategory.Ratelimit]: 2 * utils_1.kSeconds
36
+ },
37
+ /**
38
+ * 刷新时间
39
+ * 达到此时间,会自动更新数据(如数据已过期)
40
+ * _数据刷新,并不影响资源回收策略_
41
+ */
42
+ refreshTime: {
43
+ /** 实例刷新时间 */
44
+ [plugins_1.RegistryCategory.Instance]: 10 * utils_1.kSeconds,
45
+ /** 规则刷新时间 */
46
+ [plugins_1.RegistryCategory.Rule]: 10 * utils_1.kSeconds,
47
+ /** 限流规则刷新时间 */
48
+ [plugins_1.RegistryCategory.Ratelimit]: 10 * utils_1.kSeconds
49
+ },
50
+ /**
51
+ * 脏数据时间
52
+ * 超过此时间,会 __同步__ 请求新数据
53
+ * _也就是说,返回值一定为新数据_
54
+ */
55
+ dirtyTime: {
56
+ /** 实例脏数据时间 */
57
+ [plugins_1.RegistryCategory.Instance]: 1 * utils_1.kMinutes,
58
+ /** 规则脏数据时间 */
59
+ [plugins_1.RegistryCategory.Rule]: 1 * utils_1.kMinutes,
60
+ /** 限流规则脏数据时间 */
61
+ [plugins_1.RegistryCategory.Ratelimit]: 1 * utils_1.kMinutes
62
+ },
63
+ /**
64
+ * 资源回收时间
65
+ * 回收条件为:_至少_经历指定的间隔都没被访问
66
+ * 小于或等于 0 则为不启用此特性
67
+ */
68
+ recycleTime: 1 * utils_1.kDays,
69
+ // #endregion
70
+ // #region Report
71
+ /**
72
+ * 服务状态上报间隔
73
+ */
74
+ reportInterval: 3 * utils_1.kMinutes,
75
+ /**
76
+ * 服务状态上报阈值
77
+ */
78
+ reportThreshold: 10000,
79
+ // #endregion
80
+ /**
81
+ * 请求池最大容量
82
+ * 超过此大小,且无请求时,将会进行回收
83
+ */
84
+ maxRequestsCapacity: 18 /** v8 对于 FastProperties Slot 的上限为 18 */
85
+ };
86
+ // #endregion
87
+ class LocalRegistry extends events_1.EventEmitter {
88
+ constructor(logger, naming, registry, reporters, ratelimit, options) {
89
+ super();
90
+ this.logger = logger;
91
+ this.naming = naming;
92
+ this.registry = registry;
93
+ this.reporters = reporters;
94
+ this.ratelimit = ratelimit;
95
+ this.entriesMeta = this.createEntries();
96
+ this.servicesMeta = Object.create(null);
97
+ // #region request
98
+ this.activeRequestsPool = Object.create(null);
99
+ this.activeRequestsCapacity = 0;
100
+ this.activeRequestsCount = 0;
101
+ // #endregion
102
+ // #region report
103
+ this.historyRecorder = Object.create(null);
104
+ this.historyRecorderCount = 0;
105
+ this.needReport = false;
106
+ this.disposed = false;
107
+ this.options = Object.assign(Object.assign(Object.assign({}, kDefaultOptions), options), { expireTime: Object.assign(Object.assign({}, kDefaultOptions.expireTime), options === null || options === void 0 ? void 0 : options.expireTime), refreshTime: Object.assign(Object.assign({}, kDefaultOptions.refreshTime), options === null || options === void 0 ? void 0 : options.refreshTime), dirtyTime: Object.assign(Object.assign({}, kDefaultOptions.dirtyTime), options === null || options === void 0 ? void 0 : options.dirtyTime) });
108
+ this.needReport = reporters.some(report => typeof report.registryCache === "function");
109
+ }
110
+ get location() {
111
+ const { location } = this.naming;
112
+ const { baseLocation } = this.options;
113
+ if (baseLocation && (0, location_1.isEmptyLocation)(location)) {
114
+ return baseLocation;
115
+ }
116
+ return location;
117
+ }
118
+ async fetch(type, namespace, service) {
119
+ if (this.disposed) {
120
+ throw new errors_1.StateError("Already disposed");
121
+ }
122
+ if (namespace === "" && service === "") {
123
+ switch (type) {
124
+ case plugins_1.RegistryCategory.Instance: {
125
+ return [];
126
+ }
127
+ case plugins_1.RegistryCategory.Rule: {
128
+ return {
129
+ in: [],
130
+ out: []
131
+ };
132
+ }
133
+ case plugins_1.RegistryCategory.Ratelimit: {
134
+ return [];
135
+ }
136
+ default: {
137
+ (0, utils_1.UNREACHABLE)();
138
+ }
139
+ }
140
+ }
141
+ /** 标记对 `namespace.service` 的访问 */
142
+ this.accessService(namespace, service);
143
+ const fromLocal = this.local(type, namespace, service);
144
+ // #region remote
145
+ if (fromLocal === null) {
146
+ const fromNaming = await this.pull(type, namespace, service);
147
+ if (fromNaming !== null) {
148
+ return fromNaming;
149
+ }
150
+ /*
151
+ * note:
152
+ * 如果前一相同查询设置了数据,
153
+ * 则重走标准逻辑获取数据。
154
+ */
155
+ return this.fetch(type, namespace, service);
156
+ }
157
+ // #endregion
158
+ const entryMeta = this.getEntryMeta(type, namespace, service);
159
+ switch (entryMeta.status) {
160
+ case EntryStatus.Outdated: {
161
+ /**
162
+ * `timeSpan` >= dirtyTime
163
+ * 删除本地所有缓存数据,重新获取
164
+ */
165
+ if (entryMeta.outdatedTime === undefined) {
166
+ (0, utils_1.UNREACHABLE)();
167
+ }
168
+ if (((0, process_1.uptime)() - entryMeta.outdatedTime) * utils_1.kSeconds >= this.options.dirtyTime[type]) {
169
+ this.dropService([type], namespace, service);
170
+ return this.fetch(type, namespace, service);
171
+ }
172
+ /*
173
+ * `timeSpan` < dirtyTime
174
+ * 异步更新缓存数据
175
+ *
176
+ * note:
177
+ * 更新机制为异步更新,
178
+ * 避免缓存击穿,及在特定场景下死循环
179
+ */
180
+ this.performUpdate(type, namespace, service, fromLocal, entryMeta).catch(e => this.logger.error(`[Registry] [fetch], update ${type}`, e));
181
+ break;
182
+ }
183
+ case EntryStatus.Normal: {
184
+ if (entryMeta.statusUpdater === null) {
185
+ (0, utils_1.UNREACHABLE)();
186
+ }
187
+ break;
188
+ }
189
+ case EntryStatus.Updating: {
190
+ break;
191
+ }
192
+ case EntryStatus.Released: // [[fallthrough]]
193
+ default: {
194
+ (0, utils_1.UNREACHABLE)();
195
+ }
196
+ }
197
+ return fromLocal.data;
198
+ }
199
+ /* eslint-enable max-len */
200
+ // #endregion
201
+ local(type, namespace, service) {
202
+ if (!namespace || !service) {
203
+ return this.registry[type].all();
204
+ }
205
+ return this.registry[type].get(namespace, service);
206
+ }
207
+ // #endregion
208
+ // #region dispose
209
+ dispose() {
210
+ this.cancelHistoryReporter();
211
+ this.dropEntryMeta();
212
+ this.dropServiceMeta();
213
+ this.removeAllListeners();
214
+ this.disposed = true;
215
+ }
216
+ get isDisposed() {
217
+ return this.disposed;
218
+ }
219
+ // #endregion
220
+ // #region update
221
+ /** for external use only */
222
+ async update(type, namespace, service) {
223
+ /** 标记对 `namespace.service` 的访问 */
224
+ this.accessService(namespace, service);
225
+ return this.performUpdate(type, namespace, service);
226
+ }
227
+ async performUpdate(type, namespace, service, fromLocal = this.local(type, namespace, service), entryMeta) {
228
+ if (fromLocal === null) {
229
+ return (await this.pull(type, namespace, service)) !== null;
230
+ }
231
+ const localEntryMeta = entryMeta !== null && entryMeta !== void 0 ? entryMeta : this.getEntryMeta(type, namespace, service);
232
+ switch (localEntryMeta.status) {
233
+ case EntryStatus.Normal: // [[fallthrough]]
234
+ case EntryStatus.Outdated: {
235
+ break;
236
+ }
237
+ case EntryStatus.Updating: {
238
+ return false;
239
+ }
240
+ case EntryStatus.Released: // [[fallthrough]]
241
+ default: {
242
+ (0, utils_1.UNREACHABLE)();
243
+ }
244
+ }
245
+ localEntryMeta.status = EntryStatus.Updating;
246
+ return Promise.resolve() /** 通过 Promise 切分同步执行代码,降低(同步)调用耗时 */
247
+ .then(() => {
248
+ switch (type) {
249
+ case plugins_1.RegistryCategory.Instance: {
250
+ return this.updateInstance(namespace, service, fromLocal, localEntryMeta);
251
+ }
252
+ case plugins_1.RegistryCategory.Rule: {
253
+ return this.updateRule(namespace, service, fromLocal, localEntryMeta);
254
+ }
255
+ case plugins_1.RegistryCategory.Ratelimit: {
256
+ return this.updateRatelimit(namespace, service, fromLocal, localEntryMeta);
257
+ }
258
+ default: {
259
+ (0, utils_1.UNREACHABLE)();
260
+ }
261
+ }
262
+ })
263
+ .then((hasUpdated) => {
264
+ if (localEntryMeta.status !== EntryStatus.Released) {
265
+ localEntryMeta.status = EntryStatus.Normal;
266
+ localEntryMeta.outdatedTime = undefined;
267
+ this.attachUpdaterToEntryMeta(type, localEntryMeta);
268
+ }
269
+ return hasUpdated;
270
+ }, (err) => {
271
+ if (localEntryMeta.status !== EntryStatus.Released) {
272
+ /** 当请求失败时,不更新过期时间戳 `outdatedTime` */
273
+ localEntryMeta.status = EntryStatus.Outdated;
274
+ }
275
+ throw err;
276
+ });
277
+ }
278
+ async updateInstance(namespace, service, fromLocal, entryMeta) {
279
+ const fromNaming = await this.request(plugins_1.RegistryCategory.Instance, namespace, service, fromLocal.revision);
280
+ if (entryMeta.status === EntryStatus.Released || fromNaming.revision === fromLocal.revision) {
281
+ return false;
282
+ }
283
+ fromNaming.data.forEach((namingInstance) => {
284
+ const exists = fromLocal.data.some((localInstance) => {
285
+ if (namingInstance.id === localInstance.id) {
286
+ (0, instance_1.instanceCopy)(namingInstance, localInstance);
287
+ if (namingInstance.status !== localInstance.status) {
288
+ /** EventEmitter Synchronously calls each of the listeners */
289
+ this.emit("SyncInstanceStatus" /* SyncInstanceStatus */, namespace, service, localInstance, namingInstance.status);
290
+ localInstance.status = namingInstance.status;
291
+ }
292
+ return true;
293
+ }
294
+ return false;
295
+ });
296
+ if (!exists) {
297
+ fromLocal.data.push(namingInstance);
298
+ }
299
+ });
300
+ fromLocal.data = fromLocal.data.filter(localInstance => fromNaming.data.some(namingInstance => namingInstance.id === localInstance.id));
301
+ fromLocal.revision = fromNaming.revision;
302
+ this.registry[plugins_1.RegistryCategory.Instance].set(namespace, service, fromLocal);
303
+ this.changelog(plugins_1.RegistryCategory.Instance, namespace, service, fromNaming.revision);
304
+ return true;
305
+ }
306
+ async updateRule(namespace, service, fromLocal, entryMeta) {
307
+ const fromNaming = await this.request(plugins_1.RegistryCategory.Rule, namespace, service, fromLocal.revision);
308
+ if (entryMeta.status === EntryStatus.Released || fromNaming.revision === fromLocal.revision) {
309
+ return false;
310
+ }
311
+ this.registry[plugins_1.RegistryCategory.Rule].set(namespace, service, fromNaming);
312
+ this.changelog(plugins_1.RegistryCategory.Rule, namespace, service, fromNaming.revision);
313
+ return true;
314
+ }
315
+ async updateRatelimit(namespace, service, fromLocal, entryMeta) {
316
+ const fromNaming = await this.request(plugins_1.RegistryCategory.Ratelimit, namespace, service, fromLocal.revision);
317
+ if (entryMeta.status === EntryStatus.Released || fromNaming.revision === fromLocal.revision) {
318
+ return false;
319
+ }
320
+ fromNaming.data.forEach((namingRule) => {
321
+ const localData = fromLocal.data;
322
+ const { length } = localData;
323
+ let index = 0;
324
+ for (; index < length; index += 1) {
325
+ const localRule = localData[index];
326
+ if (namingRule.id === localRule.id) {
327
+ if (namingRule.revision !== localRule.revision) {
328
+ localData[index] = namingRule;
329
+ }
330
+ break;
331
+ }
332
+ }
333
+ if (index === length) { /** not found */
334
+ fromLocal.data.push(namingRule);
335
+ }
336
+ });
337
+ fromLocal.data = fromLocal.data.filter(localRule => fromNaming.data.some(namingRule => namingRule.id === localRule.id));
338
+ fromLocal.revision = fromNaming.revision;
339
+ this.registry[plugins_1.RegistryCategory.Ratelimit].set(namespace, service, fromNaming);
340
+ this.changelog(plugins_1.RegistryCategory.Ratelimit, namespace, service, fromNaming.revision);
341
+ return true;
342
+ }
343
+ async request(type, namespace, service, revision) {
344
+ const key = `${type}#${namespace}.${service}${revision ? `@${revision}` : ""}`;
345
+ let activeRequest = this.activeRequestsPool[key];
346
+ const performRequest = !activeRequest;
347
+ if (performRequest) {
348
+ /**
349
+ * 当值为 `undefined` 时,说明对应(key)的槽未被使用,
350
+ * 故存储对象容量大小增加 1 个槽位。
351
+ */
352
+ if (activeRequest === undefined) {
353
+ this.activeRequestsCapacity += 1;
354
+ }
355
+ this.activeRequestsCount += 1;
356
+ switch (type) {
357
+ case plugins_1.RegistryCategory.Instance: {
358
+ activeRequest = this.naming.list(namespace, service, revision);
359
+ break;
360
+ }
361
+ case plugins_1.RegistryCategory.Rule: {
362
+ activeRequest = this.naming.routingRules(namespace, service, revision);
363
+ break;
364
+ }
365
+ case plugins_1.RegistryCategory.Ratelimit: {
366
+ if (!this.ratelimit) {
367
+ (0, utils_1.UNREACHABLE)();
368
+ }
369
+ activeRequest = this.ratelimit.ratelimitRules(namespace, service, revision);
370
+ break;
371
+ }
372
+ default: {
373
+ (0, utils_1.UNREACHABLE)();
374
+ }
375
+ }
376
+ this.activeRequestsPool[key] = activeRequest;
377
+ }
378
+ let result;
379
+ try {
380
+ result = await activeRequest;
381
+ }
382
+ finally {
383
+ if (performRequest) {
384
+ this.activeRequestsCount -= 1;
385
+ }
386
+ /**
387
+ * 回收机制:
388
+ * 当超过最大容量且当前没有未完成的请求时,进行整体回收(重新创建)。
389
+ * 这里为了性能考虑这里不使用 `delete` 删除对象属性,避免退化为字典模式。
390
+ */
391
+ if (this.activeRequestsCount === 0 && this.activeRequestsCapacity > this.options.maxRequestsCapacity) {
392
+ this.activeRequestsPool = Object.create(null);
393
+ this.activeRequestsCapacity = 0;
394
+ }
395
+ /**
396
+ * 将使用过的槽设置成为 `null`,以便于复用时区分。
397
+ */
398
+ this.activeRequestsPool[key] = null;
399
+ }
400
+ return result;
401
+ }
402
+ async pull(type, namespace, service) {
403
+ const { data: fromNaming, revision } = await this.request(type, namespace, service);
404
+ if (this.local(type, namespace, service) === null) {
405
+ this.registry[type].set(namespace, service, {
406
+ data: fromNaming,
407
+ revision
408
+ });
409
+ this.createEntryMeta(type, namespace, service, false);
410
+ return fromNaming;
411
+ }
412
+ return null;
413
+ }
414
+ // #endregion
415
+ // #region stat
416
+ report() {
417
+ const { historyRecorder } = this;
418
+ this.historyRecorder = Object.create(null);
419
+ this.historyRecorderCount = 0;
420
+ Object.keys(historyRecorder).forEach((namespace) => {
421
+ const serviceHistory = historyRecorder[namespace];
422
+ Object.keys(serviceHistory).forEach((service) => {
423
+ var _a, _b, _c;
424
+ const changelog = serviceHistory[service];
425
+ const rules = (_a = this.registry[plugins_1.RegistryCategory.Rule].get(namespace, service)) === null || _a === void 0 ? void 0 : _a.data;
426
+ const stat = {
427
+ [plugins_1.RegistryCategory.Instance]: {
428
+ history: changelog[plugins_1.RegistryCategory.Instance],
429
+ /*
430
+ * 当前实例列表不存在或为空,则认为当前已删除
431
+ */
432
+ eliminated: (((_b = this.registry[plugins_1.RegistryCategory.Instance].get(namespace, service)) === null || _b === void 0 ? void 0 : _b.data.length) || 0) === 0
433
+ },
434
+ [plugins_1.RegistryCategory.Rule]: {
435
+ history: changelog[plugins_1.RegistryCategory.Rule],
436
+ /*
437
+ * 当前规则不存在或出入规则均为空,则认为当前已删除
438
+ */
439
+ eliminated: ((rules === null || rules === void 0 ? void 0 : rules.in.length) || 0) === 0 && ((rules === null || rules === void 0 ? void 0 : rules.out.length) || 0) === 0
440
+ },
441
+ [plugins_1.RegistryCategory.Ratelimit]: {
442
+ history: changelog[plugins_1.RegistryCategory.Ratelimit],
443
+ /*
444
+ * 当前限流规则不存在或为空,则认为当前已删除
445
+ */
446
+ eliminated: (((_c = this.registry[plugins_1.RegistryCategory.Ratelimit].get(namespace, service)) === null || _c === void 0 ? void 0 : _c.data.length) || 0) === 0
447
+ }
448
+ };
449
+ this.reporters.forEach((reporter) => {
450
+ var _a;
451
+ (_a = reporter.registryCache) === null || _a === void 0 ? void 0 : _a.call(reporter, namespace, service, stat).catch(err => this.disposed || this.logger.error(`[${reporter.name}] [registryCache]`, err));
452
+ });
453
+ });
454
+ });
455
+ }
456
+ changelog(type, namespace, service, revision) {
457
+ if (!this.needReport) {
458
+ return;
459
+ }
460
+ const log = {
461
+ time: Date.now(),
462
+ revision
463
+ };
464
+ let ns = this.historyRecorder[namespace];
465
+ if (!ns) {
466
+ ns = Object.create(null);
467
+ this.historyRecorder[namespace] = ns;
468
+ }
469
+ let svr = ns[service];
470
+ if (!svr) {
471
+ svr = {
472
+ [plugins_1.RegistryCategory.Instance]: [],
473
+ [plugins_1.RegistryCategory.Rule]: [],
474
+ [plugins_1.RegistryCategory.Ratelimit]: []
475
+ };
476
+ ns[service] = svr;
477
+ }
478
+ svr[type].push(log);
479
+ this.historyRecorderCount += 1;
480
+ if (this.historyRecorderCount >= this.options.reportThreshold) {
481
+ this.cancelHistoryReporter();
482
+ this.report();
483
+ }
484
+ else if (this.historyReporter === undefined) {
485
+ this.historyReporter = setTimeout(() => {
486
+ this.report();
487
+ this.historyReporter = undefined;
488
+ }, this.options.reportInterval).unref();
489
+ }
490
+ }
491
+ cancelHistoryReporter() {
492
+ if (this.historyReporter) {
493
+ clearTimeout(this.historyReporter);
494
+ this.historyReporter = undefined;
495
+ }
496
+ }
497
+ // #endregion
498
+ // #region ServiceMeta
499
+ accessService(namespace, service) {
500
+ const { recycleTime } = this.options;
501
+ if (!(recycleTime > 0) || recycleTime === Infinity) {
502
+ return;
503
+ }
504
+ const serviceMeta = this.servicesMeta[`${namespace}.${service}`];
505
+ if (serviceMeta === undefined) {
506
+ this.createServiceMeta(namespace, service);
507
+ }
508
+ else {
509
+ serviceMeta.accessed = true;
510
+ }
511
+ }
512
+ dropServiceMeta(namespace, service) {
513
+ if (namespace === undefined && service === undefined) {
514
+ Object.values(this.servicesMeta)
515
+ .forEach(({ garbageCollector }) => clearInterval(garbageCollector));
516
+ return true;
517
+ }
518
+ if (namespace === undefined || service === undefined) {
519
+ (0, utils_1.UNREACHABLE)();
520
+ }
521
+ const serviceMeta = this.servicesMeta[`${namespace}.${service}`];
522
+ if (serviceMeta) {
523
+ clearInterval(serviceMeta.garbageCollector);
524
+ delete this.servicesMeta[`${namespace}.${service}`];
525
+ return true;
526
+ }
527
+ return false;
528
+ }
529
+ createServiceMeta(namespace, service) {
530
+ const { recycleTime } = this.options;
531
+ const serviceMeta = {
532
+ accessed: true,
533
+ garbageCollector: setInterval(() => {
534
+ if (serviceMeta.accessed) {
535
+ serviceMeta.accessed = false;
536
+ }
537
+ else {
538
+ this.dropServiceMeta(namespace, service);
539
+ this.dropService([plugins_1.RegistryCategory.Instance, plugins_1.RegistryCategory.Ratelimit, plugins_1.RegistryCategory.Rule], namespace, service);
540
+ }
541
+ }, recycleTime).unref()
542
+ };
543
+ this.servicesMeta[`${namespace}.${service}`] = serviceMeta;
544
+ return serviceMeta;
545
+ }
546
+ dropService(types, namespace, service) {
547
+ types.forEach((type) => {
548
+ this.dropEntryMeta(type, namespace, service);
549
+ this.registry[type].delete(namespace, service);
550
+ });
551
+ }
552
+ // #endregion
553
+ // #region EntryMeta
554
+ attachRefresherToEntryMeta(type, entryMeta, namespace, service) {
555
+ const interval = this.options.refreshTime[type];
556
+ if (!(interval > 0) || interval === Infinity) {
557
+ return;
558
+ }
559
+ entryMeta.contentRefresher = setInterval(() => {
560
+ if (entryMeta.status === EntryStatus.Outdated) {
561
+ this.performUpdate(type, namespace, service).catch(e => this.logger.error(`[Registry] [refresher], refresh ${namespace}.${service}#${type}`, e));
562
+ }
563
+ }, interval).unref();
564
+ }
565
+ attachUpdaterToEntryMeta(type, entryMeta) {
566
+ const timeout = this.options.expireTime[type];
567
+ if (!(timeout > 0) || timeout === Infinity) {
568
+ return;
569
+ }
570
+ if (entryMeta.statusUpdater !== null) {
571
+ clearTimeout(entryMeta.statusUpdater);
572
+ entryMeta.statusUpdater = null;
573
+ }
574
+ entryMeta.statusUpdater = setTimeout(() => {
575
+ entryMeta.statusUpdater = null;
576
+ /*
577
+ * note:
578
+ * 请注意,这里必须要判断当前状态是否正常,
579
+ * 否则会造成异步死循环问题
580
+ */
581
+ if (entryMeta.status === EntryStatus.Normal) {
582
+ entryMeta.status = EntryStatus.Outdated;
583
+ entryMeta.outdatedTime = (0, process_1.uptime)();
584
+ }
585
+ }, timeout).unref();
586
+ }
587
+ releaseEntryMeta(entryMeta) {
588
+ entryMeta.status = EntryStatus.Released;
589
+ entryMeta.outdatedTime = undefined;
590
+ if (entryMeta.statusUpdater !== null) {
591
+ clearTimeout(entryMeta.statusUpdater);
592
+ entryMeta.statusUpdater = null;
593
+ }
594
+ if (entryMeta.contentRefresher !== null) {
595
+ clearInterval(entryMeta.contentRefresher);
596
+ entryMeta.contentRefresher = null;
597
+ }
598
+ }
599
+ dropEntryMeta(type, namespace, service) {
600
+ /** drop all */
601
+ if (type === undefined && namespace === undefined && service === undefined) {
602
+ Object.values(this.entriesMeta).forEach((entriesMeta) => {
603
+ Object.values(entriesMeta).forEach((entryMeta) => {
604
+ this.releaseEntryMeta(entryMeta);
605
+ });
606
+ });
607
+ this.entriesMeta = this.createEntries();
608
+ return true;
609
+ }
610
+ /** drop one */
611
+ const entryMeta = this.getEntryMeta(type, namespace, service, true);
612
+ if (entryMeta !== undefined) {
613
+ this.releaseEntryMeta(entryMeta);
614
+ return true;
615
+ }
616
+ return false;
617
+ }
618
+ createEntries() {
619
+ return {
620
+ [plugins_1.RegistryCategory.Instance]: Object.create(null),
621
+ [plugins_1.RegistryCategory.Rule]: Object.create(null),
622
+ [plugins_1.RegistryCategory.Ratelimit]: Object.create(null)
623
+ };
624
+ }
625
+ createEntryMeta(type, namespace, service, isOutdated) {
626
+ const entryMeta = {
627
+ status: isOutdated ? EntryStatus.Outdated : EntryStatus.Normal,
628
+ statusUpdater: null,
629
+ contentRefresher: null
630
+ };
631
+ if (isOutdated) {
632
+ entryMeta.outdatedTime = (0, process_1.uptime)();
633
+ }
634
+ else {
635
+ this.attachUpdaterToEntryMeta(type, entryMeta);
636
+ }
637
+ this.attachRefresherToEntryMeta(type, entryMeta, namespace, service);
638
+ this.entriesMeta[type][`${namespace}.${service}`] = entryMeta;
639
+ return entryMeta;
640
+ }
641
+ getEntryMeta(type, namespace, service, popup = false) {
642
+ const entriesMeta = this.entriesMeta[type];
643
+ let entryMeta = entriesMeta[`${namespace}.${service}`];
644
+ if (entryMeta === undefined) {
645
+ if (!popup) {
646
+ /**
647
+ * 在本地名字服务插件中找得到的数据,并不一定有其对应的 `EntryMeta`,
648
+ * 故如查不到则创建,并标注为已过期 `EntryStatus.Outdated`,以便尽快更新
649
+ */
650
+ entryMeta = this.createEntryMeta(type, namespace, service, true);
651
+ }
652
+ }
653
+ else if (popup) {
654
+ delete entriesMeta[`${namespace}.${service}`];
655
+ }
656
+ return entryMeta;
657
+ }
658
+ }
659
+ exports.LocalRegistry = LocalRegistry;
660
+ //# sourceMappingURL=registry.js.map