Commit Graph

33 Commits

Author SHA1 Message Date
Annika
0bc78dddf5 TypeScript 5! 2023-04-09 13:02:19 -07:00
Mia
8bdebea6e4 Fix eslint errors 2022-11-17 16:18:39 -06:00
Annika
6e91e22740 Improve typing and fix build 2022-02-28 19:49:08 -08:00
Annika
34cab27a74
Properly type Promises (#7712) 2020-11-19 23:19:42 -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
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
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
Guangcong Luo
1e5b5ab465 Update Streams API with pushEnd/writeEnd
Previously, ending a read stream was `stream.push(null)`, and ending a
write stream was `stream.end()`. This was often confusing, and so now,
these are consistently `stream.pushEnd()` and `stream.writeEnd()`.

This refactor already found a bug in which `stream.end()` was used
where `stream.push(null)` should have been.

Also in this refactor: By default, `pushError` ends the stream. You can
pass `true` as the second parameter if the error is recoverable (the
stream shouldn't end).
2020-06-10 16:07:24 -07:00
Mia
cf42c6269a
Add a library for making HTTP/S requests (#6744) 2020-06-04 11:53:58 -07:00
Guangcong Luo
58b958c6fe Improve TS 3.9 property checks
These were previously fixed in 6e2b475dac, but I prefer an approach
that makes sure e.g. `pipeTo = undefined` doesn't break this check.
2020-06-04 10:23:04 -07:00
Kirk Scheibelhut
6e2b475dac Change property checks to TypeScript 3.9 2020-05-12 20:11:56 -07:00
Guangcong Luo
776ccf9796
Refactor Sockets to ProcessManager+TypeScript (#6584) 2020-04-17 04:05:45 -07:00
Guangcong Luo
125fe31d06 Improve eslintrc
Fixed some more code style, allowing these rules to be enabled:

- `comma-dangle`
- `function-paren-newline`
- `member-delimiter-style`
- `no-eval`
- `no-fallthrough`
- `no-misused-promises`
- `no-unused-vars`
- `operator-linebreak`
2020-03-06 22:35:55 -08:00
Guangcong Luo
2f0e83c14b Categorize eslintrc rules
eslintrc rules are now sorted into categories, in theory making them
easier to maintain.
2020-03-06 22:35:45 -08:00
Waleed Hassan
8aa4f053bb
Use optional chaining and linter improvements (#6422)
This is mostly just a follow up to #6342.

`prefer-optional-chaining` was turned on and fixed in every location it
complained in. The transformed function [0] looks expensive from a
glance but from skimming through the replaced sites it doesn't appear
to be ran in any important place, so it should be OK.

The linter improvements are:
- Increase linter performance
	- Make `full-lint` and `lint` write to different caches so we
	  avoid overwriting their caches since they're different configs
	- Change husky's hook to `npm run lint` so as to write to the
	  same cache
	- Remove `@typescript-eslint/eslint-plugin-tslint` which is
	  essentially a wrapper to TSLint because the rules aren't worth
	  running another linter
- Convert `.eslintrc.json` and `.eslintrc-syntax.json` to two spaces
  rather than four tabs to respect PS' `.editorconfig`
- Rename `fulllint` to `full-lint` to ease spelling it

[0] - https://pastie.io/mmtxpf.js (prettified)
2020-03-06 11:44:32 -08:00
Guangcong Luo
b21c9047e2
Migrate to typescript-eslint (#6342) 2020-03-05 08:33:06 -08:00
Kirk Scheibelhut
dfd8fc504a Wrap long line in lib/streams.ts 2019-04-10 14:19:12 -07:00
Kirk Scheibelhut
334ca88b50 Update dependencies (#5430) 2019-04-10 18:46:37 +08:00
Kirk Scheibelhut
15fe4d2ff1 Stop closing STDOUT/STDERR in lib/streams.ts (#5419)
Fixes #5403 for Node versions prior to v10.12.0.
2019-04-07 15:34:06 +08:00
Guangcong Luo
6d563f555a Fix stream ending 2019-03-24 02:31:39 +09:00
Guangcong Luo
78c0433436 Fix ./pokemon-showdown simulate-battle
Fixes #5338
2019-03-23 17:39:11 +09:00
Kirk Scheibelhut
2b1c278c42 Fix 'floating' promises and enable lint errors going forward (#5297) 2019-03-22 02:21:17 +09:00
Guangcong Luo
efa0af0ef1 Propagate errors through streams 2019-03-17 07:48:02 +09:00
Guangcong Luo
9073a5a8bf Improve Streams typing
When I originally wrote the Streams library, TypeScript-in-JS didn't
support generics. But now the library can have significantly nicer
typing, and so it now does.
2019-03-16 17:12:21 +09:00
Kirk Scheibelhut
0e1708bf9f Enable prefer-const and max 120 character lines for .ts files (#5292) 2019-03-16 07:14:04 +09:00
Kirk Scheibelhut
6e122d5d74 Refactor lib/ to be native Typescript (#5217) 2019-03-02 11:12:24 -06:00