Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

Updated types for 2022-04-27 #226

Merged
merged 1 commit into from
Apr 28, 2022
Merged
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
5 changes: 5 additions & 0 deletions .changeset/2022-04-27.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/workers-types": minor
---

Updated auto-generated types @ 2022-04-27
89 changes: 60 additions & 29 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ declare type BodyInitializer = BodyInit;
declare class ByteLengthQueuingStrategy {
constructor(init: QueuingStrategyInit);
readonly highWaterMark: number;
size(arg1?: any): number | undefined;
size(chunk?: any): number;
}

declare abstract class Cache {
Expand Down Expand Up @@ -194,7 +194,7 @@ interface Comment {
}

declare class CompressionStream extends TransformStream {
constructor(format: string);
constructor(format: "gzip" | "deflate");
}

interface Console {
Expand All @@ -214,7 +214,7 @@ interface ContentOptions {
declare class CountQueuingStrategy {
constructor(init: QueuingStrategyInit);
readonly highWaterMark: number;
size(arg1?: any): number | undefined;
size(chunk?: any): number;
}

declare abstract class Crypto {
Expand Down Expand Up @@ -323,7 +323,7 @@ declare class DOMException extends Error {
}

declare class DecompressionStream extends TransformStream {
constructor(format: string);
constructor(format: "gzip" | "deflate");
}

declare class DigestStream extends WritableStream {
Expand All @@ -345,6 +345,10 @@ interface DurableObject {
fetch(request: Request): Promise<Response>;
}

interface DurableObjectGetAlarmOptions {
allowConcurrency?: boolean;
}

interface DurableObjectGetOptions {
allowConcurrency?: boolean;
noCache?: boolean;
Expand Down Expand Up @@ -385,6 +389,11 @@ interface DurableObjectPutOptions {
noCache?: boolean;
}

interface DurableObjectSetAlarmOptions {
allowConcurrency?: boolean;
allowUnconfirmed?: boolean;
}

interface DurableObjectState {
waitUntil(promise: Promise<any>): void;
readonly id: DurableObjectId | string;
Expand Down Expand Up @@ -419,17 +428,12 @@ interface DurableObjectStorage {
transaction<T>(
closure: (txn: DurableObjectTransaction) => Promise<T>
): Promise<T>;
getAlarm(
options?: DurableObjectStorageOperationsGetAlarmOptions
): Promise<Date | null>;
getAlarm(options?: DurableObjectGetAlarmOptions): Promise<number | null>;
setAlarm(
arg2: Date,
options?: DurableObjectStorageOperationsSetAlarmOptions
scheduledTime: Date,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this right? getAlarm returns a number, but setAlarm takes a Date? Should setAlarm take number | Date?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setAlarm does take number | Date, I guess we need to update the type generation script to understand this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setAlarm(kj::Date scheduledTime

Are you sure about that Matt? The type generation script is pretty stable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we don't return a Date from getAlarm?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setAlarm(kj::Date scheduledTime

Are you sure about that Matt? The type generation script is pretty stable.

It's possible CFJS automatically casts numbers to kj::Dates?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that Brendan's observation is valid. This API is asymmetric which is odd.

@xortive could you see what's causing this and see if we can fix it? thank you

options?: DurableObjectSetAlarmOptions
): Promise<void>;
}

interface DurableObjectStorageOperationsGetAlarmOptions {
allowConcurrency?: boolean;
deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise<void>;
}

/**
Expand All @@ -451,11 +455,6 @@ declare type DurableObjectStorageOperationsListOptions =
*/
declare type DurableObjectStorageOperationsPutOptions = DurableObjectPutOptions;

interface DurableObjectStorageOperationsSetAlarmOptions {
allowConcurrency?: boolean;
allowUnconfirmed?: boolean;
}

interface DurableObjectStub extends Fetcher {
readonly id: DurableObjectId;
readonly name?: string;
Expand All @@ -482,13 +481,12 @@ interface DurableObjectTransaction {
delete(key: string, options?: DurableObjectPutOptions): Promise<boolean>;
delete(keys: string[], options?: DurableObjectPutOptions): Promise<number>;
rollback(): void;
getAlarm(
options?: DurableObjectStorageOperationsGetAlarmOptions
): Promise<Date | null>;
getAlarm(options?: DurableObjectGetAlarmOptions): Promise<number | null>;
setAlarm(
arg2: Date,
options?: DurableObjectStorageOperationsSetAlarmOptions
scheduledTime: Date,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, should this be number | Date?

options?: DurableObjectSetAlarmOptions
): Promise<void>;
deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise<void>;
}

interface Element {
Expand Down Expand Up @@ -1003,7 +1001,13 @@ interface R2Bucket {
get(key: string, options?: R2GetOptions): Promise<R2ObjectBody | null>;
put(
key: string,
value: ReadableStream | ArrayBuffer | ArrayBufferView | string | null,
value:
| ReadableStream
| ArrayBuffer
| ArrayBufferView
| string
| null
| Blob,
options?: R2PutOptions
): Promise<R2Object>;
delete(key: string): Promise<void>;
Expand Down Expand Up @@ -1077,7 +1081,7 @@ interface R2ListOptions {
* }
* ```
*/
include: ("httpMetadata" | "customMetadata")[];
include?: ("httpMetadata" | "customMetadata")[];
}

/**
Expand Down Expand Up @@ -1135,12 +1139,15 @@ declare abstract class ReadableByteStreamController {
readonly byobRequest: ReadableStreamBYOBRequest | null;
readonly desiredSize: number | null;
close(): void;
enqueue(chunk: ArrayBufferView): void;
enqueue(chunk: ArrayBuffer | ArrayBufferView): void;
error(reason: any): void;
}

declare class ReadableStream {
constructor(underlyingSource?: Object, queuingStrategy?: Object);
constructor(
underlyingSource?: UnderlyingSource,
queuingStrategy?: StreamQueuingStrategy
);
readonly locked: boolean;
cancel(reason?: any): Promise<void>;
getReader(options: ReadableStreamGetReaderOptions): ReadableStreamBYOBReader;
Expand Down Expand Up @@ -1174,7 +1181,7 @@ declare class ReadableStreamBYOBReader {
declare abstract class ReadableStreamBYOBRequest {
readonly view: Uint8Array | null;
respond(bytesWritten: number): void;
respondWithNewView(view: ArrayBufferView): void;
respondWithNewView(view: ArrayBuffer | ArrayBufferView): void;
readonly atLeast: number | null;
}

Expand Down Expand Up @@ -1814,6 +1821,26 @@ declare type URLSearchParamsInit =
*/
declare type URLSearchParamsInitializer = URLSearchParamsInit;

interface UnderlyingSink {
type?: string;
start?(controller: WritableStreamDefaultController): any;
write?(chunk: any, controller: WritableStreamDefaultController): any;
abort?(reason: any): any;
close?(): any;
}

interface UnderlyingSource {
type?: string;
autoAllocateChunkSize?: number;
start?(
controller: ReadableStreamDefaultController | ReadableByteStreamController
): any;
pull?(
controller: ReadableStreamDefaultController | ReadableByteStreamController
): any;
cancel?(reason?: any): any;
}

declare class WebSocket extends EventTarget<WebSocketEventMap> {
constructor(url: string, protocols?: string[] | string);
accept(): void;
Expand Down Expand Up @@ -1848,7 +1875,10 @@ declare type WorkerGlobalScopeEventMap = {
};

declare class WritableStream {
constructor(underlyingSink?: Object, queuingStrategy?: Object);
constructor(
underlyingSink?: UnderlyingSink,
queuingStrategy?: StreamQueuingStrategy
);
readonly locked: boolean;
abort(reason: any): Promise<void>;
close(): Promise<void>;
Expand Down Expand Up @@ -1947,6 +1977,7 @@ type Params<P extends string = any> = Record<P, string | string[]>;

type EventContext<Env, P extends string, Data> = {
request: Request;
functionPath: string;
waitUntil: (promise: Promise<any>) => void;
next: (input?: Request | string, init?: RequestInit) => Promise<Response>;
env: Env & { ASSETS: { fetch: typeof fetch } };
Expand Down
Loading