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,53 +1,15 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.commandInjector = exports.LogWrangler = exports.auth = exports.OmeggaWrapper = exports.Player = exports.Plugin = void 0;
40
- // Plugin loader format
41
- exports.Plugin = __importStar(require("./plugin"));
42
- // Player interface
43
- exports.Player = __importStar(require("./player"));
44
- // acts as the interface between server logs and matchers
45
- exports.OmeggaWrapper = __importStar(require("./wrapper"));
46
- // auth token generation helpers
47
- exports.auth = __importStar(require("./auth"));
48
- // tackles the problem of reading brickadia logs
49
- exports.LogWrangler = __importStar(require("./logWrangler"));
50
- // injects commands that only need a log wrangler to function
51
- exports.commandInjector = __importStar(require("./commandInjector"));
52
- __exportStar(require("./types"), exports);
53
- //# sourceMappingURL=index.js.map
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const plugin = require("./plugin.js");
4
+ const player = require("./player.js");
5
+ const wrapper = require("./wrapper.js");
6
+ const auth = require("./auth.js");
7
+ const logWrangler = require("./logWrangler.js");
8
+ const commandInjector = require("./commandInjector.js");
9
+ exports.Plugin = plugin;
10
+ exports.Player = player;
11
+ exports.OmeggaWrapper = wrapper;
12
+ exports.auth = auth;
13
+ exports.LogWrangler = logWrangler;
14
+ exports.commandInjector = commandInjector;
15
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/omegga/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uBAAuB;AACvB,mDAAmC;AAEnC,mBAAmB;AACnB,mDAAmC;AAEnC,yDAAyD;AACzD,2DAA2C;AAE3C,gCAAgC;AAChC,+CAA+B;AAE/B,gDAAgD;AAChD,6DAA6C;AAE7C,6DAA6D;AAC7D,qEAAqD;AAErD,0CAAwB"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
@@ -1,287 +1,236 @@
1
1
  "use strict";
2
- /*
3
- The wrapper combines the things looking at or waiting for logs with the actual server logs
4
- */
5
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
6
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
7
- 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");
8
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
9
- };
10
- var __importDefault = (this && this.__importDefault) || function (mod) {
11
- return (mod && mod.__esModule) ? mod : { "default": mod };
12
- };
13
- var _LogWrangler_matchers, _LogWrangler_watchers;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const logger_1 = __importDefault(require("../logger"));
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const logger = require("../logger.js");
16
4
  const GENERIC_LINE_REGEX = /^(\[(?<date>\d{4}\.\d\d.\d\d-\d\d.\d\d.\d\d:\d{3})\]\[\s*(?<counter>\d+)\])?(?<generator>\w+): (?<data>.+)$/;
17
5
  class LogWrangler {
18
- constructor(omegga) {
19
- // list of patterns and callbacks watching the brickadia logs in general
20
- _LogWrangler_matchers.set(this, []);
21
- // list of patterns and promises waiting for specific console logs
22
- _LogWrangler_watchers.set(this, []);
23
- // passthru functions
24
- this.exec = cmd => omegga.writeln(cmd);
25
- this.getPlayer = (arg) => omegga.getPlayer(arg);
26
- this.getVersion = () => omegga.version;
27
- // callback reads in new lines
28
- this.callback = this.handleLog.bind(this);
29
- this.addMatcher = this.addMatcher.bind(this);
30
- this.addWatcher = this.addWatcher.bind(this);
31
- this.watchLogArray = this.watchLogArray.bind(this);
32
- this.watchLogChunk = this.watchLogChunk.bind(this);
33
- this.omegga = omegga;
34
- }
35
- // add a new matcher to listen in on the logs
36
- // pattern is regex or a function that returns a match
37
- // callback is a function that receives the result of the pattern
38
- // returns a deregister function
39
- addMatcher(pattern, callback) {
40
- if ((typeof pattern !== 'function' && !(pattern instanceof RegExp)) ||
41
- typeof callback !== 'function')
42
- return undefined;
43
- // create the matcher from the callback and pattern, add it to the matchers
44
- const matcher = { pattern, callback };
45
- __classPrivateFieldGet(this, _LogWrangler_matchers, "f").push(matcher);
46
- // return a function to remove this matcher from the list of matchers
47
- return () => {
48
- const index = __classPrivateFieldGet(this, _LogWrangler_matchers, "f").indexOf(matcher);
49
- if (index > -1)
50
- __classPrivateFieldGet(this, _LogWrangler_matchers, "f").splice(index, 0);
51
- };
52
- }
53
- // wait for stdout to match this regex or matcher fn, returns the match or times out
54
- // pattern is regex or a function that returns a match
55
- // if bundle is set to true, it returns all matches after the timeout ends rather than resolving (can't be used with delay 0)
56
- // exec is a function run after adding the watcher
57
- // debounce (used with bundle) waits extra time after each match before timing out
58
- // afterMatchDelay (used with debounce) indicates to run a new timeout after the first match
59
- // last (used with bundle) is a function run on the match. when it returns true, the watcher resolves early
60
- // returns a promise, rejects after timeout ends
61
- addWatcher(pattern, { timeoutDelay = 50, bundle = false, debounce = false, afterMatchDelay = 0, last, exec, } = {}) {
62
- if (typeof pattern !== 'function' && !(pattern instanceof RegExp))
63
- return undefined;
64
- return new Promise((resolve, reject) => {
65
- // create the watcher
66
- const watcher = {
67
- pattern,
68
- bundle,
69
- debounce,
70
- timeoutDelay,
71
- afterMatchDelay,
72
- last,
73
- matches: [],
74
- };
75
- watcher.resolve = (...args) => {
76
- clearTimeout(watcher.timeout);
77
- resolve(args);
78
- };
79
- // remove helper
80
- watcher.remove = () => {
81
- const index = __classPrivateFieldGet(this, _LogWrangler_watchers, "f").indexOf(watcher);
82
- if (index > -1) {
83
- __classPrivateFieldGet(this, _LogWrangler_watchers, "f").splice(index, 1);
84
- }
85
- };
86
- // what the watcher dones when it completes
87
- watcher.done = () => {
88
- // remove the watcher if it exists
89
- watcher.remove();
90
- // if the bundle option is set to true, resolve on timeout end
91
- if (bundle) {
92
- resolve(watcher.matches);
93
- }
94
- else {
95
- logger_1.default.verbose('Watcher', pattern.toString(), 'timed out');
96
- // reject the promise
97
- reject('timed out');
98
- }
99
- };
100
- // if the delay is non 0, kill the promise after some time
101
- if (timeoutDelay !== 0) {
102
- watcher.timeout = setTimeout(watcher.done, timeoutDelay);
103
- }
104
- __classPrivateFieldGet(this, _LogWrangler_watchers, "f").push(watcher);
105
- exec && exec();
106
- });
6
+ // list of patterns and callbacks watching the brickadia logs in general
7
+ #matchers = [];
8
+ // list of patterns and promises waiting for specific console logs
9
+ #watchers = [];
10
+ constructor(omegga) {
11
+ this.exec = (cmd) => omegga.writeln(cmd);
12
+ this.getPlayer = (arg) => omegga.getPlayer(arg);
13
+ this.getVersion = () => omegga.version;
14
+ this.callback = this.handleLog.bind(this);
15
+ this.addMatcher = this.addMatcher.bind(this);
16
+ this.addWatcher = this.addWatcher.bind(this);
17
+ this.watchLogArray = this.watchLogArray.bind(this);
18
+ this.watchLogChunk = this.watchLogChunk.bind(this);
19
+ this.omegga = omegga;
20
+ }
21
+ // add a new matcher to listen in on the logs
22
+ // pattern is regex or a function that returns a match
23
+ // callback is a function that receives the result of the pattern
24
+ // returns a deregister function
25
+ addMatcher(pattern, callback) {
26
+ if (typeof pattern !== "function" && !(pattern instanceof RegExp) || typeof callback !== "function")
27
+ return void 0;
28
+ const matcher = { pattern, callback };
29
+ this.#matchers.push(matcher);
30
+ return () => {
31
+ const index = this.#matchers.indexOf(matcher);
32
+ if (index > -1) this.#matchers.splice(index, 0);
33
+ };
34
+ }
35
+ // wait for stdout to match this regex or matcher fn, returns the match or times out
36
+ // pattern is regex or a function that returns a match
37
+ // if bundle is set to true, it returns all matches after the timeout ends rather than resolving (can't be used with delay 0)
38
+ // exec is a function run after adding the watcher
39
+ // debounce (used with bundle) waits extra time after each match before timing out
40
+ // afterMatchDelay (used with debounce) indicates to run a new timeout after the first match
41
+ // last (used with bundle) is a function run on the match. when it returns true, the watcher resolves early
42
+ // returns a promise, rejects after timeout ends
43
+ addWatcher(pattern, {
44
+ timeoutDelay = 50,
45
+ bundle = false,
46
+ debounce = false,
47
+ afterMatchDelay = 0,
48
+ last,
49
+ exec
50
+ } = {}) {
51
+ if (typeof pattern !== "function" && !(pattern instanceof RegExp))
52
+ return void 0;
53
+ return new Promise((resolve, reject) => {
54
+ const watcher = {
55
+ pattern,
56
+ bundle,
57
+ debounce,
58
+ timeoutDelay,
59
+ afterMatchDelay,
60
+ last,
61
+ matches: []
62
+ };
63
+ watcher.resolve = (...args) => {
64
+ clearTimeout(watcher.timeout);
65
+ resolve(args);
66
+ };
67
+ watcher.remove = () => {
68
+ const index = this.#watchers.indexOf(watcher);
69
+ if (index > -1) {
70
+ this.#watchers.splice(index, 1);
71
+ }
72
+ };
73
+ watcher.done = () => {
74
+ watcher.remove();
75
+ if (bundle) {
76
+ resolve(watcher.matches);
77
+ } else {
78
+ logger.default.verbose("Watcher", pattern.toString(), "timed out");
79
+ reject("timed out");
80
+ }
81
+ };
82
+ if (timeoutDelay !== 0) {
83
+ watcher.timeout = setTimeout(watcher.done, timeoutDelay);
84
+ }
85
+ this.#watchers.push(watcher);
86
+ exec && exec();
87
+ });
88
+ }
89
+ // match a group of console logs that have the same counter (ran on the same thread)
90
+ // first is a function or 'index' for the index capture group that determines if this is match is the first log
91
+ // last is a function that determines if this match is the last log (and can terminate early)
92
+ // aftermatch delay is borrowed from addWatcher
93
+ watchLogChunk(cmd, pattern, {
94
+ first,
95
+ last,
96
+ afterMatchDelay = 10,
97
+ timeoutDelay = 100
98
+ } = {}) {
99
+ const logLineRegExp = /\[(?<date>\d{4}\.\d\d.\d\d-\d\d.\d\d.\d\d:\d{3})\]\[\s*(?<counter>\d+)\](?<rest>.*)$/;
100
+ let currentCounter = -1;
101
+ return this.addWatcher(
102
+ (line, _match) => {
103
+ const logLineMatch = line.match(logLineRegExp);
104
+ if (!logLineMatch) return;
105
+ const {
106
+ groups: { counter, rest }
107
+ } = logLineMatch;
108
+ const match = pattern instanceof RegExp ? rest.match(pattern) : pattern(rest, rest.match(GENERIC_LINE_REGEX));
109
+ if (!match && currentCounter !== -1) {
110
+ return "[OMEGGA_WATCHER_DONE]";
111
+ }
112
+ if (!match) return;
113
+ let isFirst = false;
114
+ if (first) {
115
+ if (typeof first === "function") isFirst = first(match);
116
+ else if (first === "index" && typeof match === "object" && "groups" in match)
117
+ isFirst = match.groups.index === "0";
118
+ } else {
119
+ isFirst = true;
120
+ }
121
+ if (currentCounter === -1 && isFirst) {
122
+ currentCounter = counter;
123
+ }
124
+ if (currentCounter === -1 && !isFirst) {
125
+ return;
126
+ }
127
+ if (counter !== currentCounter) {
128
+ if (Number(counter) - 1 + "" === currentCounter) {
129
+ currentCounter = counter;
130
+ } else {
131
+ return "[OMEGGA_WATCHER_DONE]";
132
+ }
133
+ }
134
+ return match;
135
+ },
136
+ {
137
+ last,
138
+ exec: () => this.exec(cmd),
139
+ bundle: true,
140
+ debounce: true,
141
+ timeoutDelay,
142
+ afterMatchDelay
143
+ }
144
+ );
145
+ }
146
+ // get a chunked array from the log
147
+ // patterns are actually regex and must have capture groups
148
+ // the itemPattern must have an (?<index>) capture group
149
+ // the return is in the format of:
150
+ /*
151
+ [{
152
+ item: (itemPattern group),
153
+ members: [
154
+ ...memberPattern groups,
155
+ ],
156
+ }, ...]
157
+ */
158
+ async watchLogArray(cmd, itemPattern, memberPattern) {
159
+ const results = await this.watchLogChunk(
160
+ cmd,
161
+ (line) => {
162
+ const itemMatch = line.match(itemPattern);
163
+ if (itemMatch) return ["item", itemMatch];
164
+ const memberMatch = line.match(memberPattern);
165
+ if (memberMatch) return ["member", memberMatch];
166
+ },
167
+ { first: (arr) => arr[0] === "item" && arr[1].groups.index === "0" }
168
+ );
169
+ const array = [];
170
+ for (const [type, { groups }] of results) {
171
+ if (type === "item") {
172
+ array.push({ item: groups, members: [] });
173
+ } else if (type === "member" && array.length > 0) {
174
+ array[array.length - 1].members.push(groups);
175
+ }
107
176
  }
108
- // match a group of console logs that have the same counter (ran on the same thread)
109
- // first is a function or 'index' for the index capture group that determines if this is match is the first log
110
- // last is a function that determines if this match is the last log (and can terminate early)
111
- // aftermatch delay is borrowed from addWatcher
112
- watchLogChunk(cmd, pattern, { first, last, afterMatchDelay = 10, timeoutDelay = 100, } = {}) {
113
- // we're focused on the counter part of this, the rest will be passed to the pattern matcher
114
- const logLineRegExp = /\[(?<date>\d{4}\.\d\d.\d\d-\d\d.\d\d.\d\d:\d{3})\]\[\s*(?<counter>\d+)\](?<rest>.*)$/;
115
- // keep track of the current log line
116
- let currentCounter = -1;
117
- // create the
118
- return this.addWatcher((line, _match) => {
119
- const logLineMatch = line.match(logLineRegExp);
120
- if (!logLineMatch)
121
- return;
122
- // get the counter and rest of line from the log line match
123
- const { groups: { counter, rest }, } = logLineMatch;
124
- // run the regular pattern matcher
125
- const match = pattern instanceof RegExp
126
- ? rest.match(pattern)
127
- : pattern(rest, rest.match(GENERIC_LINE_REGEX));
128
- // end the watcher early if there is no match and the match has started (log chunks are uninterrupted)
129
- // this usually means that two commands were run so quickly that the output occured on the same counter
130
- if (!match && currentCounter !== -1) {
131
- return '[OMEGGA_WATCHER_DONE]';
132
- }
133
- // ignore things that don't match
134
- if (!match)
135
- return;
136
- // determine if this is the first log in the chunk
137
- let isFirst = false;
138
- // if there is a first parameter
139
- if (first) {
140
- // if it's a function, use that function to match
141
- if (typeof first === 'function')
142
- isFirst = first(match);
143
- // if it's 'index', use the index capture group
144
- else if (first === 'index' &&
145
- typeof match === 'object' &&
146
- 'groups' in match)
147
- isFirst = match.groups.index === '0';
148
- }
149
- else {
150
- // otherwise, it doesn't matter
151
- isFirst = true;
152
- }
153
- // assign counter if it's not set and it's the first, or no first function is set
154
- if (currentCounter === -1 && isFirst) {
155
- currentCounter = counter;
156
- }
157
- if (currentCounter === -1 && !isFirst) {
158
- return;
159
- }
160
- // prematurely terminate the match if another log is found
161
- if (counter !== currentCounter) {
162
- // long running commands
163
- if (Number(counter) - 1 + '' === currentCounter) {
164
- currentCounter = counter;
165
- }
166
- else {
167
- return '[OMEGGA_WATCHER_DONE]';
168
- }
177
+ return array;
178
+ }
179
+ // check all the matchers against this line
180
+ handleLog(line) {
181
+ const logMatch = line.match(GENERIC_LINE_REGEX);
182
+ const patternMatchers = [
183
+ {
184
+ array: this.#matchers,
185
+ onMatch(match, matcher) {
186
+ matcher.callback?.(match);
187
+ }
188
+ },
189
+ {
190
+ array: this.#watchers,
191
+ onMatch(match, watcher) {
192
+ if (watcher.bundle) {
193
+ if (match === "[OMEGGA_WATCHER_DONE]") {
194
+ clearTimeout(watcher.timeout);
195
+ watcher.done();
196
+ return;
169
197
  }
170
- // add the match to the bundle
171
- return match;
172
- }, {
173
- last,
174
- exec: () => this.exec(cmd),
175
- bundle: true,
176
- debounce: true,
177
- timeoutDelay,
178
- afterMatchDelay,
179
- });
180
- }
181
- // get a chunked array from the log
182
- // patterns are actually regex and must have capture groups
183
- // the itemPattern must have an (?<index>) capture group
184
- // the return is in the format of:
185
- /*
186
- [{
187
- item: (itemPattern group),
188
- members: [
189
- ...memberPattern groups,
190
- ],
191
- }, ...]
192
- */
193
- async watchLogArray(cmd, itemPattern, memberPattern) {
194
- const results = (await this.watchLogChunk(cmd, (line) => {
195
- // match on items
196
- const itemMatch = line.match(itemPattern);
197
- if (itemMatch)
198
- return ['item', itemMatch];
199
- // match on members
200
- const memberMatch = line.match(memberPattern);
201
- if (memberMatch)
202
- return ['member', memberMatch];
203
- }, { first: arr => arr[0] === 'item' && arr[1].groups.index === '0' }));
204
- const array = [];
205
- // insert the results into the array
206
- for (const [type, { groups }] of results) {
207
- // insert an item into the array
208
- if (type === 'item') {
209
- array.push({ item: groups, members: [] });
210
- // insert a member into an item
198
+ watcher.matches = [...watcher.matches, match];
199
+ if (watcher?.last?.(match)) {
200
+ clearTimeout(watcher.timeout);
201
+ watcher.done();
202
+ return;
211
203
  }
212
- else if (type === 'member' && array.length > 0) {
213
- array[array.length - 1].members.push(groups);
204
+ if (watcher.debounce) {
205
+ clearTimeout(watcher.timeout);
206
+ watcher.timeout = setTimeout(
207
+ watcher.done,
208
+ watcher.afterMatchDelay || watcher.timeoutDelay
209
+ );
214
210
  }
211
+ } else {
212
+ watcher.resolve(match);
213
+ watcher.remove();
214
+ }
215
215
  }
216
- return array;
217
- }
218
- // check all the matchers against this line
219
- handleLog(line) {
220
- // generic match the log
221
- const logMatch = line.match(GENERIC_LINE_REGEX);
222
- // pattern matcher handlers
223
- const patternMatchers = [
224
- {
225
- array: __classPrivateFieldGet(this, _LogWrangler_matchers, "f"),
226
- onMatch(match, matcher) {
227
- var _a;
228
- (_a = matcher.callback) === null || _a === void 0 ? void 0 : _a.call(matcher, match);
229
- },
230
- },
231
- {
232
- array: __classPrivateFieldGet(this, _LogWrangler_watchers, "f"),
233
- onMatch(match, watcher) {
234
- var _a;
235
- // if the watcher is in bundle mode, add the match to its matches
236
- if (watcher.bundle) {
237
- // allow the watcher to terminate early
238
- if (match === '[OMEGGA_WATCHER_DONE]') {
239
- clearTimeout(watcher.timeout);
240
- watcher.done();
241
- return;
242
- }
243
- watcher.matches = [...watcher.matches, match];
244
- // check if this is the last line and terminate early
245
- if ((_a = watcher === null || watcher === void 0 ? void 0 : watcher.last) === null || _a === void 0 ? void 0 : _a.call(watcher, match)) {
246
- clearTimeout(watcher.timeout);
247
- watcher.done();
248
- return;
249
- }
250
- // if the watcher is debounced, reset the timer
251
- if (watcher.debounce) {
252
- clearTimeout(watcher.timeout);
253
- watcher.timeout = setTimeout(watcher.done, watcher.afterMatchDelay || watcher.timeoutDelay);
254
- }
255
- // otherwise resolve with the result and remove the watcher from the list
256
- }
257
- else {
258
- watcher.resolve(match);
259
- watcher.remove();
260
- }
261
- },
262
- },
263
- ];
264
- // loop through matchers and run callbacks if they match
265
- for (const { array, onMatch } of patternMatchers) {
266
- // iterate in reverse because removing indices will not skip over any elements
267
- for (let i = array.length - 1; i >= 0; i--) {
268
- const matcher = array[i];
269
- try {
270
- // run the match on a pattern or test with a function
271
- const match = matcher.pattern instanceof RegExp
272
- ? line.match(matcher.pattern)
273
- : matcher.pattern(line, logMatch);
274
- // if there's match, handle it for this type of matcher
275
- if (match)
276
- onMatch(match, matcher);
277
- }
278
- catch (e) {
279
- logger_1.default.error('error in matcher', matcher.pattern, e);
280
- }
281
- }
216
+ }
217
+ ];
218
+ for (const { array, onMatch } of patternMatchers) {
219
+ for (let i = array.length - 1; i >= 0; i--) {
220
+ const matcher = array[i];
221
+ try {
222
+ const match = matcher.pattern instanceof RegExp ? line.match(matcher.pattern) : matcher.pattern(line, logMatch);
223
+ if (match)
224
+ onMatch(
225
+ match,
226
+ matcher
227
+ );
228
+ } catch (e) {
229
+ logger.default.error("error in matcher", matcher.pattern, e);
282
230
  }
231
+ }
283
232
  }
233
+ }
284
234
  }
285
- _LogWrangler_matchers = new WeakMap(), _LogWrangler_watchers = new WeakMap();
286
235
  exports.default = LogWrangler;
287
- //# sourceMappingURL=logWrangler.js.map
236
+ //# sourceMappingURL=logWrangler.js.map