@meowpanel/api 0.1.0-alpha.11 → 1.0.0-beta.2

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 (297) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +40 -0
  3. package/esm/mod.d.ts +87 -1
  4. package/esm/mod.d.ts.map +1 -1
  5. package/esm/mod.js +85 -1
  6. package/esm/src/client.d.ts +248 -0
  7. package/esm/src/client.d.ts.map +1 -0
  8. package/esm/src/client.js +235 -0
  9. package/esm/src/emitter.d.ts +53 -0
  10. package/esm/src/emitter.d.ts.map +1 -0
  11. package/esm/src/emitter.js +55 -0
  12. package/esm/src/errors.d.ts +42 -0
  13. package/esm/src/errors.d.ts.map +1 -0
  14. package/esm/src/errors.js +45 -0
  15. package/esm/src/http.d.ts +157 -0
  16. package/esm/src/http.d.ts.map +1 -0
  17. package/esm/src/http.js +317 -0
  18. package/esm/src/namespace.d.ts +59 -0
  19. package/esm/src/namespace.d.ts.map +1 -0
  20. package/esm/src/namespace.js +79 -0
  21. package/esm/src/reactive.d.ts +29 -0
  22. package/esm/src/reactive.d.ts.map +1 -0
  23. package/esm/src/reactive.js +35 -0
  24. package/esm/src/resources/account.d.ts +125 -0
  25. package/esm/src/resources/account.d.ts.map +1 -0
  26. package/esm/src/resources/account.js +151 -0
  27. package/esm/src/resources/api-keys.d.ts +116 -0
  28. package/esm/src/resources/api-keys.d.ts.map +1 -0
  29. package/esm/src/resources/api-keys.js +105 -0
  30. package/esm/src/resources/auth.d.ts +57 -0
  31. package/esm/src/resources/auth.d.ts.map +1 -0
  32. package/esm/src/resources/auth.js +39 -0
  33. package/esm/src/resources/eggs.d.ts +238 -0
  34. package/esm/src/resources/eggs.d.ts.map +1 -0
  35. package/esm/src/resources/eggs.js +187 -0
  36. package/esm/src/resources/hosts.d.ts +62 -0
  37. package/esm/src/resources/hosts.d.ts.map +1 -0
  38. package/esm/src/resources/hosts.js +62 -0
  39. package/esm/src/resources/members.d.ts +138 -0
  40. package/esm/src/resources/members.d.ts.map +1 -0
  41. package/esm/src/resources/members.js +122 -0
  42. package/esm/src/resources/nodes.d.ts +397 -0
  43. package/esm/src/resources/nodes.d.ts.map +1 -0
  44. package/esm/src/resources/nodes.js +352 -0
  45. package/esm/src/resources/server-groups.d.ts +150 -0
  46. package/esm/src/resources/server-groups.d.ts.map +1 -0
  47. package/esm/src/resources/server-groups.js +111 -0
  48. package/esm/src/resources/servers/activity.d.ts +120 -0
  49. package/esm/src/resources/servers/activity.d.ts.map +1 -0
  50. package/esm/src/resources/servers/activity.js +163 -0
  51. package/esm/src/resources/servers/allocations.d.ts +125 -0
  52. package/esm/src/resources/servers/allocations.d.ts.map +1 -0
  53. package/esm/src/resources/servers/allocations.js +137 -0
  54. package/esm/src/resources/servers/connection.d.ts +108 -0
  55. package/esm/src/resources/servers/connection.d.ts.map +1 -0
  56. package/esm/src/resources/servers/connection.js +169 -0
  57. package/esm/src/resources/servers/files.d.ts +164 -0
  58. package/esm/src/resources/servers/files.d.ts.map +1 -0
  59. package/esm/src/resources/servers/files.js +281 -0
  60. package/esm/src/resources/servers/index.d.ts +126 -0
  61. package/esm/src/resources/servers/index.d.ts.map +1 -0
  62. package/esm/src/resources/servers/index.js +135 -0
  63. package/esm/src/resources/servers/profiles.d.ts +138 -0
  64. package/esm/src/resources/servers/profiles.d.ts.map +1 -0
  65. package/esm/src/resources/servers/profiles.js +177 -0
  66. package/esm/src/resources/servers/server.d.ts +136 -0
  67. package/esm/src/resources/servers/server.d.ts.map +1 -0
  68. package/esm/src/resources/servers/server.js +202 -0
  69. package/esm/src/resources/servers/sftp.d.ts +147 -0
  70. package/esm/src/resources/servers/sftp.d.ts.map +1 -0
  71. package/esm/src/resources/servers/sftp.js +153 -0
  72. package/esm/src/resources/servers/types.d.ts +199 -0
  73. package/esm/src/resources/servers/types.d.ts.map +1 -0
  74. package/esm/src/resources/servers/types.js +1 -0
  75. package/esm/src/sse.d.ts +53 -0
  76. package/esm/src/sse.d.ts.map +1 -0
  77. package/esm/src/sse.js +133 -0
  78. package/esm/src/types.d.ts +126 -0
  79. package/esm/src/types.d.ts.map +1 -0
  80. package/esm/src/types.js +21 -0
  81. package/package.json +4 -92
  82. package/script/mod.d.ts +87 -1
  83. package/script/mod.d.ts.map +1 -1
  84. package/script/mod.js +132 -3
  85. package/script/src/client.d.ts +248 -0
  86. package/script/src/client.d.ts.map +1 -0
  87. package/script/src/client.js +239 -0
  88. package/script/src/emitter.d.ts +53 -0
  89. package/script/src/emitter.d.ts.map +1 -0
  90. package/script/src/emitter.js +59 -0
  91. package/script/src/errors.d.ts +42 -0
  92. package/script/src/errors.d.ts.map +1 -0
  93. package/script/src/errors.js +49 -0
  94. package/script/src/http.d.ts +157 -0
  95. package/script/src/http.d.ts.map +1 -0
  96. package/script/src/http.js +321 -0
  97. package/script/src/namespace.d.ts +59 -0
  98. package/script/src/namespace.d.ts.map +1 -0
  99. package/script/src/namespace.js +83 -0
  100. package/script/src/reactive.d.ts +29 -0
  101. package/script/src/reactive.d.ts.map +1 -0
  102. package/script/src/reactive.js +39 -0
  103. package/script/src/resources/account.d.ts +125 -0
  104. package/script/src/resources/account.d.ts.map +1 -0
  105. package/script/src/resources/account.js +158 -0
  106. package/script/src/resources/api-keys.d.ts +116 -0
  107. package/script/src/resources/api-keys.d.ts.map +1 -0
  108. package/script/src/resources/api-keys.js +110 -0
  109. package/script/src/resources/auth.d.ts +57 -0
  110. package/script/src/resources/auth.d.ts.map +1 -0
  111. package/script/src/resources/auth.js +43 -0
  112. package/script/src/resources/eggs.d.ts +238 -0
  113. package/script/src/resources/eggs.d.ts.map +1 -0
  114. package/script/src/resources/eggs.js +193 -0
  115. package/script/src/resources/hosts.d.ts +62 -0
  116. package/script/src/resources/hosts.d.ts.map +1 -0
  117. package/script/src/resources/hosts.js +67 -0
  118. package/script/src/resources/members.d.ts +138 -0
  119. package/script/src/resources/members.d.ts.map +1 -0
  120. package/script/src/resources/members.js +127 -0
  121. package/script/src/resources/nodes.d.ts +397 -0
  122. package/script/src/resources/nodes.d.ts.map +1 -0
  123. package/script/src/resources/nodes.js +362 -0
  124. package/script/src/resources/server-groups.d.ts +150 -0
  125. package/script/src/resources/server-groups.d.ts.map +1 -0
  126. package/script/src/resources/server-groups.js +116 -0
  127. package/script/src/resources/servers/activity.d.ts +120 -0
  128. package/script/src/resources/servers/activity.d.ts.map +1 -0
  129. package/script/src/resources/servers/activity.js +170 -0
  130. package/script/src/resources/servers/allocations.d.ts +125 -0
  131. package/script/src/resources/servers/allocations.d.ts.map +1 -0
  132. package/script/src/resources/servers/allocations.js +142 -0
  133. package/script/src/resources/servers/connection.d.ts +108 -0
  134. package/script/src/resources/servers/connection.d.ts.map +1 -0
  135. package/script/src/resources/servers/connection.js +173 -0
  136. package/script/src/resources/servers/files.d.ts +164 -0
  137. package/script/src/resources/servers/files.d.ts.map +1 -0
  138. package/script/src/resources/servers/files.js +286 -0
  139. package/script/src/resources/servers/index.d.ts +126 -0
  140. package/script/src/resources/servers/index.d.ts.map +1 -0
  141. package/script/src/resources/servers/index.js +139 -0
  142. package/script/src/resources/servers/profiles.d.ts +138 -0
  143. package/script/src/resources/servers/profiles.d.ts.map +1 -0
  144. package/script/src/resources/servers/profiles.js +182 -0
  145. package/script/src/resources/servers/server.d.ts +136 -0
  146. package/script/src/resources/servers/server.d.ts.map +1 -0
  147. package/script/src/resources/servers/server.js +206 -0
  148. package/script/src/resources/servers/sftp.d.ts +147 -0
  149. package/script/src/resources/servers/sftp.d.ts.map +1 -0
  150. package/script/src/resources/servers/sftp.js +158 -0
  151. package/script/src/resources/servers/types.d.ts +199 -0
  152. package/script/src/resources/servers/types.d.ts.map +1 -0
  153. package/script/src/resources/servers/types.js +2 -0
  154. package/script/src/sse.d.ts +53 -0
  155. package/script/src/sse.d.ts.map +1 -0
  156. package/script/src/sse.js +137 -0
  157. package/script/src/types.d.ts +126 -0
  158. package/script/src/types.d.ts.map +1 -0
  159. package/script/src/types.js +25 -0
  160. package/esm/api.d.ts +0 -76
  161. package/esm/api.d.ts.map +0 -1
  162. package/esm/api.js +0 -187
  163. package/esm/components/auth.d.ts +0 -15
  164. package/esm/components/auth.d.ts.map +0 -1
  165. package/esm/components/auth.js +0 -13
  166. package/esm/components/connection/abstract.d.ts +0 -23
  167. package/esm/components/connection/abstract.d.ts.map +0 -1
  168. package/esm/components/connection/abstract.js +0 -43
  169. package/esm/components/connection/sse.d.ts +0 -20
  170. package/esm/components/connection/sse.d.ts.map +0 -1
  171. package/esm/components/connection/sse.js +0 -65
  172. package/esm/components/egg/egg.d.ts +0 -32
  173. package/esm/components/egg/egg.d.ts.map +0 -1
  174. package/esm/components/egg/egg.js +0 -70
  175. package/esm/components/group.d.ts +0 -14
  176. package/esm/components/group.d.ts.map +0 -1
  177. package/esm/components/group.js +0 -33
  178. package/esm/components/member_2.d.ts +0 -69
  179. package/esm/components/member_2.d.ts.map +0 -1
  180. package/esm/components/member_2.js +0 -140
  181. package/esm/components/node.d.ts +0 -78
  182. package/esm/components/node.d.ts.map +0 -1
  183. package/esm/components/node.js +0 -342
  184. package/esm/components/server/activity.d.ts +0 -45
  185. package/esm/components/server/activity.d.ts.map +0 -1
  186. package/esm/components/server/activity.js +0 -158
  187. package/esm/components/server/allocations.d.ts +0 -45
  188. package/esm/components/server/allocations.d.ts.map +0 -1
  189. package/esm/components/server/allocations.js +0 -146
  190. package/esm/components/server/files.d.ts +0 -50
  191. package/esm/components/server/files.d.ts.map +0 -1
  192. package/esm/components/server/files.js +0 -90
  193. package/esm/components/server/power.d.ts +0 -21
  194. package/esm/components/server/power.d.ts.map +0 -1
  195. package/esm/components/server/power.js +0 -43
  196. package/esm/components/server/profiles.d.ts +0 -63
  197. package/esm/components/server/profiles.d.ts.map +0 -1
  198. package/esm/components/server/profiles.js +0 -163
  199. package/esm/components/server/server.d.ts +0 -141
  200. package/esm/components/server/server.d.ts.map +0 -1
  201. package/esm/components/server/server.js +0 -358
  202. package/esm/components/server/sftp.d.ts +0 -31
  203. package/esm/components/server/sftp.d.ts.map +0 -1
  204. package/esm/components/server/sftp.js +0 -84
  205. package/esm/components/server/startup.d.ts +0 -17
  206. package/esm/components/server/startup.d.ts.map +0 -1
  207. package/esm/components/server/startup.js +0 -21
  208. package/esm/components/server/stats.d.ts +0 -19
  209. package/esm/components/server/stats.d.ts.map +0 -1
  210. package/esm/components/server/stats.js +0 -46
  211. package/esm/utils/cache.d.ts +0 -20
  212. package/esm/utils/cache.d.ts.map +0 -1
  213. package/esm/utils/cache.js +0 -66
  214. package/esm/utils/event.d.ts +0 -38
  215. package/esm/utils/event.d.ts.map +0 -1
  216. package/esm/utils/event.js +0 -71
  217. package/esm/utils/object.d.ts +0 -58
  218. package/esm/utils/object.d.ts.map +0 -1
  219. package/esm/utils/object.js +0 -86
  220. package/esm/utils/subscribe.d.ts +0 -37
  221. package/esm/utils/subscribe.d.ts.map +0 -1
  222. package/esm/utils/subscribe.js +0 -29
  223. package/esm/utils/timer.d.ts +0 -13
  224. package/esm/utils/timer.d.ts.map +0 -1
  225. package/esm/utils/timer.js +0 -32
  226. package/esm/utils/units.d.ts +0 -18
  227. package/esm/utils/units.d.ts.map +0 -1
  228. package/esm/utils/units.js +0 -82
  229. package/script/api.d.ts +0 -76
  230. package/script/api.d.ts.map +0 -1
  231. package/script/api.js +0 -192
  232. package/script/components/auth.d.ts +0 -15
  233. package/script/components/auth.d.ts.map +0 -1
  234. package/script/components/auth.js +0 -17
  235. package/script/components/connection/abstract.d.ts +0 -23
  236. package/script/components/connection/abstract.d.ts.map +0 -1
  237. package/script/components/connection/abstract.js +0 -47
  238. package/script/components/connection/sse.d.ts +0 -20
  239. package/script/components/connection/sse.d.ts.map +0 -1
  240. package/script/components/connection/sse.js +0 -69
  241. package/script/components/egg/egg.d.ts +0 -32
  242. package/script/components/egg/egg.d.ts.map +0 -1
  243. package/script/components/egg/egg.js +0 -74
  244. package/script/components/group.d.ts +0 -14
  245. package/script/components/group.d.ts.map +0 -1
  246. package/script/components/group.js +0 -37
  247. package/script/components/member_2.d.ts +0 -69
  248. package/script/components/member_2.d.ts.map +0 -1
  249. package/script/components/member_2.js +0 -146
  250. package/script/components/node.d.ts +0 -78
  251. package/script/components/node.d.ts.map +0 -1
  252. package/script/components/node.js +0 -349
  253. package/script/components/server/activity.d.ts +0 -45
  254. package/script/components/server/activity.d.ts.map +0 -1
  255. package/script/components/server/activity.js +0 -164
  256. package/script/components/server/allocations.d.ts +0 -45
  257. package/script/components/server/allocations.d.ts.map +0 -1
  258. package/script/components/server/allocations.js +0 -152
  259. package/script/components/server/files.d.ts +0 -50
  260. package/script/components/server/files.d.ts.map +0 -1
  261. package/script/components/server/files.js +0 -94
  262. package/script/components/server/power.d.ts +0 -21
  263. package/script/components/server/power.d.ts.map +0 -1
  264. package/script/components/server/power.js +0 -47
  265. package/script/components/server/profiles.d.ts +0 -63
  266. package/script/components/server/profiles.d.ts.map +0 -1
  267. package/script/components/server/profiles.js +0 -168
  268. package/script/components/server/server.d.ts +0 -141
  269. package/script/components/server/server.d.ts.map +0 -1
  270. package/script/components/server/server.js +0 -362
  271. package/script/components/server/sftp.d.ts +0 -31
  272. package/script/components/server/sftp.d.ts.map +0 -1
  273. package/script/components/server/sftp.js +0 -88
  274. package/script/components/server/startup.d.ts +0 -17
  275. package/script/components/server/startup.d.ts.map +0 -1
  276. package/script/components/server/startup.js +0 -25
  277. package/script/components/server/stats.d.ts +0 -19
  278. package/script/components/server/stats.d.ts.map +0 -1
  279. package/script/components/server/stats.js +0 -50
  280. package/script/utils/cache.d.ts +0 -20
  281. package/script/utils/cache.d.ts.map +0 -1
  282. package/script/utils/cache.js +0 -70
  283. package/script/utils/event.d.ts +0 -38
  284. package/script/utils/event.d.ts.map +0 -1
  285. package/script/utils/event.js +0 -75
  286. package/script/utils/object.d.ts +0 -58
  287. package/script/utils/object.d.ts.map +0 -1
  288. package/script/utils/object.js +0 -90
  289. package/script/utils/subscribe.d.ts +0 -37
  290. package/script/utils/subscribe.d.ts.map +0 -1
  291. package/script/utils/subscribe.js +0 -32
  292. package/script/utils/timer.d.ts +0 -13
  293. package/script/utils/timer.d.ts.map +0 -1
  294. package/script/utils/timer.js +0 -36
  295. package/script/utils/units.d.ts +0 -18
  296. package/script/utils/units.d.ts.map +0 -1
  297. package/script/utils/units.js +0 -86
@@ -1,31 +0,0 @@
1
- import type { MeowPanelApi } from '../../api.js';
2
- import { CachedRelation } from '../../utils/cache.js';
3
- import { Member } from '../member_2.js';
4
- import type { SftpPermissions, SftpUserResponse } from './server_2';
5
- import type { Server } from './server.js';
6
- export declare class SftpUser {
7
- protected readonly api: MeowPanelApi;
8
- protected readonly server: Server;
9
- protected readonly response: SftpUserResponse;
10
- constructor(api: MeowPanelApi, server: Server, response: SftpUserResponse);
11
- get id(): string;
12
- get name(): string;
13
- get username(): string;
14
- readonly password: CachedRelation<string>;
15
- /**
16
- * List of permissions for each file path pattern that this SFTP user has access to.
17
- */
18
- get paths(): Record<string, SftpPermissions[]>;
19
- readonly owner: CachedRelation<Member>;
20
- get lastLoginAt(): Date | null;
21
- get createdAt(): Date;
22
- get updatedAt(): Date;
23
- /**
24
- * Delete this SFTP user.
25
- *
26
- * Calling additional calls to this object may throw an error.
27
- */
28
- delete(): Promise<void>;
29
- setPathPermissions(path: string, permissions: SftpPermissions[]): Promise<void>;
30
- }
31
- //# sourceMappingURL=sftp.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sftp.d.ts","sourceRoot":"","sources":["../../../src/components/server/sftp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,qBAAa,QAAQ;IAEnB,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,YAAY;IACpC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM;IACjC,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB;gBAF1B,GAAG,EAAE,YAAY,EACjB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,gBAAgB;IAQ9C,IAAW,EAAE,IAAI,MAAM,CAEtB;IAED,IAAW,IAAI,IAAI,MAAM,CAExB;IAED,IAAW,QAAQ,IAAI,MAAM,CAE5B;IAED,SAAgB,QAAQ,EAAE,cAAc,CAAC,MAAM,CAAC,CAU9C;IAEF;;OAEG;IACH,IAAW,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,eAAe,EAAE,CAAC,CAEpD;IAED,SAAgB,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,CAE3C;IAEF,IAAW,WAAW,IAAI,IAAI,GAAG,IAAI,CAEpC;IAED,IAAW,SAAS,IAAI,IAAI,CAE3B;IAED,IAAW,SAAS,IAAI,IAAI,CAE3B;IAED;;;;OAIG;IACU,MAAM;IAQN,kBAAkB,CAC9B,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,eAAe,EAAE;CAY/B"}
@@ -1,84 +0,0 @@
1
- import { CachedRelation } from '../../utils/cache.js';
2
- import { Member } from '../member_2.js';
3
- export class SftpUser {
4
- constructor(api, server, response) {
5
- Object.defineProperty(this, "api", {
6
- enumerable: true,
7
- configurable: true,
8
- writable: true,
9
- value: api
10
- });
11
- Object.defineProperty(this, "server", {
12
- enumerable: true,
13
- configurable: true,
14
- writable: true,
15
- value: server
16
- });
17
- Object.defineProperty(this, "response", {
18
- enumerable: true,
19
- configurable: true,
20
- writable: true,
21
- value: response
22
- });
23
- Object.defineProperty(this, "password", {
24
- enumerable: true,
25
- configurable: true,
26
- writable: true,
27
- value: new CachedRelation(() => this.api
28
- .request('GET', `/v1/servers/${this.server.id}/sftp/users/${this.id}`, {
29
- params: { include: 'password' },
30
- })
31
- .then((v) => v.data.password))
32
- });
33
- Object.defineProperty(this, "owner", {
34
- enumerable: true,
35
- configurable: true,
36
- writable: true,
37
- value: new CachedRelation(() => this.api.members.get(this.response.owner_id))
38
- });
39
- if (response.owner) {
40
- this.owner.setCache(new Member(this.api, response.owner));
41
- }
42
- if (response.password)
43
- this.password.setCache(response.password);
44
- }
45
- get id() {
46
- return this.response.id;
47
- }
48
- get name() {
49
- return this.response.name;
50
- }
51
- get username() {
52
- return this.response.username;
53
- }
54
- /**
55
- * List of permissions for each file path pattern that this SFTP user has access to.
56
- */
57
- get paths() {
58
- return this.response.paths;
59
- }
60
- get lastLoginAt() {
61
- return this.response.last_login_at ? new Date(this.response.last_login_at) : null;
62
- }
63
- get createdAt() {
64
- return new Date(this.response.created_at);
65
- }
66
- get updatedAt() {
67
- return new Date(this.response.updated_at);
68
- }
69
- /**
70
- * Delete this SFTP user.
71
- *
72
- * Calling additional calls to this object may throw an error.
73
- */
74
- async delete() {
75
- await this.api.requestUrl('DELETE', `/v1/servers/${this.server.id}/sftp/users/${this.id}`, {});
76
- }
77
- async setPathPermissions(path, permissions) {
78
- await this.api.requestUrl('PATCH', `/v1/servers/${this.server.id}/sftp/users/${this.id}`, {
79
- body: {
80
- paths: { [path]: permissions },
81
- },
82
- });
83
- }
84
- }
@@ -1,17 +0,0 @@
1
- import type { ServerResponse } from './server_2';
2
- type ServerStartup = Readonly<ServerResponse['startup'] & object>;
3
- export declare class StartupParameters {
4
- constructor(data: ServerStartup);
5
- readonly command: string;
6
- readonly variables: Record<Uppercase<string>, CommandVariable>;
7
- }
8
- export interface CommandVariable {
9
- readonly key: string;
10
- name: string;
11
- description: string;
12
- value: string;
13
- default: string;
14
- rules: string;
15
- }
16
- export {};
17
- //# sourceMappingURL=startup.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"startup.d.ts","sourceRoot":"","sources":["../../../src/components/server/startup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,KAAK,aAAa,GAAG,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,CAAC;AAElE,qBAAa,iBAAiB;gBACV,IAAI,EAAE,aAAa;IAQtC,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,SAAgB,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC,CAAC;CACtE;AAED,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACd"}
@@ -1,21 +0,0 @@
1
- export class StartupParameters {
2
- constructor(data) {
3
- Object.defineProperty(this, "command", {
4
- enumerable: true,
5
- configurable: true,
6
- writable: true,
7
- value: void 0
8
- });
9
- Object.defineProperty(this, "variables", {
10
- enumerable: true,
11
- configurable: true,
12
- writable: true,
13
- value: void 0
14
- });
15
- this.command = data.command;
16
- this.variables = {};
17
- for (const [key, value] of Object.entries(data.variables)) {
18
- this.variables[key] = { ...value, key };
19
- }
20
- }
21
- }
@@ -1,19 +0,0 @@
1
- import { Timer } from '../../utils/timer.js';
2
- import { ByteUnit } from '../../utils/units.js';
3
- import { PowerStateEvent } from './power.js';
4
- import type { ServerResponse } from './server_2';
5
- import type { Server } from './server.js';
6
- export declare class ServerStatsEvent {
7
- protected readonly server: Server;
8
- private stats?;
9
- constructor(server: Server, stats?: ServerResponse['status']);
10
- readonly limits: {};
11
- get powerState(): PowerStateEvent;
12
- get uptime(): Timer;
13
- get cpuUsage(): number;
14
- get memoryUsage(): ByteUnit;
15
- get storageUsage(): ByteUnit;
16
- get networkRx(): ByteUnit;
17
- get networkTx(): ByteUnit;
18
- }
19
- //# sourceMappingURL=stats.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../../src/components/server/stats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,qBAAa,gBAAgB;IAE3B,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM;IACjC,OAAO,CAAC,KAAK,CAAC;gBADK,MAAM,EAAE,MAAM,EACzB,KAAK,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC;IAGzC,SAAgB,MAAM,KAAM;IAE5B,IAAW,UAAU,IAAI,eAAe,CAEvC;IAED,IAAW,MAAM,IAAI,KAAK,CAEzB;IAED,IAAW,QAAQ,IAAI,MAAM,CAE5B;IAED,IAAW,WAAW,IAAI,QAAQ,CAEjC;IAED,IAAW,YAAY,IAAI,QAAQ,CAElC;IAED,IAAW,SAAS,IAAI,QAAQ,CAE/B;IAED,IAAW,SAAS,IAAI,QAAQ,CAE/B;CACD"}
@@ -1,46 +0,0 @@
1
- import { Timer } from '../../utils/timer.js';
2
- import { ByteUnit } from '../../utils/units.js';
3
- import { PowerStateEvent } from './power.js';
4
- export class ServerStatsEvent {
5
- constructor(server, stats) {
6
- Object.defineProperty(this, "server", {
7
- enumerable: true,
8
- configurable: true,
9
- writable: true,
10
- value: server
11
- });
12
- Object.defineProperty(this, "stats", {
13
- enumerable: true,
14
- configurable: true,
15
- writable: true,
16
- value: stats
17
- });
18
- Object.defineProperty(this, "limits", {
19
- enumerable: true,
20
- configurable: true,
21
- writable: true,
22
- value: {}
23
- }); // TODO: use the server limit class
24
- }
25
- get powerState() {
26
- return new PowerStateEvent(this.stats?.state || 'error');
27
- }
28
- get uptime() {
29
- return new Timer(this.stats?.utilization.uptime ?? 0);
30
- }
31
- get cpuUsage() {
32
- return this.stats?.utilization.cpu_absolute ?? 0;
33
- }
34
- get memoryUsage() {
35
- return this.stats ? new ByteUnit(this.stats.utilization.memory_bytes, 'b') : ByteUnit.ZERO;
36
- }
37
- get storageUsage() {
38
- return this.stats ? new ByteUnit(this.stats.utilization.disk_bytes, 'b') : ByteUnit.ZERO;
39
- }
40
- get networkRx() {
41
- return this.stats ? new ByteUnit(this.stats.utilization.network.rx_bytes, 'b') : ByteUnit.ZERO;
42
- }
43
- get networkTx() {
44
- return this.stats ? new ByteUnit(this.stats.utilization.network.tx_bytes, 'b') : ByteUnit.ZERO;
45
- }
46
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * Simple cache wrapper that remembers the content of a function call.
3
- */
4
- export declare class CachedRelation<T> {
5
- private readonly _get;
6
- protected cacheId: string | undefined;
7
- protected cache: T | undefined;
8
- protected fetchTime: number | undefined;
9
- protected readonly lifetimeMs: number;
10
- protected getCache(): T | undefined;
11
- get(): Promise<T>;
12
- clear(): void;
13
- setCache(data: T): void;
14
- constructor(_get: () => Promise<T> | T,
15
- /**
16
- * Time in seconds that the data is valid for before calling the {@link get()} function again.
17
- */
18
- lifetimeSeconds?: number);
19
- }
20
- //# sourceMappingURL=cache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/utils/cache.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,cAAc,CAAC,CAAC;IAmC3B,OAAO,CAAC,QAAQ,CAAC,IAAI;IAlCtB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,SAAS,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC;IAC/B,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAEtC,SAAS,CAAC,QAAQ,IAAI,CAAC,GAAG,SAAS;IAQtB,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC;IASvB,KAAK;IAKL,QAAQ,CAAC,IAAI,EAAE,CAAC;gBAOL,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;IAC3C;;OAEG;IACH,eAAe,GAAE,MAAgB;CAIlC"}
@@ -1,66 +0,0 @@
1
- /**
2
- * Simple cache wrapper that remembers the content of a function call.
3
- */
4
- export class CachedRelation {
5
- getCache() {
6
- if (this.fetchTime && Date.now() - this.fetchTime < this.lifetimeMs) {
7
- this.clear();
8
- }
9
- return this.cache;
10
- }
11
- async get() {
12
- const cache = this.getCache();
13
- if (cache)
14
- return cache;
15
- const data = await this._get();
16
- this.cache = data;
17
- return data;
18
- }
19
- clear() {
20
- this.cache = undefined;
21
- this.fetchTime = undefined;
22
- }
23
- setCache(data) {
24
- if (!data)
25
- return;
26
- this.cache = data;
27
- this.fetchTime = Date.now();
28
- }
29
- constructor(_get,
30
- /**
31
- * Time in seconds that the data is valid for before calling the {@link get()} function again.
32
- */
33
- lifetimeSeconds = 30 * 60) {
34
- Object.defineProperty(this, "_get", {
35
- enumerable: true,
36
- configurable: true,
37
- writable: true,
38
- value: _get
39
- });
40
- Object.defineProperty(this, "cacheId", {
41
- enumerable: true,
42
- configurable: true,
43
- writable: true,
44
- value: void 0
45
- });
46
- Object.defineProperty(this, "cache", {
47
- enumerable: true,
48
- configurable: true,
49
- writable: true,
50
- value: void 0
51
- });
52
- Object.defineProperty(this, "fetchTime", {
53
- enumerable: true,
54
- configurable: true,
55
- writable: true,
56
- value: void 0
57
- });
58
- Object.defineProperty(this, "lifetimeMs", {
59
- enumerable: true,
60
- configurable: true,
61
- writable: true,
62
- value: void 0
63
- });
64
- this.lifetimeMs = lifetimeSeconds * 1000;
65
- }
66
- }
@@ -1,38 +0,0 @@
1
- export interface EventFunction<T extends object, K extends keyof T> {
2
- (value: T[K]): unknown;
3
- }
4
- export interface EventManagerListener<T extends object> {
5
- /**
6
- * Add an event listener to a specific event.
7
- * When the event is triggered, the listener is called with the value of the event.
8
- *
9
- * @returns a unique id that can be used to remove the listener.
10
- */
11
- on<K extends keyof T>(event: K, func: EventFunction<T, K>): number;
12
- /**
13
- * Remove an event listener from a specific event.
14
- *
15
- * @param func The listener to remove (must be the same function reference) or the id returned from {@link on}.
16
- * @returns true if the listener was removed
17
- */
18
- off<K extends keyof T>(event: K | number, func?: EventFunction<T, K> | number): boolean;
19
- }
20
- export declare class EventManager<T extends object> implements EventManagerListener<T> {
21
- private static idCounter;
22
- constructor();
23
- protected get nextId(): number;
24
- private readonly eventListeners;
25
- on<K extends keyof T>(event: K, func: EventFunction<T, K>): number;
26
- off<K extends keyof T>(event: K | number, func?: EventFunction<T, K> | number): boolean;
27
- /**
28
- * Dispatch an event to all listeners.
29
- */
30
- dispatch<K extends keyof T>(event: K, value: T[K]): void;
31
- /**
32
- * Assign all event listeners to a function.
33
- * Useful for assigning to event listener handlers.
34
- */
35
- assignAllEvents(applyFunc: <K extends keyof T>(event: K, id: number, func: (value: T[K]) => unknown) => void): void;
36
- removeAll(): void;
37
- }
38
- //# sourceMappingURL=event.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/utils/event.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC;IACjE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,MAAM;IACrD;;;;;OAKG;IACH,EAAE,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC;IACnE;;;;;OAKG;IACH,GAAG,CAAC,CAAC,SAAS,MAAM,CAAC,EACpB,KAAK,EAAE,CAAC,GAAG,MAAM,EACjB,IAAI,CAAC,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,GACjC,OAAO,CAAC;CACX;AAED,qBAAa,YAAY,CAAC,CAAC,SAAS,MAAM,CAAE,YAAW,oBAAoB,CAAC,CAAC,CAAC;IAC7E,OAAO,CAAC,MAAM,CAAC,SAAS,CAAK;;IAI7B,SAAS,KAAK,MAAM,IAAI,MAAM,CAE7B;IAED,OAAO,CAAC,QAAQ,CAAC,cAAc,CAG3B;IAEG,EAAE,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM;IAUlE,GAAG,CAAC,CAAC,SAAS,MAAM,CAAC,EAC3B,KAAK,EAAE,CAAC,GAAG,MAAM,EACjB,IAAI,CAAC,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,GACjC,OAAO;IA4BV;;OAEG;IACI,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;IAIxD;;;OAGG;IACI,eAAe,CACrB,SAAS,EAAE,CAAC,CAAC,SAAS,MAAM,CAAC,EAC5B,KAAK,EAAE,CAAC,EACR,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,KAC1B,IAAI;IASH,SAAS;CAGhB"}
@@ -1,71 +0,0 @@
1
- export class EventManager {
2
- constructor() {
3
- Object.defineProperty(this, "eventListeners", {
4
- enumerable: true,
5
- configurable: true,
6
- writable: true,
7
- value: new Map()
8
- });
9
- }
10
- get nextId() {
11
- return ++EventManager.idCounter;
12
- }
13
- on(event, func) {
14
- if (!this.eventListeners.has(event)) {
15
- this.eventListeners.set(event, new Map());
16
- }
17
- const id = this.nextId;
18
- this.eventListeners.get(event).set(id, func);
19
- return id;
20
- }
21
- off(event, func) {
22
- if (typeof event === 'number') {
23
- for (const value of this.eventListeners.values()) {
24
- const deleted = value.delete(event);
25
- if (deleted)
26
- return true;
27
- }
28
- return false;
29
- }
30
- if (!this.eventListeners.has(event))
31
- return false;
32
- const listeners = this.eventListeners.get(event);
33
- if (typeof func === 'number') {
34
- listeners.delete(func);
35
- return true;
36
- }
37
- for (const [id, listener] of listeners) {
38
- if (listener === func) {
39
- listeners.delete(id);
40
- return true;
41
- }
42
- }
43
- return false;
44
- }
45
- /**
46
- * Dispatch an event to all listeners.
47
- */
48
- dispatch(event, value) {
49
- this.eventListeners.get(event)?.forEach((func) => func(value));
50
- }
51
- /**
52
- * Assign all event listeners to a function.
53
- * Useful for assigning to event listener handlers.
54
- */
55
- assignAllEvents(applyFunc) {
56
- this.eventListeners.forEach((funcs, event) => {
57
- funcs.forEach((func, id) => {
58
- applyFunc(event, id, func);
59
- });
60
- });
61
- }
62
- removeAll() {
63
- this.eventListeners.clear();
64
- }
65
- }
66
- Object.defineProperty(EventManager, "idCounter", {
67
- enumerable: true,
68
- configurable: true,
69
- writable: true,
70
- value: 0
71
- });
@@ -1,58 +0,0 @@
1
- import type { MeowPanelApi } from '../api.js';
2
- import type { Extended } from './types';
3
- /**
4
- * Base class for objects that can be updated with new data from the API.
5
- *
6
- * @param data The initial response data for the object
7
- * @param endpoint The endpoint to the linked object that can be used to fetch the updated data.
8
- */
9
- export declare abstract class UpdatableObject<Response extends object, AdjustedResponse extends object, IncludeParam extends string, ModifiedResponse = Extended<Response, AdjustedResponse>> {
10
- protected readonly api: MeowPanelApi;
11
- protected readonly endpoint: `/${string}`;
12
- constructor(api: MeowPanelApi, data: Response, endpoint: `/${string}`);
13
- protected readonly response: ModifiedResponse;
14
- /**
15
- * Updates the {@link response} object with new properties provided.
16
- * It doesn't automatically update the {@link response} object.
17
- *
18
- * Assign here any additiona properties to update that should match the {@link ModifiedResponse} type parameter.
19
- *
20
- * @param data The new properties
21
- * @returns The updated object
22
- */
23
- protected updateSelf(data: Response): ModifiedResponse;
24
- /**
25
- * Creates an {@link AdjustedResponse} object from the received {@link Response} from the API.
26
- * This is used within the {@link updateSelf} function to apply the additional properties when creating
27
- * or updating new API data to the {@link response} object.
28
- *
29
- * Make use of `oldData?.[key]` to pass old data if it exists, use {@link _CachedRelation CachedRelation} class for partial properties.
30
- *
31
- * @param oldData The previous {@link response} object. Can be `undefined` if the object is new.
32
- * @param newData The {@link Response response} of the API
33
- * @returns The {@link AdjustedResponse} object to apply the {@link response} object to.
34
- */
35
- protected abstract applyResponse(oldData: ModifiedResponse | undefined, newData: Response): AdjustedResponse;
36
- /**
37
- * Fetches new data from the API and updates the {@link response} object.
38
- * Only updates new properties fetched.
39
- *
40
- * Also updates the {@link response} object with new data wrapping to {@link updateSelf}.
41
- *
42
- * @param include A list of properties to include in the response
43
- */
44
- protected fetchSelf(include: IncludeParam[]): Promise<Response>;
45
- /**
46
- * Fetches new data from the API and updates the object with new data.
47
- * Useful to fetch and cache multiple API calls into a single call.
48
- *
49
- * @param include A list of properties to include in the response
50
- */
51
- fetch(include: IncludeParam[]): Promise<void>;
52
- /**
53
- * Send a PATCH request to the server with the given body
54
- * @returns The new server response
55
- */
56
- protected callPatch(body: Record<string, unknown>): Promise<Response>;
57
- }
58
- //# sourceMappingURL=object.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/utils/object.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;GAKG;AACH,8BAAsB,eAAe,CACpC,QAAQ,SAAS,MAAM,EACvB,gBAAgB,SAAS,MAAM,EAC/B,YAAY,SAAS,MAAM,EAC3B,gBAAgB,GAAG,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IAGtD,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,YAAY;IAEpC,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,MAAM,EAAE;gBAFtB,GAAG,EAAE,YAAY,EACpC,IAAI,EAAE,QAAQ,EACK,QAAQ,EAAE,IAAI,MAAM,EAAE;IAK1C,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IAE9C;;;;;;;;OAQG;IACH,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,gBAAgB;IAoBtD;;;;;;;;;;OAUG;IACH,SAAS,CAAC,QAAQ,CAAC,aAAa,CAC/B,OAAO,EAAE,gBAAgB,GAAG,SAAS,EACrC,OAAO,EAAE,QAAQ,GACf,gBAAgB;IAEnB;;;;;;;OAOG;cACa,SAAS,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;IAcrE;;;;;OAKG;IACU,KAAK,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1D;;;OAGG;cACa,SAAS,CACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B,OAAO,CAAC,QAAQ,CAAC;CAUpB"}
@@ -1,86 +0,0 @@
1
- /**
2
- * Base class for objects that can be updated with new data from the API.
3
- *
4
- * @param data The initial response data for the object
5
- * @param endpoint The endpoint to the linked object that can be used to fetch the updated data.
6
- */
7
- export class UpdatableObject {
8
- constructor(api, data, endpoint) {
9
- Object.defineProperty(this, "api", {
10
- enumerable: true,
11
- configurable: true,
12
- writable: true,
13
- value: api
14
- });
15
- Object.defineProperty(this, "endpoint", {
16
- enumerable: true,
17
- configurable: true,
18
- writable: true,
19
- value: endpoint
20
- });
21
- Object.defineProperty(this, "response", {
22
- enumerable: true,
23
- configurable: true,
24
- writable: true,
25
- value: void 0
26
- });
27
- this.response = this.updateSelf(data);
28
- }
29
- /**
30
- * Updates the {@link response} object with new properties provided.
31
- * It doesn't automatically update the {@link response} object.
32
- *
33
- * Assign here any additiona properties to update that should match the {@link ModifiedResponse} type parameter.
34
- *
35
- * @param data The new properties
36
- * @returns The updated object
37
- */
38
- updateSelf(data) {
39
- const response = this.response || {};
40
- for (const [key, value] of Object.entries(data)) {
41
- if (['string', 'number', 'boolean', 'null', 'undefined'].includes(typeof response[key])) {
42
- response[key] = value;
43
- }
44
- }
45
- const modified = this.applyResponse(this.response, data);
46
- for (const [key, value] of Object.entries(modified)) {
47
- response[key] = value;
48
- }
49
- return response;
50
- }
51
- /**
52
- * Fetches new data from the API and updates the {@link response} object.
53
- * Only updates new properties fetched.
54
- *
55
- * Also updates the {@link response} object with new data wrapping to {@link updateSelf}.
56
- *
57
- * @param include A list of properties to include in the response
58
- */
59
- async fetchSelf(include) {
60
- const response = await this.api.request('GET', this.endpoint, {
61
- params: {
62
- include: include.join(','),
63
- },
64
- });
65
- this.updateSelf(response.data);
66
- return response.data;
67
- }
68
- /**
69
- * Fetches new data from the API and updates the object with new data.
70
- * Useful to fetch and cache multiple API calls into a single call.
71
- *
72
- * @param include A list of properties to include in the response
73
- */
74
- async fetch(include) {
75
- await this.fetchSelf(include);
76
- }
77
- /**
78
- * Send a PATCH request to the server with the given body
79
- * @returns The new server response
80
- */
81
- async callPatch(body) {
82
- const { data } = await this.api.request('PATCH', this.endpoint, { body });
83
- this.updateSelf(data);
84
- return data;
85
- }
86
- }
@@ -1,37 +0,0 @@
1
- /**
2
- * The function that controls updates the value of a subscription
3
- */
4
- export type SubscriptionNotifier<T> = (
5
- /**
6
- * Set the new value and notify the subscribers
7
- */
8
- set: (value: T) => void,
9
- /**
10
- * Update the value with access to current one and notify the subscribers
11
- */
12
- update: (
13
- /**
14
- * Update the value and notify the subscribers
15
- * @returns the new value to be set
16
- */
17
- func: (currentValue: T) => T | PromiseLike<T>) => void) => void;
18
- export interface Subscription<T> {
19
- /**
20
- * Subscribe to changes. Immediately calls the function with the current value.
21
- *
22
- * @returns the unsubscribe function
23
- */
24
- subscribe(fn: (value: T) => void): () => void;
25
- }
26
- export interface Subscriable {
27
- subscribe(): Subscription<this>;
28
- }
29
- /**
30
- * Create a variable that can be subscribed to for changes.
31
- *
32
- * @param initValue The initial value
33
- * @param notifier The {@link SubscriptionNotifier} function called on initialization, controlling the current value
34
- * @returns A subscription object allowing to subscribe
35
- */
36
- export declare function createSubscription<T>(initValue: T, notifier: SubscriptionNotifier<T>): Subscription<T>;
37
- //# sourceMappingURL=subscribe.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"subscribe.d.ts","sourceRoot":"","sources":["../../src/utils/subscribe.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI;AACrC;;GAEG;AACH,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI;AACvB;;GAEG;AACH,MAAM,EAAE;AACP;;;GAGG;AACH,IAAI,EAAE,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KACzC,IAAI,KACL,IAAI,CAAC;AAEV,MAAM,WAAW,YAAY,CAAC,CAAC;IAC9B;;;;OAIG;IACH,SAAS,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CAC9C;AAED,MAAM,WAAW,WAAW;IAC3B,SAAS,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;CAChC;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EACnC,SAAS,EAAE,CAAC,EACZ,QAAQ,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAC/B,YAAY,CAAC,CAAC,CAAC,CA0BjB"}
@@ -1,29 +0,0 @@
1
- /**
2
- * Create a variable that can be subscribed to for changes.
3
- *
4
- * @param initValue The initial value
5
- * @param notifier The {@link SubscriptionNotifier} function called on initialization, controlling the current value
6
- * @returns A subscription object allowing to subscribe
7
- */
8
- export function createSubscription(initValue, notifier) {
9
- let currentValue = initValue;
10
- const subscribers = new Set();
11
- function set(value) {
12
- currentValue = value;
13
- subscribers.forEach((fn) => fn(currentValue));
14
- }
15
- async function update(value) {
16
- currentValue = await value(currentValue);
17
- subscribers.forEach((fn) => fn(currentValue));
18
- }
19
- notifier(set, update);
20
- return {
21
- subscribe(fn) {
22
- subscribers.add(fn);
23
- fn(currentValue);
24
- return () => {
25
- subscribers.delete(fn);
26
- };
27
- },
28
- };
29
- }