omegga 1.2.9 → 1.3.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 (255) hide show
  1. package/README.md +20 -1
  2. package/dist/brickadia/config.js +26 -90
  3. package/dist/brickadia/config.js.map +1 -1
  4. package/dist/brickadia/server.js +294 -293
  5. package/dist/brickadia/server.js.map +1 -1
  6. package/dist/cli/auth.js +149 -177
  7. package/dist/cli/auth.js.map +1 -1
  8. package/dist/cli/config.js +64 -66
  9. package/dist/cli/config.js.map +1 -1
  10. package/dist/cli/index.js +14 -14
  11. package/dist/cli/index.js.map +1 -1
  12. package/dist/cli/installer.js +37 -43
  13. package/dist/cli/installer.js.map +1 -1
  14. package/dist/cli/plugin.js +651 -682
  15. package/dist/cli/plugin.js.map +1 -1
  16. package/dist/cli/terminal.js +811 -733
  17. package/dist/cli/terminal.js.map +1 -1
  18. package/dist/config/formats/format_js.js +6 -6
  19. package/dist/config/formats/format_js.js.map +1 -1
  20. package/dist/config/formats/format_yml.js +7 -10
  21. package/dist/config/formats/format_yml.js.map +1 -1
  22. package/dist/config/index.js +46 -68
  23. package/dist/config/index.js.map +1 -1
  24. package/dist/config/reader.js +16 -27
  25. package/dist/config/reader.js.map +1 -1
  26. package/dist/config/validator.js +23 -25
  27. package/dist/config/validator.js.map +1 -1
  28. package/dist/config/writer.js +11 -21
  29. package/dist/config/writer.js.map +1 -1
  30. package/dist/index.js +18 -64
  31. package/dist/index.js.map +1 -1
  32. package/dist/info/default_commands.json.js +39 -0
  33. package/dist/info/default_commands.json.js.map +1 -0
  34. package/dist/logger.js +61 -60
  35. package/dist/logger.js.map +1 -1
  36. package/dist/main.js +424 -471
  37. package/dist/main.js.map +1 -1
  38. package/dist/omegga/auth.js +101 -148
  39. package/dist/omegga/auth.js.map +1 -1
  40. package/dist/omegga/commandInjector.js +261 -251
  41. package/dist/omegga/commandInjector.js.map +1 -1
  42. package/dist/omegga/index.js +14 -52
  43. package/dist/omegga/index.js.map +1 -1
  44. package/dist/omegga/logWrangler.js +224 -275
  45. package/dist/omegga/logWrangler.js.map +1 -1
  46. package/dist/omegga/matchers/auth.js +36 -50
  47. package/dist/omegga/matchers/auth.js.map +1 -1
  48. package/dist/omegga/matchers/chat.js +49 -71
  49. package/dist/omegga/matchers/chat.js.map +1 -1
  50. package/dist/omegga/matchers/command.js +25 -36
  51. package/dist/omegga/matchers/command.js.map +1 -1
  52. package/dist/omegga/matchers/exit.js +15 -18
  53. package/dist/omegga/matchers/exit.js.map +1 -1
  54. package/dist/omegga/matchers/index.js +26 -40
  55. package/dist/omegga/matchers/index.js.map +1 -1
  56. package/dist/omegga/matchers/init.js +20 -23
  57. package/dist/omegga/matchers/init.js.map +1 -1
  58. package/dist/omegga/matchers/interact.js +58 -64
  59. package/dist/omegga/matchers/interact.js.map +1 -1
  60. package/dist/omegga/matchers/join.js +74 -95
  61. package/dist/omegga/matchers/join.js.map +1 -1
  62. package/dist/omegga/matchers/leave.js +43 -56
  63. package/dist/omegga/matchers/leave.js.map +1 -1
  64. package/dist/omegga/matchers/mapChange.js +26 -35
  65. package/dist/omegga/matchers/mapChange.js.map +1 -1
  66. package/dist/omegga/matchers/minigameJoin.js +24 -31
  67. package/dist/omegga/matchers/minigameJoin.js.map +1 -1
  68. package/dist/omegga/matchers/version.js +42 -49
  69. package/dist/omegga/matchers/version.js.map +1 -1
  70. package/dist/omegga/player.js +527 -527
  71. package/dist/omegga/player.js.map +1 -1
  72. package/dist/omegga/plugin/interface.js +91 -98
  73. package/dist/omegga/plugin/interface.js.map +1 -1
  74. package/dist/omegga/plugin/plugin_jsonrpc_stdio.js +524 -429
  75. package/dist/omegga/plugin/plugin_jsonrpc_stdio.js.map +1 -1
  76. package/dist/omegga/plugin/plugin_node_safe/proxyOmegga.js +282 -294
  77. package/dist/omegga/plugin/plugin_node_safe/proxyOmegga.js.map +1 -1
  78. package/dist/omegga/plugin/plugin_node_safe.js +365 -393
  79. package/dist/omegga/plugin/plugin_node_safe.js.map +1 -1
  80. package/dist/omegga/plugin/plugin_node_unsafe.js +119 -179
  81. package/dist/omegga/plugin/plugin_node_unsafe.js.map +1 -1
  82. package/dist/omegga/plugin.js +402 -347
  83. package/dist/omegga/plugin.js.map +1 -1
  84. package/dist/omegga/server.js +742 -774
  85. package/dist/omegga/server.js.map +1 -1
  86. package/dist/omegga/wrapper.js +64 -91
  87. package/dist/omegga/wrapper.js.map +1 -1
  88. package/dist/plugin.js +11 -31
  89. package/dist/plugin.js.map +1 -1
  90. package/dist/softconfig.js +121 -100
  91. package/dist/softconfig.js.map +1 -1
  92. package/dist/updater/steam.js +97 -112
  93. package/dist/updater/steam.js.map +1 -1
  94. package/dist/util/brdb.js +496 -528
  95. package/dist/util/brdb.js.map +1 -1
  96. package/dist/util/brick/checkBounds.js +11 -15
  97. package/dist/util/brick/checkBounds.js.map +1 -1
  98. package/dist/util/brick/constants.js +723 -174
  99. package/dist/util/brick/constants.js.map +1 -1
  100. package/dist/util/brick/displayName.js +204 -211
  101. package/dist/util/brick/displayName.js.map +1 -1
  102. package/dist/util/brick/getBounds.js +29 -41
  103. package/dist/util/brick/getBounds.js.map +1 -1
  104. package/dist/util/brick/getBrickSize.js +6 -7
  105. package/dist/util/brick/getBrickSize.js.map +1 -1
  106. package/dist/util/brick/getScaleAxis.js +24 -30
  107. package/dist/util/brick/getScaleAxis.js.map +1 -1
  108. package/dist/util/brick/index.js +8 -29
  109. package/dist/util/brick/index.js.map +1 -1
  110. package/dist/util/brick/rotate.js +29 -34
  111. package/dist/util/brick/rotate.js.map +1 -1
  112. package/dist/util/brick/setOwnership.js +13 -19
  113. package/dist/util/brick/setOwnership.js.map +1 -1
  114. package/dist/util/chat.js +53 -44
  115. package/dist/util/chat.js.map +1 -1
  116. package/dist/util/color.js +112 -124
  117. package/dist/util/color.js.map +1 -1
  118. package/dist/util/file.js +54 -98
  119. package/dist/util/file.js.map +1 -1
  120. package/dist/util/index.js +84 -106
  121. package/dist/util/index.js.map +1 -1
  122. package/dist/util/map.js +18 -20
  123. package/dist/util/map.js.map +1 -1
  124. package/dist/util/pattern.js +6 -9
  125. package/dist/util/pattern.js.map +1 -1
  126. package/dist/util/time.js +31 -34
  127. package/dist/util/time.js.map +1 -1
  128. package/dist/util/uuid.js +10 -8
  129. package/dist/util/uuid.js.map +1 -1
  130. package/dist/util/wsl.js +19 -25
  131. package/dist/util/wsl.js.map +1 -1
  132. package/dist/version.js +7 -9
  133. package/dist/version.js.map +1 -1
  134. package/dist/webserver/backend/api.js +784 -874
  135. package/dist/webserver/backend/api.js.map +1 -1
  136. package/dist/webserver/backend/calendar.js +14 -17
  137. package/dist/webserver/backend/calendar.js.map +1 -1
  138. package/dist/webserver/backend/database.js +563 -613
  139. package/dist/webserver/backend/database.js.map +1 -1
  140. package/dist/webserver/backend/index.js +153 -191
  141. package/dist/webserver/backend/index.js.map +1 -1
  142. package/dist/webserver/backend/metrics.js +219 -248
  143. package/dist/webserver/backend/metrics.js.map +1 -1
  144. package/dist/webserver/backend/util.js +47 -68
  145. package/dist/webserver/backend/util.js.map +1 -1
  146. package/dist/worker.js +322 -0
  147. package/dist/worker.js.map +1 -0
  148. package/package.json +14 -10
  149. package/templates/safe-ts/omegga.d.ts +1 -1
  150. package/vite.backend.config.mts +46 -0
  151. package/vite.frontend.config.mts +58 -0
  152. package/vitest.backend.config.mts +7 -0
  153. package/dist/brickadia/config.d.ts +0 -3
  154. package/dist/brickadia/presets.d.ts +0 -65
  155. package/dist/brickadia/presets.js +0 -3
  156. package/dist/brickadia/presets.js.map +0 -1
  157. package/dist/brickadia/server.d.ts +0 -36
  158. package/dist/brickadia/types.d.ts +0 -45
  159. package/dist/brickadia/types.js +0 -3
  160. package/dist/brickadia/types.js.map +0 -1
  161. package/dist/cli/auth.d.ts +0 -26
  162. package/dist/cli/config.d.ts +0 -10
  163. package/dist/cli/index.d.ts +0 -30
  164. package/dist/cli/installer.d.ts +0 -1
  165. package/dist/cli/plugin.d.ts +0 -22
  166. package/dist/cli/terminal.d.ts +0 -25
  167. package/dist/config/authorizer.d.ts +0 -2
  168. package/dist/config/authorizer.js +0 -38
  169. package/dist/config/authorizer.js.map +0 -1
  170. package/dist/config/formats/format_js.d.ts +0 -3
  171. package/dist/config/formats/format_yml.d.ts +0 -3
  172. package/dist/config/index.d.ts +0 -18
  173. package/dist/config/reader.d.ts +0 -3
  174. package/dist/config/types.d.ts +0 -50
  175. package/dist/config/types.js +0 -3
  176. package/dist/config/types.js.map +0 -1
  177. package/dist/config/validator.d.ts +0 -6
  178. package/dist/config/writer.d.ts +0 -3
  179. package/dist/index.d.ts +0 -22
  180. package/dist/info/default_commands.json +0 -29
  181. package/dist/logger.d.ts +0 -41
  182. package/dist/main.d.ts +0 -1
  183. package/dist/omegga/auth.d.ts +0 -9
  184. package/dist/omegga/commandInjector.d.ts +0 -35
  185. package/dist/omegga/index.d.ts +0 -7
  186. package/dist/omegga/logWrangler.d.ts +0 -32
  187. package/dist/omegga/matchers/auth.d.ts +0 -10
  188. package/dist/omegga/matchers/chat.d.ts +0 -10
  189. package/dist/omegga/matchers/command.d.ts +0 -7
  190. package/dist/omegga/matchers/exit.d.ts +0 -3
  191. package/dist/omegga/matchers/index.d.ts +0 -3
  192. package/dist/omegga/matchers/init.d.ts +0 -3
  193. package/dist/omegga/matchers/interact.d.ts +0 -4
  194. package/dist/omegga/matchers/join.d.ts +0 -4
  195. package/dist/omegga/matchers/leave.d.ts +0 -4
  196. package/dist/omegga/matchers/mapChange.d.ts +0 -3
  197. package/dist/omegga/matchers/minigameJoin.d.ts +0 -9
  198. package/dist/omegga/matchers/types.d.ts +0 -5
  199. package/dist/omegga/matchers/types.js +0 -3
  200. package/dist/omegga/matchers/types.js.map +0 -1
  201. package/dist/omegga/matchers/version.d.ts +0 -3
  202. package/dist/omegga/player.d.ts +0 -81
  203. package/dist/omegga/plugin/interface.d.ts +0 -30
  204. package/dist/omegga/plugin/plugin_jsonrpc_stdio.d.ts +0 -23
  205. package/dist/omegga/plugin/plugin_node_safe/proxyOmegga.d.ts +0 -145
  206. package/dist/omegga/plugin/plugin_node_safe/worker.d.ts +0 -1
  207. package/dist/omegga/plugin/plugin_node_safe/worker.js +0 -367
  208. package/dist/omegga/plugin/plugin_node_safe/worker.js.map +0 -1
  209. package/dist/omegga/plugin/plugin_node_safe.d.ts +0 -23
  210. package/dist/omegga/plugin/plugin_node_unsafe.d.ts +0 -13
  211. package/dist/omegga/plugin.d.ts +0 -63
  212. package/dist/omegga/server.d.ts +0 -166
  213. package/dist/omegga/types.d.ts +0 -49
  214. package/dist/omegga/types.js +0 -3
  215. package/dist/omegga/types.js.map +0 -1
  216. package/dist/omegga/wrapper.d.ts +0 -32
  217. package/dist/plugin.d.ts +0 -916
  218. package/dist/softconfig.d.ts +0 -67
  219. package/dist/tsconfig.tsbuildinfo +0 -1
  220. package/dist/updater/index.d.ts +0 -1
  221. package/dist/updater/index.js +0 -10
  222. package/dist/updater/index.js.map +0 -1
  223. package/dist/updater/steam.d.ts +0 -52
  224. package/dist/util/brdb.d.ts +0 -31
  225. package/dist/util/brick/checkBounds.d.ts +0 -8
  226. package/dist/util/brick/constants.d.ts +0 -18
  227. package/dist/util/brick/displayName.d.ts +0 -7
  228. package/dist/util/brick/getBounds.d.ts +0 -5
  229. package/dist/util/brick/getBrickSize.d.ts +0 -3
  230. package/dist/util/brick/getScaleAxis.d.ts +0 -3
  231. package/dist/util/brick/index.d.ts +0 -14
  232. package/dist/util/brick/rotate.d.ts +0 -16
  233. package/dist/util/brick/setOwnership.d.ts +0 -12
  234. package/dist/util/chat.d.ts +0 -23
  235. package/dist/util/color.d.ts +0 -13
  236. package/dist/util/file.d.ts +0 -5
  237. package/dist/util/index.d.ts +0 -183
  238. package/dist/util/map.d.ts +0 -6
  239. package/dist/util/pattern.d.ts +0 -1
  240. package/dist/util/time.d.ts +0 -39
  241. package/dist/util/uuid.d.ts +0 -3
  242. package/dist/util/wsl.d.ts +0 -2
  243. package/dist/version.d.ts +0 -2
  244. package/dist/webserver/backend/api.d.ts +0 -115
  245. package/dist/webserver/backend/calendar.d.ts +0 -5
  246. package/dist/webserver/backend/database.d.ts +0 -150
  247. package/dist/webserver/backend/index.d.ts +0 -30
  248. package/dist/webserver/backend/metrics.d.ts +0 -3
  249. package/dist/webserver/backend/types.d.ts +0 -114
  250. package/dist/webserver/backend/types.js +0 -3
  251. package/dist/webserver/backend/types.js.map +0 -1
  252. package/dist/webserver/backend/util.d.ts +0 -2
  253. package/dist/webserver/index.d.ts +0 -2
  254. package/dist/webserver/index.js +0 -9
  255. package/dist/webserver/index.js.map +0 -1
@@ -1,407 +1,379 @@
1
1
  "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
- if (kind === "m") throw new TypeError("Private method is not writable");
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- var _NodeVmPlugin_worker, _NodeVmPlugin_outInterface, _NodeVmPlugin_errInterface;
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const logger_1 = __importDefault(require("../../logger"));
19
- const events_1 = __importDefault(require("events"));
20
- const fs_1 = __importDefault(require("fs"));
21
- const path_1 = __importDefault(require("path"));
22
- const readline_1 = __importDefault(require("readline"));
23
- const worker_threads_1 = require("worker_threads");
24
- const interface_1 = require("./interface");
25
- const proxyOmegga_1 = require("./plugin_node_safe/proxyOmegga");
26
- // Main plugin file (like index.js)
27
- // this isn't named 'index.js' or 'plugin.js' because those may be filenames
28
- // used with other loaders (rpc loader) and are too generic
29
- // omegga.main.js is rather unique and helps avoid collision
30
- const MAIN_FILE = 'omegga.plugin.js';
31
- const MAIN_FILE_TS = 'omegga.plugin.ts';
32
- // Documentation file (contains name, description, author, command helptext)
33
- const DOC_FILE = 'doc.json';
34
- const ACCESS_FILE = 'access.json';
35
- const PLUGIN_FILE = 'plugin.json';
36
- class NodeVmPlugin extends interface_1.Plugin {
37
- // every node vm plugin requires a main file, a doc file, and an access file
38
- // may evolve this so it checks the contents of the doc file later
39
- static canLoad(pluginPath) {
40
- return ((fs_1.default.existsSync(path_1.default.join(pluginPath, MAIN_FILE)) ||
41
- fs_1.default.existsSync(path_1.default.join(pluginPath, MAIN_FILE_TS))) &&
42
- fs_1.default.existsSync(path_1.default.join(pluginPath, DOC_FILE)) &&
43
- fs_1.default.existsSync(path_1.default.join(pluginPath, ACCESS_FILE)));
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const logger = require("../../logger.js");
4
+ const EventEmitter = require("node:events");
5
+ const fs = require("node:fs");
6
+ const path = require("node:path");
7
+ const node_worker_threads = require("node:worker_threads");
8
+ const readline = require("readline");
9
+ const _interface = require("./interface.js");
10
+ const proxyOmegga = require("./plugin_node_safe/proxyOmegga.js");
11
+ const MAIN_FILE = "omegga.plugin.js";
12
+ const MAIN_FILE_TS = "omegga.plugin.ts";
13
+ const DOC_FILE = "doc.json";
14
+ const ACCESS_FILE = "access.json";
15
+ const PLUGIN_FILE = "plugin.json";
16
+ class NodeVmPlugin extends _interface.Plugin {
17
+ #worker;
18
+ #outInterface;
19
+ #errInterface;
20
+ // every node vm plugin requires a main file, a doc file, and an access file
21
+ // may evolve this so it checks the contents of the doc file later
22
+ static canLoad(pluginPath) {
23
+ return (fs.existsSync(path.join(pluginPath, MAIN_FILE)) || fs.existsSync(path.join(pluginPath, MAIN_FILE_TS))) && fs.existsSync(path.join(pluginPath, DOC_FILE)) && fs.existsSync(path.join(pluginPath, ACCESS_FILE));
24
+ }
25
+ // safe node plugins are limited
26
+ static getFormat() {
27
+ return "node_safe";
28
+ }
29
+ constructor(pluginPath, omegga) {
30
+ super(pluginPath, omegga);
31
+ this.plugin = new EventEmitter();
32
+ this.messageCounter = 0;
33
+ this.documentation = _interface.Plugin.readJSON(path.join(pluginPath, DOC_FILE));
34
+ this.isTypeScript = fs.existsSync(path.join(pluginPath, MAIN_FILE_TS));
35
+ this.pluginConfig = _interface.Plugin.readJSON(path.join(pluginPath, PLUGIN_FILE));
36
+ this.access = _interface.Plugin.readJSON(path.join(pluginPath, ACCESS_FILE)) || [];
37
+ this.commands = [];
38
+ if (!(this.access instanceof Array) || !this.access.every((s) => typeof s === "string")) {
39
+ throw new Error("access list not a string array");
44
40
  }
45
- // safe node plugins are limited
46
- static getFormat() {
47
- return 'node_safe';
48
- }
49
- constructor(pluginPath, omegga) {
50
- super(pluginPath, omegga);
51
- _NodeVmPlugin_worker.set(this, void 0);
52
- _NodeVmPlugin_outInterface.set(this, void 0);
53
- _NodeVmPlugin_errInterface.set(this, void 0);
54
- // event emitter and message counter for keeping track of worker events
55
- this.plugin = new events_1.default();
56
- this.messageCounter = 0;
57
- // TODO: validate documentation
58
- this.documentation = interface_1.Plugin.readJSON(path_1.default.join(pluginPath, DOC_FILE));
59
- this.isTypeScript = fs_1.default.existsSync(path_1.default.join(pluginPath, MAIN_FILE_TS));
60
- this.pluginConfig = interface_1.Plugin.readJSON(path_1.default.join(pluginPath, PLUGIN_FILE));
61
- // access list is a list of builtin requires
62
- // can be ['*'] for everything
63
- this.access = interface_1.Plugin.readJSON(path_1.default.join(pluginPath, ACCESS_FILE)) || [];
64
- // list of registered commands
65
- this.commands = [];
66
- // verify access is an array of strings
67
- if (!(this.access instanceof Array) ||
68
- !this.access.every(s => typeof s === 'string')) {
69
- throw new Error('access list not a string array');
70
- }
71
- // plugin name
72
- const name = this.getName();
73
- // when the worker emits an error or a log, pass it up to omegga
74
- this.plugin.on('error', (resp, ...args) => {
75
- logger_1.default.error(name.brightRed.underline, '!>'.red, ...args);
76
- this.notify(resp);
77
- });
78
- this.plugin.on('log', (resp, ...args) => {
79
- logger_1.default.log(name.underline, '>>'.green, ...args);
80
- this.notify(resp);
81
- });
82
- // let the worker write commands to brickadia
83
- this.plugin.on('exec', (_, cmd) => omegga.writeln(cmd));
84
- // storage interface
85
- this.plugin.on('store.get', async (resp, key) => {
86
- try {
87
- this.notify(resp, await this.storage.get(key));
88
- }
89
- catch (e) {
90
- logger_1.default.error(name.brightRed.underline, '!>'.red, 'error in store.get of', key, e);
91
- }
92
- });
93
- this.plugin.on('store.set', async (resp, key, value) => {
94
- try {
95
- await this.storage.set(key, JSON.parse(value));
96
- }
97
- catch (e) {
98
- logger_1.default.error(name.brightRed.underline, '!>'.red, 'error in store.set of', key, value, e);
99
- }
100
- this.notify(resp);
101
- });
102
- this.plugin.on('store.delete', async (resp, key) => {
103
- try {
104
- await this.storage.delete(key);
105
- }
106
- catch (e) {
107
- logger_1.default.error(name.brightRed.underline, '!>'.red, 'error in store.delete of', key, e);
108
- }
109
- this.notify(resp);
110
- });
111
- this.plugin.on('store.wipe', async (resp) => {
112
- try {
113
- await this.storage.wipe();
114
- }
115
- catch (e) {
116
- logger_1.default.error(name.brightRed.underline, '!>'.red, 'error in store.wipe', e);
117
- }
118
- this.notify(resp);
41
+ const name = this.getName();
42
+ this.plugin.on("error", (resp, ...args) => {
43
+ logger.default.error(name.brightRed.underline, "!>".red, ...args);
44
+ this.notify(resp);
45
+ });
46
+ this.plugin.on("log", (resp, ...args) => {
47
+ logger.default.log(name.underline, ">>".green, ...args);
48
+ this.notify(resp);
49
+ });
50
+ this.plugin.on("exec", (_, cmd) => omegga.writeln(cmd));
51
+ this.plugin.on("store.get", async (resp, key) => {
52
+ try {
53
+ this.notify(resp, await this.storage.get(key));
54
+ } catch (e) {
55
+ logger.default.error(
56
+ name.brightRed.underline,
57
+ "!>".red,
58
+ "error in store.get of",
59
+ key,
60
+ e
61
+ );
62
+ }
63
+ });
64
+ this.plugin.on("store.set", async (resp, key, value) => {
65
+ try {
66
+ await this.storage.set(key, JSON.parse(value));
67
+ } catch (e) {
68
+ logger.default.error(
69
+ name.brightRed.underline,
70
+ "!>".red,
71
+ "error in store.set of",
72
+ key,
73
+ value,
74
+ e
75
+ );
76
+ }
77
+ this.notify(resp);
78
+ });
79
+ this.plugin.on("store.delete", async (resp, key) => {
80
+ try {
81
+ await this.storage.delete(key);
82
+ } catch (e) {
83
+ logger.default.error(
84
+ name.brightRed.underline,
85
+ "!>".red,
86
+ "error in store.delete of",
87
+ key,
88
+ e
89
+ );
90
+ }
91
+ this.notify(resp);
92
+ });
93
+ this.plugin.on("store.wipe", async (resp) => {
94
+ try {
95
+ await this.storage.wipe();
96
+ } catch (e) {
97
+ logger.default.error(
98
+ name.brightRed.underline,
99
+ "!>".red,
100
+ "error in store.wipe",
101
+ e
102
+ );
103
+ }
104
+ this.notify(resp);
105
+ });
106
+ this.plugin.on("store.count", async (resp) => {
107
+ try {
108
+ this.notify(resp, await this.storage.count());
109
+ } catch (e) {
110
+ logger.default.error(
111
+ name.brightRed.underline,
112
+ "!>".red,
113
+ "error in store.count",
114
+ e
115
+ );
116
+ }
117
+ });
118
+ this.plugin.on("store.keys", async (resp) => {
119
+ try {
120
+ this.notify(resp, await this.storage.keys());
121
+ } catch (e) {
122
+ logger.default.error(
123
+ name.brightRed.underline,
124
+ "!>".red,
125
+ "error in store.keys",
126
+ e
127
+ );
128
+ }
129
+ });
130
+ this.plugin.on("getPlugin", async (resp, name2) => {
131
+ const plugin = this.omegga.pluginLoader.plugins.find(
132
+ (p) => p.getName() === name2
133
+ );
134
+ if (plugin) {
135
+ this.notify(resp, {
136
+ name: name2,
137
+ documentation: plugin.getDocumentation(),
138
+ loaded: plugin.isLoaded()
119
139
  });
120
- this.plugin.on('store.count', async (resp) => {
121
- try {
122
- this.notify(resp, await this.storage.count());
123
- }
124
- catch (e) {
125
- logger_1.default.error(name.brightRed.underline, '!>'.red, 'error in store.count', e);
126
- }
127
- });
128
- this.plugin.on('store.keys', async (resp) => {
129
- try {
130
- this.notify(resp, await this.storage.keys());
131
- }
132
- catch (e) {
133
- logger_1.default.error(name.brightRed.underline, '!>'.red, 'error in store.keys', e);
134
- }
135
- });
136
- // plugin fetching
137
- this.plugin.on('getPlugin', async (resp, name) => {
138
- const plugin = this.omegga.pluginLoader.plugins.find(p => p.getName() === name);
139
- if (plugin) {
140
- this.notify(resp, {
141
- name,
142
- documentation: plugin.getDocumentation(),
143
- loaded: plugin.isLoaded(),
144
- });
145
- }
146
- else {
147
- this.notify(resp);
148
- }
149
- });
150
- this.plugin.on('emitPlugin', async (resp, target, ev, args) => {
151
- const plugin = this.omegga.pluginLoader.plugins.find(p => p.getName() === target);
152
- if (plugin) {
153
- let r = await plugin.emitPlugin(ev, name, args);
154
- this.notify(resp, r);
155
- }
156
- else {
157
- logger_1.default.error(name.brightRed.underline, '!>'.red, 'error in emitPlugin');
158
- }
159
- });
160
- // command registration
161
- this.plugin.on('command.registers', async (_, blob) => {
162
- if (typeof blob !== 'string')
163
- return;
164
- const registers = JSON.parse(blob);
165
- // ensure registers is an array of strings
166
- if (!(registers instanceof Array) ||
167
- registers.some(i => typeof i !== 'string'))
168
- return;
169
- this.commands = registers;
170
- });
171
- // listen on every message, post them to to the worker
172
- this.eventPassthrough = this.eventPassthrough.bind(this);
173
- }
174
- // emit a custom plugin event
175
- async emitPlugin(ev, from, args) {
176
- var _a;
177
- const [r] = (_a = (await this.emit('emitPlugin', ev, from, args))) !== null && _a !== void 0 ? _a : [];
178
- return r;
179
- }
180
- // documentation is based on doc.json file
181
- getDocumentation() {
182
- return this.documentation;
183
- }
184
- // loaded state is based on if a worker exists
185
- isLoaded() {
186
- return !!__classPrivateFieldGet(this, _NodeVmPlugin_worker, "f");
187
- }
188
- // determing if a command is registered
189
- isCommand(cmd) {
190
- return this.commands.includes(cmd);
191
- }
192
- // require the plugin into the system, run the init func
193
- async load() {
194
- var _a;
195
- // can't load the plugin if it's already loaded
196
- if (typeof __classPrivateFieldGet(this, _NodeVmPlugin_worker, "f") !== 'undefined')
197
- return false;
198
- // vm restriction settings, default is access to everything
199
- const vmOptions = {
200
- builtin: this.access, // TODO: reference access file
201
- external: true, // TODO: reference access file
202
- isTypeScript: this.isTypeScript,
203
- };
204
- this.commands = [];
205
- try {
206
- const config = await this.storage.getConfig();
207
- if ((_a = this.pluginConfig) === null || _a === void 0 ? void 0 : _a.emitConfig) {
208
- await fs_1.default.promises.writeFile(path_1.default.join(this.path, this.pluginConfig.emitConfig), JSON.stringify(config));
209
- }
210
- this.createWorker();
211
- // tell the worker its name :)
212
- await this.emit('name', this.getName());
213
- // create the vm, export the plugin's class
214
- logger_1.default.verbose('Loading safe plugin');
215
- if (!(await this.emit('load', this.path, vmOptions))[0])
216
- throw '';
217
- // get some initial information to create an omegga proxy
218
- const initialData = (0, proxyOmegga_1.bootstrap)(this.omegga);
219
- // send all of the mock events to the proxy omegga
220
- logger_1.default.verbose('Sending initial data to safe plugin');
221
- for (const ev in initialData) {
222
- try {
223
- __classPrivateFieldGet(this, _NodeVmPlugin_worker, "f").postMessage({
224
- action: 'brickadiaEvent',
225
- args: [ev, ...initialData[ev]],
226
- });
227
- }
228
- catch (e) {
229
- /* just writing 'safe' code :) */
230
- }
231
- }
232
- // pass events through
233
- this.omegga.on('*', this.eventPassthrough);
234
- logger_1.default.verbose('Starting safe plugin');
235
- // actually start the plugin
236
- if (!(await this.emit('start', config))[0])
237
- throw 'plugin failed start';
238
- this.emitStatus();
239
- return true;
240
- }
241
- catch (e) {
242
- // kill the worker
243
- await this.emit('kill');
244
- logger_1.default.error('!>'.red, 'error loading node vm plugin', this.getName().brightRed.underline, e);
245
- this.emitStatus();
246
- return false;
247
- }
248
- }
249
- // disrequire the plugin into the system, run the stop func
250
- unload() {
251
- let frozen = true, timed = false;
252
- return Promise.race([
253
- (async () => {
254
- // can't unload the plugin if it hasn't been loaded
255
- if (typeof __classPrivateFieldGet(this, _NodeVmPlugin_worker, "f") === 'undefined')
256
- return false;
257
- try {
258
- // stop the plugin (cleanly)
259
- await this.emit('stop');
260
- // remove listeners
261
- this.omegga.off('*', this.eventPassthrough);
262
- // let the unload function wait for the worker to properly cleanup
263
- const promise = new Promise(res => {
264
- __classPrivateFieldGet(this, _NodeVmPlugin_worker, "f").once('exit', res);
265
- });
266
- // kill the worker
267
- await this.emit('kill');
268
- // wait for the worker to exit
269
- await promise;
270
- frozen = false;
271
- if (timed)
272
- return;
273
- this.emitStatus();
274
- this.commands = [];
275
- return true;
276
- }
277
- catch (e) {
278
- frozen = false;
279
- if (timed)
280
- return;
281
- logger_1.default.error('!>'.red, 'error unloading node plugin', this.getName().brightRed.underline, e);
282
- this.emitStatus();
283
- return false;
284
- }
285
- })(),
286
- new Promise(resolve => {
287
- // check if the worker is frozen (while true)
288
- setTimeout(() => {
289
- if (!frozen)
290
- return;
291
- this.plugin.emit('error', 0, 'I appear to be in an unresponsive state - terminating worker');
292
- // remove listeners
293
- this.omegga.off('*', this.eventPassthrough);
294
- // tell the worker to exit
295
- if (__classPrivateFieldGet(this, _NodeVmPlugin_worker, "f"))
296
- __classPrivateFieldGet(this, _NodeVmPlugin_worker, "f").emit('exit');
297
- // terminate the worker if it still exists
298
- try {
299
- if (__classPrivateFieldGet(this, _NodeVmPlugin_worker, "f"))
300
- __classPrivateFieldGet(this, _NodeVmPlugin_worker, "f").terminate();
301
- }
302
- catch (err) {
303
- console.error('error terminating worker:', err);
304
- }
305
- timed = true;
306
- resolve(true);
307
- this.emitStatus();
308
- }, 5000);
309
- }),
310
- ]);
311
- }
312
- // emit an action to the worker and return a promise with its response
313
- emit(action, ...args) {
314
- if (!__classPrivateFieldGet(this, _NodeVmPlugin_worker, "f"))
315
- return;
316
- const messageId = 'message:' + this.messageCounter++;
317
- // promise waits for the message to resolve
318
- const promise = new Promise(resolve => this.plugin.once(messageId, (_, ...x) => resolve(x)));
319
- // post the message
140
+ } else {
141
+ this.notify(resp);
142
+ }
143
+ });
144
+ this.plugin.on("emitPlugin", async (resp, target, ev, args) => {
145
+ const plugin = this.omegga.pluginLoader.plugins.find(
146
+ (p) => p.getName() === target
147
+ );
148
+ if (plugin) {
149
+ let r = await plugin.emitPlugin(ev, name, args);
150
+ this.notify(resp, r);
151
+ } else {
152
+ logger.default.error(name.brightRed.underline, "!>".red, "error in emitPlugin");
153
+ }
154
+ });
155
+ this.plugin.on("command.registers", async (_, blob) => {
156
+ if (typeof blob !== "string") return;
157
+ const registers = JSON.parse(blob);
158
+ if (!(registers instanceof Array) || registers.some((i) => typeof i !== "string"))
159
+ return;
160
+ this.commands = registers;
161
+ });
162
+ this.eventPassthrough = this.eventPassthrough.bind(this);
163
+ }
164
+ // emit a custom plugin event
165
+ async emitPlugin(ev, from, args) {
166
+ const [r] = await this.emit("emitPlugin", ev, from, args) ?? [];
167
+ return r;
168
+ }
169
+ // documentation is based on doc.json file
170
+ getDocumentation() {
171
+ return this.documentation;
172
+ }
173
+ // loaded state is based on if a worker exists
174
+ isLoaded() {
175
+ return !!this.#worker;
176
+ }
177
+ // determing if a command is registered
178
+ isCommand(cmd) {
179
+ return this.commands.includes(cmd);
180
+ }
181
+ // require the plugin into the system, run the init func
182
+ async load() {
183
+ if (typeof this.#worker !== "undefined") return false;
184
+ const vmOptions = {
185
+ builtin: this.access,
186
+ // TODO: reference access file
187
+ external: true,
188
+ // TODO: reference access file
189
+ isTypeScript: this.isTypeScript
190
+ };
191
+ this.commands = [];
192
+ try {
193
+ const config = await this.storage.getConfig();
194
+ if (this.pluginConfig?.emitConfig) {
195
+ await fs.promises.writeFile(
196
+ path.join(this.path, this.pluginConfig.emitConfig),
197
+ JSON.stringify(config)
198
+ );
199
+ }
200
+ this.createWorker();
201
+ await this.emit("name", this.getName());
202
+ logger.default.verbose("Loading safe plugin");
203
+ if (!(await this.emit("load", this.path, vmOptions))[0]) throw "";
204
+ const initialData = proxyOmegga.bootstrap(this.omegga);
205
+ logger.default.verbose("Sending initial data to safe plugin");
206
+ for (const ev in initialData) {
320
207
  try {
321
- __classPrivateFieldGet(this, _NodeVmPlugin_worker, "f").postMessage({
322
- action,
323
- args: [messageId, ...args],
324
- });
325
- }
326
- catch (e) {
327
- return Promise.reject(e);
208
+ this.#worker.postMessage({
209
+ action: "brickadiaEvent",
210
+ args: [ev, ...initialData[ev]]
211
+ });
212
+ } catch (e) {
328
213
  }
329
- // return the promise
330
- return promise;
214
+ }
215
+ this.omegga.on("*", this.eventPassthrough);
216
+ logger.default.verbose("Starting safe plugin");
217
+ if (!(await this.emit("start", config))[0]) throw "plugin failed start";
218
+ this.emitStatus();
219
+ return true;
220
+ } catch (e) {
221
+ await this.emit("kill");
222
+ logger.default.error(
223
+ "!>".red,
224
+ "error loading node vm plugin",
225
+ this.getName().brightRed.underline,
226
+ e
227
+ );
228
+ this.emitStatus();
229
+ return false;
331
230
  }
332
- // notify a response to the worker
333
- notify(action, ...args) {
334
- if (!__classPrivateFieldGet(this, _NodeVmPlugin_worker, "f"))
335
- return;
336
- // post the message
231
+ }
232
+ // disrequire the plugin into the system, run the stop func
233
+ unload() {
234
+ let frozen = true, timed = false;
235
+ return Promise.race([
236
+ (async () => {
237
+ if (typeof this.#worker === "undefined") return false;
337
238
  try {
338
- __classPrivateFieldGet(this, _NodeVmPlugin_worker, "f").postMessage({
339
- action,
340
- args: [...args],
341
- });
342
- }
343
- catch (e) {
344
- // do nothing here
239
+ await this.emit("stop");
240
+ this.omegga.off("*", this.eventPassthrough);
241
+ const promise = new Promise((res) => {
242
+ this.#worker.once("exit", res);
243
+ });
244
+ await this.emit("kill");
245
+ await promise;
246
+ frozen = false;
247
+ if (timed) return;
248
+ this.emitStatus();
249
+ this.commands = [];
250
+ return true;
251
+ } catch (e) {
252
+ frozen = false;
253
+ if (timed) return;
254
+ logger.default.error(
255
+ "!>".red,
256
+ "error unloading node plugin",
257
+ this.getName().brightRed.underline,
258
+ e
259
+ );
260
+ this.emitStatus();
261
+ return false;
345
262
  }
263
+ })(),
264
+ new Promise((resolve) => {
265
+ setTimeout(() => {
266
+ if (!frozen) return;
267
+ this.plugin.emit(
268
+ "error",
269
+ 0,
270
+ "I appear to be in an unresponsive state - terminating worker"
271
+ );
272
+ this.omegga.off("*", this.eventPassthrough);
273
+ if (this.#worker) this.#worker.emit("exit");
274
+ try {
275
+ if (this.#worker) this.#worker.terminate();
276
+ } catch (err) {
277
+ console.error("error terminating worker:", err);
278
+ }
279
+ timed = true;
280
+ resolve(true);
281
+ this.emitStatus();
282
+ }, 5e3);
283
+ })
284
+ ]);
285
+ }
286
+ // emit an action to the worker and return a promise with its response
287
+ emit(action, ...args) {
288
+ if (!this.#worker) return;
289
+ const messageId = "message:" + this.messageCounter++;
290
+ const promise = new Promise(
291
+ (resolve) => this.plugin.once(messageId, (_, ...x) => resolve(x))
292
+ );
293
+ try {
294
+ this.#worker.postMessage({
295
+ action,
296
+ args: [messageId, ...args]
297
+ });
298
+ } catch (e) {
299
+ return Promise.reject(e);
346
300
  }
347
- // create the worker for this plugin, attach emitter
348
- createWorker() {
349
- __classPrivateFieldSet(this, _NodeVmPlugin_worker, new worker_threads_1.Worker(path_1.default.join(__dirname, 'plugin_node_safe/worker.js'), {
350
- stdout: true,
351
- env: {
352
- VERBOSE: logger_1.default.VERBOSE + '',
353
- },
354
- }), "f");
355
- // pipe plugin output into omegga
356
- __classPrivateFieldSet(this, _NodeVmPlugin_outInterface, readline_1.default.createInterface({
357
- input: __classPrivateFieldGet(this, _NodeVmPlugin_worker, "f").stdout,
358
- terminal: false,
359
- }), "f");
360
- __classPrivateFieldSet(this, _NodeVmPlugin_errInterface, readline_1.default.createInterface({
361
- input: __classPrivateFieldGet(this, _NodeVmPlugin_worker, "f").stderr,
362
- terminal: false,
363
- }), "f");
364
- __classPrivateFieldGet(this, _NodeVmPlugin_outInterface, "f").on('line', logger_1.default.log);
365
- __classPrivateFieldGet(this, _NodeVmPlugin_errInterface, "f").on('line', logger_1.default.error);
366
- // attach message emitter
367
- __classPrivateFieldGet(this, _NodeVmPlugin_worker, "f").on('message', ({ action, args }) => this.plugin.emit(action, ...args));
368
- // broadcast an error if there is one
369
- __classPrivateFieldGet(this, _NodeVmPlugin_worker, "f").on('error', err => {
370
- logger_1.default.error('!>'.red, 'error in plugin', this.getName().brightRed.underline, err);
371
- });
372
- // when the worker exits - set its variable to undefined this knows it's stopped
373
- __classPrivateFieldGet(this, _NodeVmPlugin_worker, "f").on('exit', () => {
374
- this.omegga.off('*', this.eventPassthrough);
375
- __classPrivateFieldGet(this, _NodeVmPlugin_outInterface, "f").removeAllListeners('line');
376
- __classPrivateFieldGet(this, _NodeVmPlugin_errInterface, "f").removeAllListeners('line');
377
- try {
378
- if (__classPrivateFieldGet(this, _NodeVmPlugin_worker, "f"))
379
- __classPrivateFieldGet(this, _NodeVmPlugin_worker, "f").terminate();
380
- }
381
- catch (err) {
382
- logger_1.default.error('!>'.red, 'Error terminating worker for', this.getName().brightRed.underline, err);
383
- }
384
- __classPrivateFieldSet(this, _NodeVmPlugin_worker, undefined, "f");
385
- this.emitStatus();
386
- });
301
+ return promise;
302
+ }
303
+ // notify a response to the worker
304
+ notify(action, ...args) {
305
+ if (!this.#worker) return;
306
+ try {
307
+ this.#worker.postMessage({
308
+ action,
309
+ args: [...args]
310
+ });
311
+ } catch (e) {
387
312
  }
388
- eventPassthrough(...args) {
389
- // worker does not exist
390
- if (!__classPrivateFieldGet(this, _NodeVmPlugin_worker, "f"))
391
- return;
392
- try {
393
- // post the message
394
- __classPrivateFieldGet(this, _NodeVmPlugin_worker, "f").postMessage({
395
- action: 'brickadiaEvent',
396
- args,
397
- });
398
- }
399
- catch (e) {
400
- // make sure post message doesn't crash the entire app
401
- logger_1.default.error('!>'.red, 'error sending to plugin', ...args, e);
313
+ }
314
+ // create the worker for this plugin, attach emitter
315
+ createWorker() {
316
+ this.#worker = new node_worker_threads.Worker(
317
+ // vite transpiles worker.ts to dist/worker.js
318
+ path.join(__dirname, "../../worker.js"),
319
+ {
320
+ stdout: true,
321
+ env: {
322
+ VERBOSE: logger.default.VERBOSE + ""
402
323
  }
324
+ }
325
+ );
326
+ this.#outInterface = readline.createInterface({
327
+ input: this.#worker.stdout,
328
+ terminal: false
329
+ });
330
+ this.#errInterface = readline.createInterface({
331
+ input: this.#worker.stderr,
332
+ terminal: false
333
+ });
334
+ this.#outInterface.on("line", logger.default.log);
335
+ this.#errInterface.on("line", logger.default.error);
336
+ this.#worker.on(
337
+ "message",
338
+ ({ action, args }) => this.plugin.emit(action, ...args)
339
+ );
340
+ this.#worker.on("error", (err) => {
341
+ logger.default.error(
342
+ "!>".red,
343
+ "error in plugin",
344
+ this.getName().brightRed.underline,
345
+ err
346
+ );
347
+ });
348
+ this.#worker.on("exit", () => {
349
+ this.omegga.off("*", this.eventPassthrough);
350
+ this.#outInterface.removeAllListeners("line");
351
+ this.#errInterface.removeAllListeners("line");
352
+ try {
353
+ if (this.#worker) this.#worker.terminate();
354
+ } catch (err) {
355
+ logger.default.error(
356
+ "!>".red,
357
+ "Error terminating worker for",
358
+ this.getName().brightRed.underline,
359
+ err
360
+ );
361
+ }
362
+ this.#worker = void 0;
363
+ this.emitStatus();
364
+ });
365
+ }
366
+ eventPassthrough(...args) {
367
+ if (!this.#worker) return;
368
+ try {
369
+ this.#worker.postMessage({
370
+ action: "brickadiaEvent",
371
+ args
372
+ });
373
+ } catch (e) {
374
+ logger.default.error("!>".red, "error sending to plugin", ...args, e);
403
375
  }
376
+ }
404
377
  }
405
- _NodeVmPlugin_worker = new WeakMap(), _NodeVmPlugin_outInterface = new WeakMap(), _NodeVmPlugin_errInterface = new WeakMap();
406
378
  exports.default = NodeVmPlugin;
407
- //# sourceMappingURL=plugin_node_safe.js.map
379
+ //# sourceMappingURL=plugin_node_safe.js.map