@cloudflare/workers-types 4.20230511.0 → 4.20230628.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -217,6 +217,7 @@ declare interface ServiceWorkerGlobalScope extends WorkerGlobalScope {
217
217
  Response: typeof Response;
218
218
  WebSocket: typeof WebSocket;
219
219
  WebSocketPair: typeof WebSocketPair;
220
+ WebSocketRequestResponsePair: typeof WebSocketRequestResponsePair;
220
221
  AbortController: typeof AbortController;
221
222
  AbortSignal: typeof AbortSignal;
222
223
  TextDecoder: typeof TextDecoder;
@@ -332,7 +333,7 @@ declare type ExportedHandlerTestHandler<Env = unknown> = (
332
333
  ) => void | Promise<void>;
333
334
  declare interface ExportedHandler<
334
335
  Env = unknown,
335
- QueueMessage = unknown,
336
+ QueueHandlerMessage = unknown,
336
337
  CfHostMetadata = unknown
337
338
  > {
338
339
  fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata>;
@@ -340,7 +341,8 @@ declare interface ExportedHandler<
340
341
  trace?: ExportedHandlerTraceHandler<Env>;
341
342
  scheduled?: ExportedHandlerScheduledHandler<Env>;
342
343
  test?: ExportedHandlerTestHandler<Env>;
343
- queue?: ExportedHandlerQueueHandler<Env, Message>;
344
+ email?: EmailExportedHandler<Env>;
345
+ queue?: ExportedHandlerQueueHandler<Env, QueueHandlerMessage>;
344
346
  }
345
347
  declare interface StructuredSerializeOptions {
346
348
  transfer?: any[];
@@ -410,6 +412,9 @@ declare interface DurableObjectState {
410
412
  blockConcurrencyWhile<T>(callback: () => Promise<T>): Promise<T>;
411
413
  acceptWebSocket(ws: WebSocket, tags?: string[]): void;
412
414
  getWebSockets(tag?: string): WebSocket[];
415
+ setWebSocketAutoResponse(maybeReqResp?: WebSocketRequestResponsePair): void;
416
+ getWebSocketAutoResponse(): WebSocketRequestResponsePair | null;
417
+ getWebSocketAutoResponseTimestamp(ws: WebSocket): Date | null;
413
418
  abort(reason?: string): void;
414
419
  }
415
420
  declare interface DurableObjectTransaction {
@@ -478,6 +483,10 @@ declare interface DurableObjectStorage {
478
483
  deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise<void>;
479
484
  sync(): Promise<void>;
480
485
  sql: SqlStorage;
486
+ transactionSync<T>(closure: () => T): T;
487
+ getCurrentBookmark(): Promise<string>;
488
+ getBookmarkForTime(timestamp: number | Date): Promise<string>;
489
+ onNextSessionRestoreBookmark(bookmark: string): Promise<string>;
481
490
  }
482
491
  declare interface DurableObjectListOptions {
483
492
  start?: string;
@@ -505,6 +514,11 @@ declare interface DurableObjectSetAlarmOptions {
505
514
  allowConcurrency?: boolean;
506
515
  allowUnconfirmed?: boolean;
507
516
  }
517
+ declare class WebSocketRequestResponsePair {
518
+ constructor(request: string, response: string);
519
+ get request(): string;
520
+ get response(): string;
521
+ }
508
522
  declare interface AnalyticsEngineDataset {
509
523
  writeDataPoint(event?: AnalyticsEngineDataPoint): void;
510
524
  }
@@ -1682,6 +1696,7 @@ declare interface TraceItem {
1682
1696
  readonly eventTimestamp: number | null;
1683
1697
  readonly logs: TraceLog[];
1684
1698
  readonly exceptions: TraceException[];
1699
+ readonly diagnosticsChannelEvents: TraceDiagnosticChannelEvent[];
1685
1700
  readonly scriptName: string | null;
1686
1701
  readonly dispatchNamespace?: string;
1687
1702
  readonly scriptTags?: string[];
@@ -1728,6 +1743,11 @@ declare interface TraceException {
1728
1743
  readonly message: string;
1729
1744
  readonly name: string;
1730
1745
  }
1746
+ declare interface TraceDiagnosticChannelEvent {
1747
+ readonly timestamp: number;
1748
+ readonly channel: string;
1749
+ readonly message: any;
1750
+ }
1731
1751
  declare interface TraceMetrics {
1732
1752
  readonly cpuTime: number;
1733
1753
  readonly wallTime: number;
@@ -1769,10 +1789,10 @@ declare class URLSearchParams {
1769
1789
  );
1770
1790
  get size(): number;
1771
1791
  append(name: string, value: string): void;
1772
- delete(name: string): void;
1792
+ delete(name: string, value?: string): void;
1773
1793
  get(name: string): string | null;
1774
1794
  getAll(name: string): string[];
1775
- has(name: string): boolean;
1795
+ has(name: string, value?: string): boolean;
1776
1796
  set(name: string, value: string): void;
1777
1797
  sort(): void;
1778
1798
  entries(): IterableIterator<[key: string, value: string]>;
@@ -1893,8 +1913,6 @@ declare interface SqlStorage {
1893
1913
  exec(query: string, ...bindings: any[]): SqlStorageCursor;
1894
1914
  prepare(query: string): SqlStorageStatement;
1895
1915
  get databaseSize(): number;
1896
- get voluntarySizeLimit(): number;
1897
- set voluntarySizeLimit(value: number);
1898
1916
  Cursor: typeof SqlStorageCursor;
1899
1917
  Statement: typeof SqlStorageStatement;
1900
1918
  }
@@ -2895,22 +2913,27 @@ declare type CfProperties<HostMetadata = unknown> =
2895
2913
  | IncomingRequestCfProperties<HostMetadata>
2896
2914
  | RequestInitCfProperties;
2897
2915
  declare interface D1Result<T = unknown> {
2898
- results?: T[];
2899
- success: boolean;
2900
- error?: string;
2916
+ results: T[];
2917
+ success: true;
2901
2918
  meta: any;
2919
+ error?: never;
2920
+ }
2921
+ declare interface D1ExecResult {
2922
+ count: number;
2923
+ duration: number;
2902
2924
  }
2903
2925
  declare abstract class D1Database {
2904
2926
  prepare(query: string): D1PreparedStatement;
2905
2927
  dump(): Promise<ArrayBuffer>;
2906
2928
  batch<T = unknown>(statements: D1PreparedStatement[]): Promise<D1Result<T>[]>;
2907
- exec<T = unknown>(query: string): Promise<D1Result<T>>;
2929
+ exec<T = unknown>(query: string): Promise<D1ExecResult>;
2908
2930
  }
2909
2931
  declare abstract class D1PreparedStatement {
2910
2932
  bind(...values: any[]): D1PreparedStatement;
2911
- first<T = unknown>(colName?: string): Promise<T>;
2933
+ first<T = unknown>(colName: string): Promise<T | null>;
2934
+ first<T = unknown>(): Promise<Record<string, T> | null>;
2912
2935
  run<T = unknown>(): Promise<D1Result<T>>;
2913
- all<T = unknown>(): Promise<D1Result<T>>;
2936
+ all<T = unknown>(): Promise<D1Result<T[]>>;
2914
2937
  raw<T = unknown>(): Promise<T[]>;
2915
2938
  }
2916
2939
  /**
@@ -3057,12 +3080,49 @@ declare interface JsonWebKeyWithKid extends JsonWebKey {
3057
3080
  // Key Identifier of the JWK
3058
3081
  readonly kid: string;
3059
3082
  }
3083
+ declare module "cloudflare:sockets" {
3084
+ function _connect(
3085
+ address: string | SocketAddress,
3086
+ options?: SocketOptions
3087
+ ): Socket;
3088
+ export { _connect as connect };
3089
+ }
3060
3090
  // https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/
3091
+ declare interface DynamicDispatchLimits {
3092
+ /**
3093
+ * Limit CPU time in milliseconds.
3094
+ */
3095
+ cpuMs?: number;
3096
+ /**
3097
+ * Limit number of subrequests.
3098
+ */
3099
+ subRequests?: number;
3100
+ }
3101
+ declare interface DynamicDispatchOptions {
3102
+ /**
3103
+ * Limit resources of invoked Worker script.
3104
+ */
3105
+ limits?: DynamicDispatchLimits;
3106
+ /**
3107
+ * Arguments for outbound Worker script, if configured.
3108
+ */
3109
+ outbound?: {
3110
+ [key: string]: any;
3111
+ };
3112
+ }
3061
3113
  declare interface DispatchNamespace {
3062
3114
  /**
3063
3115
  * @param name Name of the Worker script.
3116
+ * @param args Arguments to Worker script.
3117
+ * @param options Options for Dynamic Dispatch invocation.
3064
3118
  * @returns A Fetcher object that allows you to send requests to the Worker script.
3065
3119
  * @throws If the Worker script does not exist in this dispatch namespace, an error will be thrown.
3066
3120
  */
3067
- get(name: string): Fetcher;
3121
+ get(
3122
+ name: string,
3123
+ args?: {
3124
+ [key: string]: any;
3125
+ },
3126
+ options?: DynamicDispatchOptions
3127
+ ): Fetcher;
3068
3128
  }
@@ -217,6 +217,7 @@ export interface ServiceWorkerGlobalScope extends WorkerGlobalScope {
217
217
  Response: typeof Response;
218
218
  WebSocket: typeof WebSocket;
219
219
  WebSocketPair: typeof WebSocketPair;
220
+ WebSocketRequestResponsePair: typeof WebSocketRequestResponsePair;
220
221
  AbortController: typeof AbortController;
221
222
  AbortSignal: typeof AbortSignal;
222
223
  TextDecoder: typeof TextDecoder;
@@ -334,7 +335,7 @@ export type ExportedHandlerTestHandler<Env = unknown> = (
334
335
  ) => void | Promise<void>;
335
336
  export interface ExportedHandler<
336
337
  Env = unknown,
337
- QueueMessage = unknown,
338
+ QueueHandlerMessage = unknown,
338
339
  CfHostMetadata = unknown
339
340
  > {
340
341
  fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata>;
@@ -342,7 +343,8 @@ export interface ExportedHandler<
342
343
  trace?: ExportedHandlerTraceHandler<Env>;
343
344
  scheduled?: ExportedHandlerScheduledHandler<Env>;
344
345
  test?: ExportedHandlerTestHandler<Env>;
345
- queue?: ExportedHandlerQueueHandler<Env, Message>;
346
+ email?: EmailExportedHandler<Env>;
347
+ queue?: ExportedHandlerQueueHandler<Env, QueueHandlerMessage>;
346
348
  }
347
349
  export interface StructuredSerializeOptions {
348
350
  transfer?: any[];
@@ -412,6 +414,9 @@ export interface DurableObjectState {
412
414
  blockConcurrencyWhile<T>(callback: () => Promise<T>): Promise<T>;
413
415
  acceptWebSocket(ws: WebSocket, tags?: string[]): void;
414
416
  getWebSockets(tag?: string): WebSocket[];
417
+ setWebSocketAutoResponse(maybeReqResp?: WebSocketRequestResponsePair): void;
418
+ getWebSocketAutoResponse(): WebSocketRequestResponsePair | null;
419
+ getWebSocketAutoResponseTimestamp(ws: WebSocket): Date | null;
415
420
  abort(reason?: string): void;
416
421
  }
417
422
  export interface DurableObjectTransaction {
@@ -480,6 +485,10 @@ export interface DurableObjectStorage {
480
485
  deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise<void>;
481
486
  sync(): Promise<void>;
482
487
  sql: SqlStorage;
488
+ transactionSync<T>(closure: () => T): T;
489
+ getCurrentBookmark(): Promise<string>;
490
+ getBookmarkForTime(timestamp: number | Date): Promise<string>;
491
+ onNextSessionRestoreBookmark(bookmark: string): Promise<string>;
483
492
  }
484
493
  export interface DurableObjectListOptions {
485
494
  start?: string;
@@ -507,6 +516,11 @@ export interface DurableObjectSetAlarmOptions {
507
516
  allowConcurrency?: boolean;
508
517
  allowUnconfirmed?: boolean;
509
518
  }
519
+ export declare class WebSocketRequestResponsePair {
520
+ constructor(request: string, response: string);
521
+ get request(): string;
522
+ get response(): string;
523
+ }
510
524
  export interface AnalyticsEngineDataset {
511
525
  writeDataPoint(event?: AnalyticsEngineDataPoint): void;
512
526
  }
@@ -1687,6 +1701,7 @@ export interface TraceItem {
1687
1701
  readonly eventTimestamp: number | null;
1688
1702
  readonly logs: TraceLog[];
1689
1703
  readonly exceptions: TraceException[];
1704
+ readonly diagnosticsChannelEvents: TraceDiagnosticChannelEvent[];
1690
1705
  readonly scriptName: string | null;
1691
1706
  readonly dispatchNamespace?: string;
1692
1707
  readonly scriptTags?: string[];
@@ -1733,6 +1748,11 @@ export interface TraceException {
1733
1748
  readonly message: string;
1734
1749
  readonly name: string;
1735
1750
  }
1751
+ export interface TraceDiagnosticChannelEvent {
1752
+ readonly timestamp: number;
1753
+ readonly channel: string;
1754
+ readonly message: any;
1755
+ }
1736
1756
  export interface TraceMetrics {
1737
1757
  readonly cpuTime: number;
1738
1758
  readonly wallTime: number;
@@ -1774,10 +1794,10 @@ export declare class URLSearchParams {
1774
1794
  );
1775
1795
  get size(): number;
1776
1796
  append(name: string, value: string): void;
1777
- delete(name: string): void;
1797
+ delete(name: string, value?: string): void;
1778
1798
  get(name: string): string | null;
1779
1799
  getAll(name: string): string[];
1780
- has(name: string): boolean;
1800
+ has(name: string, value?: string): boolean;
1781
1801
  set(name: string, value: string): void;
1782
1802
  sort(): void;
1783
1803
  entries(): IterableIterator<[key: string, value: string]>;
@@ -1898,8 +1918,6 @@ export interface SqlStorage {
1898
1918
  exec(query: string, ...bindings: any[]): SqlStorageCursor;
1899
1919
  prepare(query: string): SqlStorageStatement;
1900
1920
  get databaseSize(): number;
1901
- get voluntarySizeLimit(): number;
1902
- set voluntarySizeLimit(value: number);
1903
1921
  Cursor: typeof SqlStorageCursor;
1904
1922
  Statement: typeof SqlStorageStatement;
1905
1923
  }
@@ -2900,22 +2918,27 @@ export type CfProperties<HostMetadata = unknown> =
2900
2918
  | IncomingRequestCfProperties<HostMetadata>
2901
2919
  | RequestInitCfProperties;
2902
2920
  export interface D1Result<T = unknown> {
2903
- results?: T[];
2904
- success: boolean;
2905
- error?: string;
2921
+ results: T[];
2922
+ success: true;
2906
2923
  meta: any;
2924
+ error?: never;
2925
+ }
2926
+ export interface D1ExecResult {
2927
+ count: number;
2928
+ duration: number;
2907
2929
  }
2908
2930
  export declare abstract class D1Database {
2909
2931
  prepare(query: string): D1PreparedStatement;
2910
2932
  dump(): Promise<ArrayBuffer>;
2911
2933
  batch<T = unknown>(statements: D1PreparedStatement[]): Promise<D1Result<T>[]>;
2912
- exec<T = unknown>(query: string): Promise<D1Result<T>>;
2934
+ exec<T = unknown>(query: string): Promise<D1ExecResult>;
2913
2935
  }
2914
2936
  export declare abstract class D1PreparedStatement {
2915
2937
  bind(...values: any[]): D1PreparedStatement;
2916
- first<T = unknown>(colName?: string): Promise<T>;
2938
+ first<T = unknown>(colName: string): Promise<T | null>;
2939
+ first<T = unknown>(): Promise<Record<string, T> | null>;
2917
2940
  run<T = unknown>(): Promise<D1Result<T>>;
2918
- all<T = unknown>(): Promise<D1Result<T>>;
2941
+ all<T = unknown>(): Promise<D1Result<T[]>>;
2919
2942
  raw<T = unknown>(): Promise<T[]>;
2920
2943
  }
2921
2944
  /**
@@ -3053,11 +3076,41 @@ export interface JsonWebKeyWithKid extends JsonWebKey {
3053
3076
  readonly kid: string;
3054
3077
  }
3055
3078
  // https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/
3079
+ export interface DynamicDispatchLimits {
3080
+ /**
3081
+ * Limit CPU time in milliseconds.
3082
+ */
3083
+ cpuMs?: number;
3084
+ /**
3085
+ * Limit number of subrequests.
3086
+ */
3087
+ subRequests?: number;
3088
+ }
3089
+ export interface DynamicDispatchOptions {
3090
+ /**
3091
+ * Limit resources of invoked Worker script.
3092
+ */
3093
+ limits?: DynamicDispatchLimits;
3094
+ /**
3095
+ * Arguments for outbound Worker script, if configured.
3096
+ */
3097
+ outbound?: {
3098
+ [key: string]: any;
3099
+ };
3100
+ }
3056
3101
  export interface DispatchNamespace {
3057
3102
  /**
3058
3103
  * @param name Name of the Worker script.
3104
+ * @param args Arguments to Worker script.
3105
+ * @param options Options for Dynamic Dispatch invocation.
3059
3106
  * @returns A Fetcher object that allows you to send requests to the Worker script.
3060
3107
  * @throws If the Worker script does not exist in this dispatch namespace, an error will be thrown.
3061
3108
  */
3062
- get(name: string): Fetcher;
3109
+ get(
3110
+ name: string,
3111
+ args?: {
3112
+ [key: string]: any;
3113
+ },
3114
+ options?: DynamicDispatchOptions
3115
+ ): Fetcher;
3063
3116
  }
package/index.d.ts CHANGED
@@ -213,6 +213,7 @@ declare interface ServiceWorkerGlobalScope extends WorkerGlobalScope {
213
213
  Response: typeof Response;
214
214
  WebSocket: typeof WebSocket;
215
215
  WebSocketPair: typeof WebSocketPair;
216
+ WebSocketRequestResponsePair: typeof WebSocketRequestResponsePair;
216
217
  AbortController: typeof AbortController;
217
218
  AbortSignal: typeof AbortSignal;
218
219
  TextDecoder: typeof TextDecoder;
@@ -325,7 +326,7 @@ declare type ExportedHandlerTestHandler<Env = unknown> = (
325
326
  ) => void | Promise<void>;
326
327
  declare interface ExportedHandler<
327
328
  Env = unknown,
328
- QueueMessage = unknown,
329
+ QueueHandlerMessage = unknown,
329
330
  CfHostMetadata = unknown
330
331
  > {
331
332
  fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata>;
@@ -333,7 +334,8 @@ declare interface ExportedHandler<
333
334
  trace?: ExportedHandlerTraceHandler<Env>;
334
335
  scheduled?: ExportedHandlerScheduledHandler<Env>;
335
336
  test?: ExportedHandlerTestHandler<Env>;
336
- queue?: ExportedHandlerQueueHandler<Env, Message>;
337
+ email?: EmailExportedHandler<Env>;
338
+ queue?: ExportedHandlerQueueHandler<Env, QueueHandlerMessage>;
337
339
  }
338
340
  declare interface StructuredSerializeOptions {
339
341
  transfer?: any[];
@@ -396,6 +398,9 @@ declare interface DurableObjectState {
396
398
  blockConcurrencyWhile<T>(callback: () => Promise<T>): Promise<T>;
397
399
  acceptWebSocket(ws: WebSocket, tags?: string[]): void;
398
400
  getWebSockets(tag?: string): WebSocket[];
401
+ setWebSocketAutoResponse(maybeReqResp?: WebSocketRequestResponsePair): void;
402
+ getWebSocketAutoResponse(): WebSocketRequestResponsePair | null;
403
+ getWebSocketAutoResponseTimestamp(ws: WebSocket): Date | null;
399
404
  }
400
405
  declare interface DurableObjectTransaction {
401
406
  get<T = unknown>(
@@ -462,6 +467,7 @@ declare interface DurableObjectStorage {
462
467
  ): Promise<void>;
463
468
  deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise<void>;
464
469
  sync(): Promise<void>;
470
+ transactionSync<T>(closure: () => T): T;
465
471
  }
466
472
  declare interface DurableObjectListOptions {
467
473
  start?: string;
@@ -489,6 +495,11 @@ declare interface DurableObjectSetAlarmOptions {
489
495
  allowConcurrency?: boolean;
490
496
  allowUnconfirmed?: boolean;
491
497
  }
498
+ declare class WebSocketRequestResponsePair {
499
+ constructor(request: string, response: string);
500
+ get request(): string;
501
+ get response(): string;
502
+ }
492
503
  declare interface AnalyticsEngineDataset {
493
504
  writeDataPoint(event?: AnalyticsEngineDataPoint): void;
494
505
  }
@@ -1669,6 +1680,7 @@ declare interface TraceItem {
1669
1680
  readonly eventTimestamp: number | null;
1670
1681
  readonly logs: TraceLog[];
1671
1682
  readonly exceptions: TraceException[];
1683
+ readonly diagnosticsChannelEvents: TraceDiagnosticChannelEvent[];
1672
1684
  readonly scriptName: string | null;
1673
1685
  readonly dispatchNamespace?: string;
1674
1686
  readonly scriptTags?: string[];
@@ -1715,6 +1727,11 @@ declare interface TraceException {
1715
1727
  readonly message: string;
1716
1728
  readonly name: string;
1717
1729
  }
1730
+ declare interface TraceDiagnosticChannelEvent {
1731
+ readonly timestamp: number;
1732
+ readonly channel: string;
1733
+ readonly message: any;
1734
+ }
1718
1735
  declare interface TraceMetrics {
1719
1736
  readonly cpuTime: number;
1720
1737
  readonly wallTime: number;
@@ -2863,22 +2880,27 @@ declare type CfProperties<HostMetadata = unknown> =
2863
2880
  | IncomingRequestCfProperties<HostMetadata>
2864
2881
  | RequestInitCfProperties;
2865
2882
  declare interface D1Result<T = unknown> {
2866
- results?: T[];
2867
- success: boolean;
2868
- error?: string;
2883
+ results: T[];
2884
+ success: true;
2869
2885
  meta: any;
2886
+ error?: never;
2887
+ }
2888
+ declare interface D1ExecResult {
2889
+ count: number;
2890
+ duration: number;
2870
2891
  }
2871
2892
  declare abstract class D1Database {
2872
2893
  prepare(query: string): D1PreparedStatement;
2873
2894
  dump(): Promise<ArrayBuffer>;
2874
2895
  batch<T = unknown>(statements: D1PreparedStatement[]): Promise<D1Result<T>[]>;
2875
- exec<T = unknown>(query: string): Promise<D1Result<T>>;
2896
+ exec<T = unknown>(query: string): Promise<D1ExecResult>;
2876
2897
  }
2877
2898
  declare abstract class D1PreparedStatement {
2878
2899
  bind(...values: any[]): D1PreparedStatement;
2879
- first<T = unknown>(colName?: string): Promise<T>;
2900
+ first<T = unknown>(colName: string): Promise<T | null>;
2901
+ first<T = unknown>(): Promise<Record<string, T> | null>;
2880
2902
  run<T = unknown>(): Promise<D1Result<T>>;
2881
- all<T = unknown>(): Promise<D1Result<T>>;
2903
+ all<T = unknown>(): Promise<D1Result<T[]>>;
2882
2904
  raw<T = unknown>(): Promise<T[]>;
2883
2905
  }
2884
2906
  /**
@@ -3025,12 +3047,49 @@ declare interface JsonWebKeyWithKid extends JsonWebKey {
3025
3047
  // Key Identifier of the JWK
3026
3048
  readonly kid: string;
3027
3049
  }
3050
+ declare module "cloudflare:sockets" {
3051
+ function _connect(
3052
+ address: string | SocketAddress,
3053
+ options?: SocketOptions
3054
+ ): Socket;
3055
+ export { _connect as connect };
3056
+ }
3028
3057
  // https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/
3058
+ declare interface DynamicDispatchLimits {
3059
+ /**
3060
+ * Limit CPU time in milliseconds.
3061
+ */
3062
+ cpuMs?: number;
3063
+ /**
3064
+ * Limit number of subrequests.
3065
+ */
3066
+ subRequests?: number;
3067
+ }
3068
+ declare interface DynamicDispatchOptions {
3069
+ /**
3070
+ * Limit resources of invoked Worker script.
3071
+ */
3072
+ limits?: DynamicDispatchLimits;
3073
+ /**
3074
+ * Arguments for outbound Worker script, if configured.
3075
+ */
3076
+ outbound?: {
3077
+ [key: string]: any;
3078
+ };
3079
+ }
3029
3080
  declare interface DispatchNamespace {
3030
3081
  /**
3031
3082
  * @param name Name of the Worker script.
3083
+ * @param args Arguments to Worker script.
3084
+ * @param options Options for Dynamic Dispatch invocation.
3032
3085
  * @returns A Fetcher object that allows you to send requests to the Worker script.
3033
3086
  * @throws If the Worker script does not exist in this dispatch namespace, an error will be thrown.
3034
3087
  */
3035
- get(name: string): Fetcher;
3088
+ get(
3089
+ name: string,
3090
+ args?: {
3091
+ [key: string]: any;
3092
+ },
3093
+ options?: DynamicDispatchOptions
3094
+ ): Fetcher;
3036
3095
  }
package/index.ts CHANGED
@@ -213,6 +213,7 @@ export interface ServiceWorkerGlobalScope extends WorkerGlobalScope {
213
213
  Response: typeof Response;
214
214
  WebSocket: typeof WebSocket;
215
215
  WebSocketPair: typeof WebSocketPair;
216
+ WebSocketRequestResponsePair: typeof WebSocketRequestResponsePair;
216
217
  AbortController: typeof AbortController;
217
218
  AbortSignal: typeof AbortSignal;
218
219
  TextDecoder: typeof TextDecoder;
@@ -327,7 +328,7 @@ export type ExportedHandlerTestHandler<Env = unknown> = (
327
328
  ) => void | Promise<void>;
328
329
  export interface ExportedHandler<
329
330
  Env = unknown,
330
- QueueMessage = unknown,
331
+ QueueHandlerMessage = unknown,
331
332
  CfHostMetadata = unknown
332
333
  > {
333
334
  fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata>;
@@ -335,7 +336,8 @@ export interface ExportedHandler<
335
336
  trace?: ExportedHandlerTraceHandler<Env>;
336
337
  scheduled?: ExportedHandlerScheduledHandler<Env>;
337
338
  test?: ExportedHandlerTestHandler<Env>;
338
- queue?: ExportedHandlerQueueHandler<Env, Message>;
339
+ email?: EmailExportedHandler<Env>;
340
+ queue?: ExportedHandlerQueueHandler<Env, QueueHandlerMessage>;
339
341
  }
340
342
  export interface StructuredSerializeOptions {
341
343
  transfer?: any[];
@@ -398,6 +400,9 @@ export interface DurableObjectState {
398
400
  blockConcurrencyWhile<T>(callback: () => Promise<T>): Promise<T>;
399
401
  acceptWebSocket(ws: WebSocket, tags?: string[]): void;
400
402
  getWebSockets(tag?: string): WebSocket[];
403
+ setWebSocketAutoResponse(maybeReqResp?: WebSocketRequestResponsePair): void;
404
+ getWebSocketAutoResponse(): WebSocketRequestResponsePair | null;
405
+ getWebSocketAutoResponseTimestamp(ws: WebSocket): Date | null;
401
406
  }
402
407
  export interface DurableObjectTransaction {
403
408
  get<T = unknown>(
@@ -464,6 +469,7 @@ export interface DurableObjectStorage {
464
469
  ): Promise<void>;
465
470
  deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise<void>;
466
471
  sync(): Promise<void>;
472
+ transactionSync<T>(closure: () => T): T;
467
473
  }
468
474
  export interface DurableObjectListOptions {
469
475
  start?: string;
@@ -491,6 +497,11 @@ export interface DurableObjectSetAlarmOptions {
491
497
  allowConcurrency?: boolean;
492
498
  allowUnconfirmed?: boolean;
493
499
  }
500
+ export declare class WebSocketRequestResponsePair {
501
+ constructor(request: string, response: string);
502
+ get request(): string;
503
+ get response(): string;
504
+ }
494
505
  export interface AnalyticsEngineDataset {
495
506
  writeDataPoint(event?: AnalyticsEngineDataPoint): void;
496
507
  }
@@ -1674,6 +1685,7 @@ export interface TraceItem {
1674
1685
  readonly eventTimestamp: number | null;
1675
1686
  readonly logs: TraceLog[];
1676
1687
  readonly exceptions: TraceException[];
1688
+ readonly diagnosticsChannelEvents: TraceDiagnosticChannelEvent[];
1677
1689
  readonly scriptName: string | null;
1678
1690
  readonly dispatchNamespace?: string;
1679
1691
  readonly scriptTags?: string[];
@@ -1720,6 +1732,11 @@ export interface TraceException {
1720
1732
  readonly message: string;
1721
1733
  readonly name: string;
1722
1734
  }
1735
+ export interface TraceDiagnosticChannelEvent {
1736
+ readonly timestamp: number;
1737
+ readonly channel: string;
1738
+ readonly message: any;
1739
+ }
1723
1740
  export interface TraceMetrics {
1724
1741
  readonly cpuTime: number;
1725
1742
  readonly wallTime: number;
@@ -2868,22 +2885,27 @@ export type CfProperties<HostMetadata = unknown> =
2868
2885
  | IncomingRequestCfProperties<HostMetadata>
2869
2886
  | RequestInitCfProperties;
2870
2887
  export interface D1Result<T = unknown> {
2871
- results?: T[];
2872
- success: boolean;
2873
- error?: string;
2888
+ results: T[];
2889
+ success: true;
2874
2890
  meta: any;
2891
+ error?: never;
2892
+ }
2893
+ export interface D1ExecResult {
2894
+ count: number;
2895
+ duration: number;
2875
2896
  }
2876
2897
  export declare abstract class D1Database {
2877
2898
  prepare(query: string): D1PreparedStatement;
2878
2899
  dump(): Promise<ArrayBuffer>;
2879
2900
  batch<T = unknown>(statements: D1PreparedStatement[]): Promise<D1Result<T>[]>;
2880
- exec<T = unknown>(query: string): Promise<D1Result<T>>;
2901
+ exec<T = unknown>(query: string): Promise<D1ExecResult>;
2881
2902
  }
2882
2903
  export declare abstract class D1PreparedStatement {
2883
2904
  bind(...values: any[]): D1PreparedStatement;
2884
- first<T = unknown>(colName?: string): Promise<T>;
2905
+ first<T = unknown>(colName: string): Promise<T | null>;
2906
+ first<T = unknown>(): Promise<Record<string, T> | null>;
2885
2907
  run<T = unknown>(): Promise<D1Result<T>>;
2886
- all<T = unknown>(): Promise<D1Result<T>>;
2908
+ all<T = unknown>(): Promise<D1Result<T[]>>;
2887
2909
  raw<T = unknown>(): Promise<T[]>;
2888
2910
  }
2889
2911
  /**
@@ -3021,11 +3043,41 @@ export interface JsonWebKeyWithKid extends JsonWebKey {
3021
3043
  readonly kid: string;
3022
3044
  }
3023
3045
  // https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/
3046
+ export interface DynamicDispatchLimits {
3047
+ /**
3048
+ * Limit CPU time in milliseconds.
3049
+ */
3050
+ cpuMs?: number;
3051
+ /**
3052
+ * Limit number of subrequests.
3053
+ */
3054
+ subRequests?: number;
3055
+ }
3056
+ export interface DynamicDispatchOptions {
3057
+ /**
3058
+ * Limit resources of invoked Worker script.
3059
+ */
3060
+ limits?: DynamicDispatchLimits;
3061
+ /**
3062
+ * Arguments for outbound Worker script, if configured.
3063
+ */
3064
+ outbound?: {
3065
+ [key: string]: any;
3066
+ };
3067
+ }
3024
3068
  export interface DispatchNamespace {
3025
3069
  /**
3026
3070
  * @param name Name of the Worker script.
3071
+ * @param args Arguments to Worker script.
3072
+ * @param options Options for Dynamic Dispatch invocation.
3027
3073
  * @returns A Fetcher object that allows you to send requests to the Worker script.
3028
3074
  * @throws If the Worker script does not exist in this dispatch namespace, an error will be thrown.
3029
3075
  */
3030
- get(name: string): Fetcher;
3076
+ get(
3077
+ name: string,
3078
+ args?: {
3079
+ [key: string]: any;
3080
+ },
3081
+ options?: DynamicDispatchOptions
3082
+ ): Fetcher;
3031
3083
  }