Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/connect/src/protocol-connect/end-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const endStreamFlag = 0b00000010;
*/
export interface EndStreamResponse {
metadata: Headers;
error?: ConnectError;
error?: ConnectError | undefined;
}

/**
Expand Down
32 changes: 26 additions & 6 deletions packages/connect/src/protocol/async-iterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,29 @@ interface Abortable {

type AbortState = "rethrown" | "completed" | "caught";

function assertHasThrow(
t: unknown,
message: string
): asserts t is {
throw: CallableFunction;
} {
if (
typeof t === "object" &&
t !== null &&
"throw" in t &&
typeof t.throw === "function"
) {
return;
}
throw new Error(message);
}

const hasReturn = (t: unknown): t is { return: CallableFunction } =>
typeof t === "object" &&
t !== null &&
"return" in t &&
typeof t.return === "function";

/**
* Wrap the given iterable and return an iterable with an abort() method.
*
Expand Down Expand Up @@ -1101,11 +1124,8 @@ type AbortState = "rethrown" | "completed" | "caught";
export function makeIterableAbortable<T>(
iterable: AsyncIterable<T>
): AsyncIterable<T> & Abortable {
const innerCandidate = iterable[Symbol.asyncIterator]();
if (innerCandidate.throw === undefined) {
throw new Error("AsyncIterable does not implement throw");
}
const inner = innerCandidate as Required<AsyncIterator<T>>;
const inner = iterable[Symbol.asyncIterator]();
assertHasThrow(inner, "AsyncIterable does not implement throw");
let aborted: { reason: unknown; state: Promise<AbortState> } | undefined;
let resultPromise: Promise<IteratorResult<T>> | undefined;
let it: AsyncIterator<T> = {
Expand All @@ -1119,7 +1139,7 @@ export function makeIterableAbortable<T>(
return inner.throw(e);
},
};
if (innerCandidate.return === undefined) {
if (hasReturn(inner)) {
it = {
...it,
return(value?: unknown): Promise<IteratorResult<T>> {
Expand Down
2 changes: 1 addition & 1 deletion packages/connect/src/protocol/compression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function compressionNegotiate(
): {
request: Compression | null;
response: Compression | null;
error?: ConnectError;
error?: ConnectError | undefined;
} {
let request = null;
let response = null;
Expand Down
4 changes: 2 additions & 2 deletions packages/connect/src/protocol/universal-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ export interface UniversalHandlerOptions {
/**
* Options for the JSON format.
*/
jsonOptions?: Partial<JsonReadOptions & JsonWriteOptions>;
jsonOptions?: Partial<JsonReadOptions & JsonWriteOptions> | undefined;

/**
* Options for the binary wire format.
*/
binaryOptions?: Partial<BinaryReadOptions & BinaryWriteOptions>;
binaryOptions?: Partial<BinaryReadOptions & BinaryWriteOptions> | undefined;

maxDeadlineDurationMs: number; // TODO TCN-785
shutdownSignal: AbortSignal; // TODO TCN-919
Expand Down
1 change: 1 addition & 0 deletions packages/example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"lib": ["ESNext", "DOM"],
"moduleResolution": "Node",
"strict": true,
"exactOptionalPropertyTypes": true,
"sourceMap": true,
"resolveJsonModule": true,
"isolatedModules": true,
Expand Down
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"exactOptionalPropertyTypes": true,
"noImplicitThis": true,
"useUnknownInCatchVariables": true,
"noUnusedLocals": true,
Expand Down