-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
191 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { type Part } from 'meros'; | ||
import { meros } from 'meros/browser'; | ||
|
||
declare function assert<T>(thing: T): void; | ||
|
||
declare const response: Response; | ||
|
||
type Result = { name: string }; | ||
type ThePart<T> = Part<T, string>; | ||
type Unwrapped<T> = Promise<Response | AsyncGenerator<ThePart<T>>>; | ||
|
||
assert<Unwrapped<Result>>(meros<Result>(response)); | ||
|
||
{ | ||
const result = await meros<Result>(response); | ||
if (!(result instanceof Response)) { | ||
for await (let item of result) { | ||
assert<ThePart<Result>>(item); | ||
|
||
if (item.json) assert<Result>(item.body); | ||
else assert<string>(item.body); | ||
|
||
// @ts-expect-error | ||
assert<{ foo: string }>(item.body); | ||
|
||
assert<boolean>(item.json); | ||
assert<Record<string, string>>(item.headers); | ||
} | ||
} | ||
} | ||
|
||
{ | ||
const result = await meros<Result>(response, { multiple: true }); | ||
if (!(result instanceof Response)) { | ||
for await (let parts of result) { | ||
assert<readonly ThePart<Result>[]>(parts); | ||
|
||
for (let item of parts) { | ||
assert<ThePart<Result>>(item); | ||
|
||
if (item.json) assert<Result>(item.body); | ||
else assert<string>(item.body); | ||
|
||
// @ts-expect-error | ||
assert<{ foo: string }>(item.body); | ||
|
||
assert<boolean>(item.json); | ||
assert<Record<string, string>>(item.headers); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { IncomingMessage } from 'http'; | ||
import type { Part } from 'meros'; | ||
import { meros } from 'meros'; | ||
|
||
declare function assert<T>(thing: T): void; | ||
|
||
type Wrapped<T, B, F> = Promise<B | AsyncGenerator<Part<T, F>>>; | ||
|
||
type Result = { name: string }; | ||
|
||
declare const responseNode: IncomingMessage; | ||
assert<Wrapped<Result, IncomingMessage, Buffer>>(meros<Result>(responseNode)); | ||
|
||
{ | ||
type P = Part<Result, Buffer>; | ||
const result = await meros<Result>(responseNode); | ||
if (!(result instanceof IncomingMessage)) { | ||
for await (let item of result) { | ||
assert<P>(item); | ||
|
||
if (item.json) assert<Result>(item.body); | ||
else assert<Buffer>(item.body); | ||
|
||
// @ts-expect-error | ||
assert<{ foo: string }>(item.body); | ||
|
||
assert<boolean>(item.json); | ||
assert<Record<string, string>>(item.headers); | ||
} | ||
} | ||
} | ||
|
||
declare const responseBrowser: Response; | ||
assert<Wrapped<Result, Response, string>>(meros<Result>(responseBrowser)); | ||
|
||
{ | ||
type P = Part<Result, string>; | ||
const result = await meros<Result>(responseBrowser); | ||
if (!(result instanceof Response)) { | ||
for await (let item of result) { | ||
assert<P>(item); | ||
|
||
if (item.json) assert<Result>(item.body); | ||
else assert<string>(item.body); | ||
|
||
// @ts-expect-error | ||
assert<{ foo: string }>(item.body); | ||
|
||
assert<boolean>(item.json); | ||
assert<Record<string, string>>(item.headers); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { IncomingMessage } from 'http'; | ||
import type { Part } from 'meros'; | ||
import { meros } from 'meros/node'; | ||
|
||
declare function assert<T>(thing: T): void; | ||
|
||
declare const response: IncomingMessage; | ||
|
||
type Result = { name: string }; | ||
type ThePart<T> = Part<T, Buffer>; | ||
type Unwrapped<T> = Promise<IncomingMessage | AsyncGenerator<ThePart<T>>>; | ||
|
||
assert<Unwrapped<Result>>(meros<Result>(response)); | ||
|
||
{ | ||
const result = await meros<Result>(response); | ||
if (!(result instanceof IncomingMessage)) { | ||
for await (let item of result) { | ||
assert<ThePart<Result>>(item); | ||
|
||
if (item.json) assert<Result>(item.body); | ||
else assert<Buffer>(item.body); | ||
|
||
// @ts-expect-error | ||
assert<{ foo: string }>(item.body); | ||
|
||
assert<boolean>(item.json); | ||
assert<Record<string, string>>(item.headers); | ||
} | ||
} | ||
} | ||
|
||
{ | ||
const result = await meros<Result>(response, { multiple: true }); | ||
if (!(result instanceof IncomingMessage)) { | ||
for await (let parts of result) { | ||
assert<readonly ThePart<Result>[]>(parts); | ||
|
||
for (let item of parts) { | ||
assert<ThePart<Result>>(item); | ||
|
||
if (item.json) assert<Result>(item.body); | ||
else assert<Buffer>(item.body); | ||
|
||
// @ts-expect-error | ||
assert<{ foo: string }>(item.body); | ||
|
||
assert<boolean>(item.json); | ||
assert<Record<string, string>>(item.headers); | ||
} | ||
} | ||
} | ||
} |