Commit Graph

231 Commits

Author SHA1 Message Date
GregLyons
c589fb5a5a
Improved typing for utils.ts, and for iterating over base stats (#8919) 2022-10-16 18:08:11 -07:00
PartMan
161b48daff
Scavengers: Add Speedrun Twist (#8852) 2022-08-06 17:48:46 -07:00
Mia
0860a6e036 Remove accidental debug print 2022-07-28 03:10:12 -05:00
Mia
a0963b8f32 Postgres: Ensure table version is always inserted 2022-07-28 00:12:23 -05:00
Mia
922a7bf8a9 Postgres: Fix bugs in migration API 2022-07-27 23:57:31 -05:00
Mia
67fcc14bf4
Rooms: Ensure battles save all data correctly (#8851)
* Rooms: Ensure battles save all data correctly

* Standardize migration code for future use
2022-07-27 21:08:19 -07:00
Mia
ec4cb6a6fa
Support persisting battles in a Postgres database (#8442) 2022-07-22 18:07:10 -07:00
Annika
bc6e0dcdb7 REPL: Fix heapdump path
The `path` identifier referred to the module `path`, not the path that the heapdump should be written to
2022-03-02 19:48:22 -08:00
Annika
6e91e22740 Improve typing and fix build 2022-02-28 19:49:08 -08:00
Mia
1c8381113f
SQL: Expose an sql-template-strings API
Necessary for consumers of the DatabaseTable API wishing to use the delete etc functions. And this solution is much nicer than `tableinstance.SQL\`\``.
2022-02-01 12:36:31 -06:00
Mia
29cef961c6
SQL: Add an abstraction for typed queries (#8565) 2022-02-01 10:02:53 -08:00
Mia
fa8f7a3e50
SQL: Propagate errors to the parent process (#8613) 2022-01-05 17:56:52 -08:00
Mia
971a02061a
Fix build
I don't know why this counts as a variable.
2021-11-27 22:43:36 -06:00
Mia
5649bc5f30 Crashlogger: Don't crash if there's no Config global 2021-11-27 14:34:20 -06:00
Guangcong Luo
57554dc283 Stop using fs.exists
`fs.exists` should in practice be replaced with try-catch (since the
latter isn't susceptible to race conditions).
2021-10-09 15:53:30 -04:00
Mia
a4e81e29d3 Crashlogger: Support passing nodemailer configuration
This is useful for the new loginserver.
2021-10-03 19:58:13 -05:00
Mia
e08e1a9cf0 Repl: Create file directory if it doesn't exist 2021-09-13 20:26:11 -05:00
Mia
7811795344
Handle new TypeScript version (#8449)
Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>
2021-08-30 20:11:44 -07:00
Mia
d9b342745c Process-Manager: Allow undefined responses in QueryProcessManager 2021-08-21 13:20:06 -05:00
Mia
b70bf3fa17
ProcessManager: Crashlog bad JSON responses (#8438) 2021-08-20 18:18:34 -07:00
Mia
8cf1035ee2
SQL: Automatically prepare statements unless told otherwise (#8439) 2021-08-18 12:51:39 -07:00
Mia
0a2ed42d13 SQL: Support turning SQL.Statements to JSON 2021-08-15 15:17:45 -05:00
Annika
a7ddaa1b63 SQL library: Support loading extensions at will 2021-08-14 20:35:08 -07:00
Annika
f13609e721
SQL library: Improve typing of #run() 2021-08-14 18:58:13 -07:00
Mia
ca1400ddc3 Fix build 2021-08-14 20:24:23 -05:00
Mia
d63e647a95 Fix typo 2021-08-14 19:58:24 -05:00
Mia
c8991c3d9d SQL: Overhaul database/statement not found errors 2021-08-14 19:58:02 -05:00
Mia
77861ceae6
SQL: Use a QueryProcessManager subclass (#8422) 2021-08-14 17:45:51 -07:00
Mia
a43d3f66a9 SQL: Properly support named parameters 2021-08-13 21:08:43 -05:00
Annika
33ad1a0a50 Move Modlog.formatArray to Utils 2021-08-12 16:38:14 -07:00
Annika
e9990080d3 FS: Fix build 2021-08-04 21:12:37 -07:00
Annika
bcbe100c41
Modlog: Use SQLite for searches (#8004) 2021-07-23 13:47:49 -07:00
Mia
4f50a1143f Fix build 2021-07-21 16:26:21 -05:00
Mia
9ed2c0036f
Add a command for evaluating SQLite (#8407) 2021-07-21 13:05:02 -07:00
Annika
9e11aab86d SQL library: Fix bugs and add features for modlog 2021-07-20 21:31:02 -07:00
Mia
330038ca0f SQL: Expose normal statement table to transactions 2021-07-20 20:47:40 -05:00
Mia
719f0818d0 SQL: Expose string-keyed statement table to transactions 2021-07-20 20:45:27 -05:00
Mia
044dc3e54f SQL library: Improve API 2021-07-20 20:25:34 -05:00
Mia
ace114ff36 Fix build 2021-07-20 00:03:12 -05:00
Mia
adbe7b9947 SQL library: Improve error handling 2021-07-19 23:56:58 -05:00
Mia
2c1b7d7828
Add a library for running SQLite databases in threads (#7350) 2021-07-19 21:02:03 -05:00
Mia
b175d8b000 Friends: Use /migrations/friends for versioning 2021-07-19 20:49:47 -05:00
Mia
20c795f8f4
Friends: Move caching to User#friends (#8404) 2021-07-16 20:33:07 -07:00
Mia
e5fbd64427
Support adding friends (#7333) 2021-07-16 12:56:34 -07:00
Annika
6ed55b6d1f
IPTools: Add sanity checks (#8331) 2021-07-09 19:59:45 -07:00
Annika
c134195915
Use ts-node instead of Sucrase (#8369) 2021-07-09 19:59:22 -07:00
Guangcong Luo
f47e38c5ad Support building TS declarations
`./build decl` now builds TS declarations for everything exported by
`sim/`. Unfortunately, the built TS declarations still refer to global
types, so some things still have `any` type, but it's much better than
nothing.
2021-06-09 17:51:49 -05:00
Mia
48ce5d720f FS: Don't crash if config doesn't exist
QOL. Also, if we _do_ want to export this as a module, we need this to not crash if Config doesn't exist.
2021-05-30 12:21:24 -05:00
Mia
c7b8925d82
Repl: Make it easier to heapdump processes (#8333) 2021-05-25 16:00:00 -07:00
Guangcong Luo
4e213368dc Redesign Rock Paper Scissors
This new update will have it looking a lot nicer, and also fixes some
architectural issues with the old design.
2021-05-13 09:39:51 -04:00
Guangcong Luo
574bb28bbe
Implement Utils.Multiset (#8260)
If you grep the codebase for `|| 0) + 1` you get a lot of results,
all of which would be better implemented with a multiset.
2021-05-04 21:53:23 -07:00
Guangcong Luo
04243bc731 Fix crash in Utils.sortBy 2021-04-26 14:57:35 -04:00
Guangcong Luo
486f292904
Refactor everything to use Utils.sortBy (#8220)
A few uses of `array.sort()` have been left alone:

- sorting in `data/` because they aren't supposed to import anything

- `set-importer` because I still have no clue what that's for and what
  dependencies it is/isn't allowed to have

- `sort()` with no arguments used as a lexical sort (at which point
  `sortBy` offers no benefits)

All other cases have been replaced with `Utils.sortBy`, which should
be a massive increase in readability.

Sort orders should be much more readable now, without needing to puzzle
through sign issues. The order is always low-to-high, A-to-Z,
true-to-false.
2021-04-23 22:41:00 -07:00
Guangcong Luo
13189fdb02
Update Dex API (#8181)
This is the change that renames:

- `Dex.getMove` -> `Dex.moves.get`
- `Dex.getAbility` -> `Dex.abilities.get`
- `Dex.getItem` -> `Dex.items.get`
- `Dex.getSpecies` -> `Dex.species.get`
- `Dex.getEffect` -> `Dex.conditions.get`
- `Dex.getNature` -> `Dex.natures.get`
- `Dex.getType` -> `Dex.types.get`
- `Dex.getFormat` -> `Dex.formats.get`

In addition, some other APIs have been updated:

- `getByID` methods have also been added to every other table.
- `Dex.moves.all()` now gets an array of all moves
  - Plus equivalent methods for `abilities`, `items`, `species`, `formats`, `natures`, `types`
  - Note: there's no `Dex.conditions.all()`
- new API: `Dex.stats` for naming/iterating stats
- `Dex.getEffectByID` -> `Dex.conditions.getByID`
- `Dex.getType` -> `Dex.types.get`
- `Dex.data.Formats` -> `Dex.data.Rulesets`
- `Dex.formats` -> now an array `Dex.formats.all()`
- `Dex.getRuleTable` -> `Dex.formats.getRuleTable`
- `Dex.validateFormat` -> `Dex.formats.validate`

Team functions have been split off into a new `sim/teams` package:

- `Dex.packTeam` -> `Teams.pack`
- `Dex.fastUnpackTeam` -> `Teams.unpack`
- `Dex.generateTeam` -> `Teams.generate`
- `Dex.stringifyTeam` -> `Teams.export`

`Teams.export` has also been rewritten to better match how it works in client.

This implements #8178
2021-04-08 03:00:37 -07:00
Mia
07b1c01f75
Support hotpatching User/Room/ProcessManager protos (#8095) 2021-03-08 05:23:17 -08:00
Mia
736e38e4af
ProcessManager: Handle Monitor#slow in subprocesses (#7990) 2021-03-03 12:39:53 -08:00
Guangcong Luo
61ea2dd916 Implement Utils.escapeHTMLForceWrap
Combining escapeHTML and forceWrap allows us to use <wbr /> instead
of U+200B, fixing a copy/paste bug.
2021-02-15 06:09:58 -05:00
Guangcong Luo
d2ba0c7a9f Fix hotpatching 2021-02-02 13:15:09 -08:00
Mia
76c10841ea
Lib: Add an index file for all exports (#7972) 2021-01-31 18:00:19 -08:00
Guangcong Luo
a4d722ed65
PM: Support querying in a new process (#7968)
Better subprocess query system for #7937.

I mentioned in #7937 that it should be a regular `child_process`, but
Mia's not _wrong_ that PM has some useful features that make it more
convenient than `child_process`. This change allows a
`QueryProcessManager` to easily run a query in a new child process.
2021-01-30 12:11:48 -08:00
Guangcong Luo
67f6d3908e Improve ProcessManager typing
This removes the need for some more casting... although I'm starting
to worry if generics are too unreadable. I suppose anyone working on
library code is likely to prefer generics to casting, and it's safer,
anyway.
2021-01-30 11:53:34 -08:00
Guangcong Luo
f4abf52f61 Fix QueryProcessManager type signatures 2021-01-30 11:35:35 -08:00
Mia
184e867761
Hangman: Support saving hangman entries (#7630) 2021-01-28 11:24:46 -08:00
Mia
ca94dea20f
FS: Fix hotpatching and add more throttling (#7878)
- `writeUpdate` state is now stored in a global variable, so hotpatching doesn't crash it
- throttling now writes on the tail (so two throttled `writeUpdate` calls will write one update, not two)
- room settings, punishments, and helptickets are now throttled
2021-01-09 15:49:30 -08:00
Guangcong Luo
b5c25a84e2 Fix typo 2021-01-06 11:18:56 -08:00
Guangcong Luo
c44af3286d Implement Utils.forceWrap
I wrote a `forceWrap` method to support break-word wrapping in table
cells for scavengers, but apparently code blocks need it too, so I'm
moving it to Utils.

Fixes #7854
2020-12-30 17:41:41 -08:00
Mia
1b1d91df02
Utils: Visualize Maps/Sets in a cleaner fashion (#7830)
* Utils: Visualize Maps/Sets in a cleaner fashion

* OK

* Update lib/utils.ts

Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>

* Update lib/utils.ts

Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>

* Update lib/utils.ts

Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>

Co-authored-by: Guangcong Luo <guangcongluo@gmail.com>
2020-12-27 12:51:11 -08:00
Guangcong Luo
6e281dbe31 Move build-utils from lib to tools
The current idea is for `lib` to contain shared libraries useful to
many projects. `build-utils` is specific to this repo and so doesn't go
there.
2020-12-26 10:08:30 -08:00
Guangcong Luo
3cbf3f8a30 Fix build
Building from a fresh install currently fails since #7797

The problem is that `require('sucrase')` needs to be done _after_
sucrase is installed, which is a lot harder than it sounds.
2020-12-26 10:04:41 -08:00
Mia
f792cfe28e
Move FSPath#waitUntil to Utils (#7805) 2020-12-14 14:15:52 -08:00
Adam Tran
c7c5f4253b
Support generating sourceMaps for source debugging (#7797) 2020-12-13 19:42:19 -08:00
Mia
fca97b418c Fix build errors 2020-11-30 13:17:52 -06:00
Annika
34cab27a74
Properly type Promises (#7712) 2020-11-19 23:19:42 -08:00
Mia
89d127eafd
ProcessManager: Add a static execFile (#7566) 2020-11-02 11:35:07 -08:00
Guangcong Luo
c8dfed19db Better handle races when reading Streams 2020-11-01 22:08:59 +00:00
Guangcong Luo
8b68cdd736 Fix Streams bug
It turns out 001f98b4f2 was wrong.

When urkerab asked why it `peek` wasn't awaited:

e91c4c5260 (commitcomment-41364837)

The answer was because clearing the buffer after peeking needed to
happen synchronous: if the buffer is written to after peeking but
before the buffer is cleared, that write is lost forever.

This just goes to show, if you do something subtle enough to require
type assertions, you should probably add a comment about what's going
on.

Fixes #7605

This also removes `BattleStream#start()` which is completely useless
API complication. A better implementation would properly forward
crashes between streams (maybe `pipeTo` should do this) but as it
stands, it's not doing anything.
2020-11-01 02:06:24 +00:00
Guangcong Luo
a38f0597f8 Remove last vestiges of tslint 2020-10-27 22:49:00 +00:00
Guangcong Luo
9d87616176
Add more style linting rules (#7537)
* Lint arrow-body-style

* Lint prefer-object-spread

Object spread is faster _and_ more readable.

This also fixes a few unnecessary object clones.

* Enable no-parameter-properties

This isn't currently used, but this makes clear that it shouldn't be.

* Refactor more Promises to async/await

* Remove unnecessary code from getDataMoveHTML etc

* Lint prefer-string-starts-ends-with

* Stop using no-undef

According to the typescript-eslint FAQ, this is redundant with
TypeScript, and they're not wrong. This will save us from needing to
specify globals in two different places which will be nice.
2020-10-19 02:42:28 -07:00
Annika
9aa837b9df
ProcessManager: Support timing out queries (#7502) 2020-10-16 02:56:02 -07:00
Guangcong Luo
1c0c77ff6b
Update to TypeScript 4.0 (#7504) 2020-10-10 14:43:32 -07:00
Guangcong Luo
3d68248efa Update to latest eslint
We're skipping two major typescript-eslint versions, so there are a
bunch of changes here, including:

- it's catching a lot of things it didn't catch in the past, for
  reasons unclear to me

- no-unused-vars has to be explicitly disabled in global-types now

- a lot of `ts-ignore`s were never necessary and have been fixed

- Crashlogger can now handle being thrown things that aren't errors.
  This has never been a problem in the past, but to satisfy TypeScript
	we might as well not die in a fire on the off chance someone tries to
	`throw null` or something.
2020-09-29 15:28:08 -07:00
Guangcong Luo
d3ecb74121 Fix bug in ReadStream buffer expansion
This prevented the buffer from properly expanding as needed for long
reads.

This also fixes a bug when the buffer wasn't being used optimally.
2020-09-27 16:44:40 -07:00
Guangcong Luo
9fe45238f5
Introduce chunk readers for ReadStream (#7215)
This adds new functions `stream.byChunk(bytes)`, `stream.byLine()` etc
which parse a `ReadStream` into an `ObjectReadStream<string>` which
can then be consumed with for-await.

Fixes #7195
2020-09-27 08:55:59 -07:00
Guangcong Luo
8d79bf9725 Rename Dex.deepClone to Utils.deepClone
`this.dex.deepClone` still exists as an alias to `Utils.deepClone` for
use in `data/`. I'll need to spend more time figuring out the correct
solution there.
2020-08-21 04:24:34 -07:00
Guangcong Luo
18948c8c2c Refactor ObjectReadStreams to use for-await
Regular ReadStreams still can't; I now believe they shouldn't have a
"default" read method, and you should explicitly choose whether you
want to read "by chunks as they become available", "by chunks of a
specific line" or "by a delimiter".

So you would specifically use `stream.byLine()` or
`stream.byChunk([size])`, which would return an
`ObjectReadStream<string>`.

Inspired by #7195
2020-08-15 15:11:53 -07:00
Guangcong Luo
001f98b4f2 Fix some Streams weirdness
Pointed out by @urkerab in e91c4c5260

I'm confused it ever worked in the past.

I also added `Symbol.asyncIterator` to make `for await` work correctly.
I'm still very annoyed by `Symbol`. Especially since the spec saw no
reason not to name the other function `next`, but calling it
`asyncIterator` instead of `[Symbol.asyncIterator] was too much of a
risk??? Complete bullshit that does nothing but break backwards
compatibility.
2020-08-15 14:32:21 -07:00
Ben Davies
86c1aca097 Streams: fix ObjectReadStream _destroy method setting 2020-08-11 00:08:27 -03:00
Ben Davies
e91c4c5260 Streams: return buffers from ReadStream#readBuffer, not strings 2020-08-11 00:04:51 -03:00
Ben Davies
5cee3b401f Streams: fix _destroy method setting in ReadStream 2020-08-10 23:06:58 -03:00
Annika
b3771214d5
Fix modlog tests on Windows (#7187) 2020-08-10 09:37:08 -07:00
Mia
deeed6c789
Remove sim/ and data/'s globals (#7091) 2020-08-07 06:44:15 -07:00
Annika
f34ffa9e74
Refactor Modlog into one file (#7127) 2020-08-06 00:39:37 -07:00
Guangcong Luo
8eeec74ce0 Use TypeScript tuples for low splitFirst limits 2020-07-02 15:06:53 -04:00
Guangcong Luo
160efc9898 Fix crash after failed Net request 2020-07-02 11:25:34 -07:00
Guangcong Luo
f6d5e7f5c2 Stop showing REPL error in Windows 2020-07-01 16:37:36 -07:00
Guangcong Luo
db975b2b39
Don't automatically restart REPL server on crash
This leads to a spinlock that causes #6873
2020-06-25 02:28:23 -07:00
Guangcong Luo
9f0d6d03d3 Attempt to fix REPL crash in WSL2
For some reason, my last try failed. The error just wasn't getting
caught. This is an attempt to make it not listen to the `'close'` event
if the `listen` function throws, which might work? I'll reboot to test
in Windows when I have time.

Refs #6873
2020-06-19 22:53:31 -07:00
Guangcong Luo
dffd9dbff8 Fix stream destroying
`SubprocessStream` wasn't getting properly destroyed.
2020-06-18 21:47:03 -07:00
Guangcong Luo
39206a6959 Don't crash if FS doesn't support Unix sockets
Fixes #6873
2020-06-18 18:30:43 -07:00
Guangcong Luo
e0f97dcf6b Replace Chat.uncache* with Utils.clearRequireCache
This replaces the old approach with a new "clear everything except a
whitelist" approach, which should overall involve much less code and
lead to fewer bugs of the "the path changed for a module and I forgot
to update the uncache paths" variety.

I considered a lot of other approaches, but they seem to have more
flaws without any advantages in exchange for them. (We moved away
from `uncacheTree` because it only tracks the first require: there's
no way to get a full list of dependents for a module, only its first
dependent.)
2020-06-12 22:02:32 -07:00