@cloudflare/workers-types 4.20230904.0 → 4.20230914.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.
@@ -878,7 +878,7 @@ declare class TextDecoder {
878
878
  }
879
879
  declare class TextEncoder {
880
880
  constructor();
881
- encode(input?: string): ArrayBuffer | ArrayBufferView;
881
+ encode(input?: string): Uint8Array;
882
882
  encodeInto(
883
883
  input: string,
884
884
  buffer: ArrayBuffer | ArrayBufferView
@@ -2900,9 +2900,6 @@ declare type ContinentCode = "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA";
2900
2900
  declare type CfProperties<HostMetadata = unknown> =
2901
2901
  | IncomingRequestCfProperties<HostMetadata>
2902
2902
  | RequestInitCfProperties;
2903
- // Copyright (c) 2022-2023 Cloudflare, Inc.
2904
- // Licensed under the Apache 2.0 license found in the LICENSE file or at:
2905
- // https://opensource.org/licenses/Apache-2.0
2906
2903
  declare interface D1Result<T = unknown> {
2907
2904
  results: T[];
2908
2905
  success: true;
@@ -2927,9 +2924,6 @@ declare abstract class D1PreparedStatement {
2927
2924
  all<T = Record<string, unknown>>(): Promise<D1Result<T>>;
2928
2925
  raw<T = unknown[]>(): Promise<T[]>;
2929
2926
  }
2930
- // Copyright (c) 2023 Cloudflare, Inc.
2931
- // Licensed under the Apache 2.0 license found in the LICENSE file or at:
2932
- // https://opensource.org/licenses/Apache-2.0
2933
2927
  /**
2934
2928
  * An email message that can be sent from a Worker.
2935
2929
  */
@@ -2994,9 +2988,53 @@ declare module "cloudflare:email" {
2994
2988
  };
2995
2989
  export { _EmailMessage as EmailMessage };
2996
2990
  }
2997
- // Copyright (c) 2022-2023 Cloudflare, Inc.
2998
- // Licensed under the Apache 2.0 license found in the LICENSE file or at:
2999
- // https://opensource.org/licenses/Apache-2.0
2991
+ declare interface Hyperdrive {
2992
+ /**
2993
+ * Connect directly to Hyperdrive as if it's your database, returning a TCP socket.
2994
+ *
2995
+ * Calling this method returns an idential socket to if you call
2996
+ * `connect("host:port")` using the `host` and `port` fields from this object.
2997
+ * Pick whichever approach works better with your preferred DB client library.
2998
+ *
2999
+ * Note that this socket is not yet authenticated -- it's expected that your
3000
+ * code (or preferably, the client library of your choice) will authenticate
3001
+ * using the information in this class's readonly fields.
3002
+ */
3003
+ connect(): Socket;
3004
+ /**
3005
+ * A valid DB connection string that can be passed straight into the typical
3006
+ * client library/driver/ORM. This will typically be the easiest way to use
3007
+ * Hyperdrive.
3008
+ */
3009
+ readonly connectionString: string;
3010
+ /*
3011
+ * A randomly generated hostname that is only valid within the context of the
3012
+ * currently running Worker which, when passed into `connect()` function from
3013
+ * the "cloudflare:sockets" module, will connect to the Hyperdrive instance
3014
+ * for your database.
3015
+ */
3016
+ readonly host: string;
3017
+ /*
3018
+ * The port that must be paired the the host field when connecting.
3019
+ */
3020
+ readonly port: string;
3021
+ /*
3022
+ * The username to use when authenticating to your database via Hyperdrive.
3023
+ * Unlike the host and password, this will be the same every time
3024
+ */
3025
+ readonly user: string;
3026
+ /*
3027
+ * The randomly generated password to use when authenticating to your
3028
+ * database via Hyperdrive. Like the host field, this password is only valid
3029
+ * within the context of the currently running Worker instance from which
3030
+ * it's read.
3031
+ */
3032
+ readonly password: string;
3033
+ /*
3034
+ * The name of the database to connect to.
3035
+ */
3036
+ readonly database: string;
3037
+ }
3000
3038
  declare type Params<P extends string = any> = Record<P, string | string[]>;
3001
3039
  declare type EventContext<Env, P extends string, Data> = {
3002
3040
  request: Request;
@@ -3043,13 +3081,10 @@ declare type PagesPluginFunction<
3043
3081
  declare module "assets:*" {
3044
3082
  export const onRequest: PagesFunction;
3045
3083
  }
3046
- // Copyright (c) 2023 Cloudflare, Inc.
3047
- // Licensed under the Apache 2.0 license found in the LICENSE file or at:
3048
- // https://opensource.org/licenses/Apache-2.0
3049
- // https://developers.cloudflare.com/pub-sub/
3050
3084
  // PubSubMessage represents an incoming PubSub message.
3051
3085
  // The message includes metadata about the broker, the client, and the payload
3052
3086
  // itself.
3087
+ // https://developers.cloudflare.com/pub-sub/
3053
3088
  declare interface PubSubMessage {
3054
3089
  // Message ID
3055
3090
  readonly mid: number;
@@ -3080,9 +3115,6 @@ declare interface JsonWebKeyWithKid extends JsonWebKey {
3080
3115
  // Key Identifier of the JWK
3081
3116
  readonly kid: string;
3082
3117
  }
3083
- // Copyright (c) 2023 Cloudflare, Inc.
3084
- // Licensed under the Apache 2.0 license found in the LICENSE file or at:
3085
- // https://opensource.org/licenses/Apache-2.0
3086
3118
  declare module "cloudflare:sockets" {
3087
3119
  function _connect(
3088
3120
  address: string | SocketAddress,
@@ -3090,10 +3122,149 @@ declare module "cloudflare:sockets" {
3090
3122
  ): Socket;
3091
3123
  export { _connect as connect };
3092
3124
  }
3093
- // Copyright (c) 2023 Cloudflare, Inc.
3125
+ // Copyright (c) 2022-2023 Cloudflare, Inc.
3094
3126
  // Licensed under the Apache 2.0 license found in the LICENSE file or at:
3095
3127
  // https://opensource.org/licenses/Apache-2.0
3096
- // https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/
3128
+ /**
3129
+ * Additional information to associate with a vector.
3130
+ */
3131
+ declare type VectorizeVectorMetadata =
3132
+ | string
3133
+ | number
3134
+ | boolean
3135
+ | string[]
3136
+ | Record<string, string | number | boolean | string[]>;
3137
+ declare type VectorFloatArray = Float32Array | Float64Array;
3138
+ declare interface VectorizeError {
3139
+ code?: number;
3140
+ error: string;
3141
+ }
3142
+ /**
3143
+ * A pre-configured list of known models.
3144
+ * These can be supplied in place of configuring explicit dimensions.
3145
+ */
3146
+ declare type VectorizePreset =
3147
+ | "openapi-text-embedding-ada-002"
3148
+ | "workers-ai/bge-small-en"
3149
+ | "cohere/embed-multilingual-v2.0";
3150
+ /**
3151
+ * Supported distance metrics for an index.
3152
+ * Distance metrics determine how other "similar" vectors are determined.
3153
+ */
3154
+ declare type VectorizeDistanceMetric = "euclidean" | "cosine" | "dot-product";
3155
+ declare interface VectorizeQueryOptions {
3156
+ topK?: number;
3157
+ namespace?: string;
3158
+ returnVectors?: boolean;
3159
+ }
3160
+ /**
3161
+ * Information about the configuration of an index.
3162
+ */
3163
+ declare type VectorizeIndexConfig =
3164
+ | {
3165
+ dimensions: number;
3166
+ metric: VectorizeDistanceMetric;
3167
+ }
3168
+ | {
3169
+ preset: VectorizePreset;
3170
+ };
3171
+ /**
3172
+ * Metadata about an existing index.
3173
+ */
3174
+ declare interface VectorizeIndexDetails {
3175
+ /** The unique ID of the index */
3176
+ readonly id: string;
3177
+ /** The name of the index. */
3178
+ name: string;
3179
+ /** (optional) A human readable description for the index. */
3180
+ description?: string;
3181
+ /** The index configuration, including the dimension size and distance metric. */
3182
+ config: VectorizeIndexConfig;
3183
+ /** The number of records containing vectors within the index. */
3184
+ vectorsCount: number;
3185
+ }
3186
+ /**
3187
+ * Represents a single vector value set along with its associated metadata.
3188
+ */
3189
+ declare interface VectorizeVector {
3190
+ /** The ID for the vector. This can be user-defined, and must be unique. It should uniquely identify the object, and is best set based on the ID of what the vector represents. */
3191
+ id: string;
3192
+ /** The vector values */
3193
+ values: VectorFloatArray | number[];
3194
+ /** The namespace this vector belongs to. */
3195
+ namespace?: string;
3196
+ /** Metadata associated with the binding. Includes the values of the other fields and potentially additional details. */
3197
+ metadata?: Record<string, VectorizeVectorMetadata>;
3198
+ }
3199
+ /**
3200
+ * Represents a matched vector for a query along with its score and (if specified) the matching vector information.
3201
+ */
3202
+ declare interface VectorizeMatch {
3203
+ /** The ID for the vector. This can be user-defined, and must be unique. It should uniquely identify the object, and is best set based on the ID of what the vector represents. */
3204
+ vectorId: string;
3205
+ /** The score or rank for similarity, when returned as a result */
3206
+ score: number;
3207
+ /** Vector data for the match. Included only if the user specified they want it returned (via {@link VectorizeQueryOptions}). */
3208
+ vector?: VectorizeVector;
3209
+ }
3210
+ /**
3211
+ * A set of vector {@link VectorizeMatch} for a particular query.
3212
+ */
3213
+ declare interface VectorizeMatches {
3214
+ matches: VectorizeMatch[];
3215
+ count: number;
3216
+ }
3217
+ /**
3218
+ * Results of an operation that performed a mutation on a set of vectors.
3219
+ * Here, `ids` is a list of vectors that were successfully processed.
3220
+ */
3221
+ declare interface VectorizeVectorMutation {
3222
+ /* List of ids of vectors that were successfully processed. */
3223
+ ids: string[];
3224
+ /* Total count of the number of processed vectors. */
3225
+ count: number;
3226
+ }
3227
+ declare abstract class VectorizeIndex {
3228
+ /**
3229
+ * Get information about the currently bound index.
3230
+ * @returns A promise that resolves with information about the current index.
3231
+ */
3232
+ public describe(): Promise<VectorizeIndexDetails>;
3233
+ /**
3234
+ * Use the provided vector to perform a similarity search across the index.
3235
+ * @param vector Input vector that will be used to drive the similarity search.
3236
+ * @param options Configuration options to massage the returned data.
3237
+ * @returns A promise that resolves with matched and scored vectors.
3238
+ */
3239
+ public query(
3240
+ vector: VectorFloatArray | number[],
3241
+ options: VectorizeQueryOptions
3242
+ ): Promise<VectorizeMatches>;
3243
+ /**
3244
+ * Insert a list of vectors into the index dataset. If a provided id exists, an error will be thrown.
3245
+ * @param vectors List of vectors that will be inserted.
3246
+ * @returns A promise that resolves with the ids & count of records that were successfully processed.
3247
+ */
3248
+ public insert(vectors: VectorizeVector[]): Promise<VectorizeVectorMutation>;
3249
+ /**
3250
+ * Upsert a list of vectors into the index dataset. If a provided id exists, it will be replaced with the new values.
3251
+ * @param vectors List of vectors that will be upserted.
3252
+ * @returns A promise that resolves with the ids & count of records that were successfully processed.
3253
+ */
3254
+ public upsert(vectors: VectorizeVector[]): Promise<VectorizeVectorMutation>;
3255
+ /**
3256
+ * Delete a list of vectors with a matching id.
3257
+ * @param ids List of vector ids that should be deleted.
3258
+ * @returns A promise that resolves with the ids & count of records that were successfully processed (and thus deleted).
3259
+ */
3260
+ public deleteByIds(ids: string[]): Promise<VectorizeVectorMutation>;
3261
+ /**
3262
+ * Get a list of vectors with a matching id.
3263
+ * @param ids List of vector ids that should be returned.
3264
+ * @returns A promise that resolves with the raw unscored vectors matching the id set.
3265
+ */
3266
+ public getByIds(ids: string[]): Promise<VectorizeVector[]>;
3267
+ }
3097
3268
  declare interface DynamicDispatchLimits {
3098
3269
  /**
3099
3270
  * Limit CPU time in milliseconds.
@@ -880,7 +880,7 @@ export declare class TextDecoder {
880
880
  }
881
881
  export declare class TextEncoder {
882
882
  constructor();
883
- encode(input?: string): ArrayBuffer | ArrayBufferView;
883
+ encode(input?: string): Uint8Array;
884
884
  encodeInto(
885
885
  input: string,
886
886
  buffer: ArrayBuffer | ArrayBufferView
@@ -2905,9 +2905,6 @@ export type ContinentCode = "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA";
2905
2905
  export type CfProperties<HostMetadata = unknown> =
2906
2906
  | IncomingRequestCfProperties<HostMetadata>
2907
2907
  | RequestInitCfProperties;
2908
- // Copyright (c) 2022-2023 Cloudflare, Inc.
2909
- // Licensed under the Apache 2.0 license found in the LICENSE file or at:
2910
- // https://opensource.org/licenses/Apache-2.0
2911
2908
  export interface D1Result<T = unknown> {
2912
2909
  results: T[];
2913
2910
  success: true;
@@ -2932,9 +2929,6 @@ export declare abstract class D1PreparedStatement {
2932
2929
  all<T = Record<string, unknown>>(): Promise<D1Result<T>>;
2933
2930
  raw<T = unknown[]>(): Promise<T[]>;
2934
2931
  }
2935
- // Copyright (c) 2023 Cloudflare, Inc.
2936
- // Licensed under the Apache 2.0 license found in the LICENSE file or at:
2937
- // https://opensource.org/licenses/Apache-2.0
2938
2932
  /**
2939
2933
  * An email message that can be sent from a Worker.
2940
2934
  */
@@ -2992,9 +2986,53 @@ export type EmailExportedHandler<Env = unknown> = (
2992
2986
  env: Env,
2993
2987
  ctx: ExecutionContext
2994
2988
  ) => void | Promise<void>;
2995
- // Copyright (c) 2022-2023 Cloudflare, Inc.
2996
- // Licensed under the Apache 2.0 license found in the LICENSE file or at:
2997
- // https://opensource.org/licenses/Apache-2.0
2989
+ export interface Hyperdrive {
2990
+ /**
2991
+ * Connect directly to Hyperdrive as if it's your database, returning a TCP socket.
2992
+ *
2993
+ * Calling this method returns an idential socket to if you call
2994
+ * `connect("host:port")` using the `host` and `port` fields from this object.
2995
+ * Pick whichever approach works better with your preferred DB client library.
2996
+ *
2997
+ * Note that this socket is not yet authenticated -- it's expected that your
2998
+ * code (or preferably, the client library of your choice) will authenticate
2999
+ * using the information in this class's readonly fields.
3000
+ */
3001
+ connect(): Socket;
3002
+ /**
3003
+ * A valid DB connection string that can be passed straight into the typical
3004
+ * client library/driver/ORM. This will typically be the easiest way to use
3005
+ * Hyperdrive.
3006
+ */
3007
+ readonly connectionString: string;
3008
+ /*
3009
+ * A randomly generated hostname that is only valid within the context of the
3010
+ * currently running Worker which, when passed into `connect()` function from
3011
+ * the "cloudflare:sockets" module, will connect to the Hyperdrive instance
3012
+ * for your database.
3013
+ */
3014
+ readonly host: string;
3015
+ /*
3016
+ * The port that must be paired the the host field when connecting.
3017
+ */
3018
+ readonly port: string;
3019
+ /*
3020
+ * The username to use when authenticating to your database via Hyperdrive.
3021
+ * Unlike the host and password, this will be the same every time
3022
+ */
3023
+ readonly user: string;
3024
+ /*
3025
+ * The randomly generated password to use when authenticating to your
3026
+ * database via Hyperdrive. Like the host field, this password is only valid
3027
+ * within the context of the currently running Worker instance from which
3028
+ * it's read.
3029
+ */
3030
+ readonly password: string;
3031
+ /*
3032
+ * The name of the database to connect to.
3033
+ */
3034
+ readonly database: string;
3035
+ }
2998
3036
  export type Params<P extends string = any> = Record<P, string | string[]>;
2999
3037
  export type EventContext<Env, P extends string, Data> = {
3000
3038
  request: Request;
@@ -3038,13 +3076,10 @@ export type PagesPluginFunction<
3038
3076
  > = (
3039
3077
  context: EventPluginContext<Env, Params, Data, PluginArgs>
3040
3078
  ) => Response | Promise<Response>;
3041
- // Copyright (c) 2023 Cloudflare, Inc.
3042
- // Licensed under the Apache 2.0 license found in the LICENSE file or at:
3043
- // https://opensource.org/licenses/Apache-2.0
3044
- // https://developers.cloudflare.com/pub-sub/
3045
3079
  // PubSubMessage represents an incoming PubSub message.
3046
3080
  // The message includes metadata about the broker, the client, and the payload
3047
3081
  // itself.
3082
+ // https://developers.cloudflare.com/pub-sub/
3048
3083
  export interface PubSubMessage {
3049
3084
  // Message ID
3050
3085
  readonly mid: number;
@@ -3075,10 +3110,149 @@ export interface JsonWebKeyWithKid extends JsonWebKey {
3075
3110
  // Key Identifier of the JWK
3076
3111
  readonly kid: string;
3077
3112
  }
3078
- // Copyright (c) 2023 Cloudflare, Inc.
3113
+ // Copyright (c) 2022-2023 Cloudflare, Inc.
3079
3114
  // Licensed under the Apache 2.0 license found in the LICENSE file or at:
3080
3115
  // https://opensource.org/licenses/Apache-2.0
3081
- // https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/
3116
+ /**
3117
+ * Additional information to associate with a vector.
3118
+ */
3119
+ export type VectorizeVectorMetadata =
3120
+ | string
3121
+ | number
3122
+ | boolean
3123
+ | string[]
3124
+ | Record<string, string | number | boolean | string[]>;
3125
+ export type VectorFloatArray = Float32Array | Float64Array;
3126
+ export interface VectorizeError {
3127
+ code?: number;
3128
+ error: string;
3129
+ }
3130
+ /**
3131
+ * A pre-configured list of known models.
3132
+ * These can be supplied in place of configuring explicit dimensions.
3133
+ */
3134
+ export type VectorizePreset =
3135
+ | "openapi-text-embedding-ada-002"
3136
+ | "workers-ai/bge-small-en"
3137
+ | "cohere/embed-multilingual-v2.0";
3138
+ /**
3139
+ * Supported distance metrics for an index.
3140
+ * Distance metrics determine how other "similar" vectors are determined.
3141
+ */
3142
+ export type VectorizeDistanceMetric = "euclidean" | "cosine" | "dot-product";
3143
+ export interface VectorizeQueryOptions {
3144
+ topK?: number;
3145
+ namespace?: string;
3146
+ returnVectors?: boolean;
3147
+ }
3148
+ /**
3149
+ * Information about the configuration of an index.
3150
+ */
3151
+ export type VectorizeIndexConfig =
3152
+ | {
3153
+ dimensions: number;
3154
+ metric: VectorizeDistanceMetric;
3155
+ }
3156
+ | {
3157
+ preset: VectorizePreset;
3158
+ };
3159
+ /**
3160
+ * Metadata about an existing index.
3161
+ */
3162
+ export interface VectorizeIndexDetails {
3163
+ /** The unique ID of the index */
3164
+ readonly id: string;
3165
+ /** The name of the index. */
3166
+ name: string;
3167
+ /** (optional) A human readable description for the index. */
3168
+ description?: string;
3169
+ /** The index configuration, including the dimension size and distance metric. */
3170
+ config: VectorizeIndexConfig;
3171
+ /** The number of records containing vectors within the index. */
3172
+ vectorsCount: number;
3173
+ }
3174
+ /**
3175
+ * Represents a single vector value set along with its associated metadata.
3176
+ */
3177
+ export interface VectorizeVector {
3178
+ /** The ID for the vector. This can be user-defined, and must be unique. It should uniquely identify the object, and is best set based on the ID of what the vector represents. */
3179
+ id: string;
3180
+ /** The vector values */
3181
+ values: VectorFloatArray | number[];
3182
+ /** The namespace this vector belongs to. */
3183
+ namespace?: string;
3184
+ /** Metadata associated with the binding. Includes the values of the other fields and potentially additional details. */
3185
+ metadata?: Record<string, VectorizeVectorMetadata>;
3186
+ }
3187
+ /**
3188
+ * Represents a matched vector for a query along with its score and (if specified) the matching vector information.
3189
+ */
3190
+ export interface VectorizeMatch {
3191
+ /** The ID for the vector. This can be user-defined, and must be unique. It should uniquely identify the object, and is best set based on the ID of what the vector represents. */
3192
+ vectorId: string;
3193
+ /** The score or rank for similarity, when returned as a result */
3194
+ score: number;
3195
+ /** Vector data for the match. Included only if the user specified they want it returned (via {@link VectorizeQueryOptions}). */
3196
+ vector?: VectorizeVector;
3197
+ }
3198
+ /**
3199
+ * A set of vector {@link VectorizeMatch} for a particular query.
3200
+ */
3201
+ export interface VectorizeMatches {
3202
+ matches: VectorizeMatch[];
3203
+ count: number;
3204
+ }
3205
+ /**
3206
+ * Results of an operation that performed a mutation on a set of vectors.
3207
+ * Here, `ids` is a list of vectors that were successfully processed.
3208
+ */
3209
+ export interface VectorizeVectorMutation {
3210
+ /* List of ids of vectors that were successfully processed. */
3211
+ ids: string[];
3212
+ /* Total count of the number of processed vectors. */
3213
+ count: number;
3214
+ }
3215
+ export declare abstract class VectorizeIndex {
3216
+ /**
3217
+ * Get information about the currently bound index.
3218
+ * @returns A promise that resolves with information about the current index.
3219
+ */
3220
+ public describe(): Promise<VectorizeIndexDetails>;
3221
+ /**
3222
+ * Use the provided vector to perform a similarity search across the index.
3223
+ * @param vector Input vector that will be used to drive the similarity search.
3224
+ * @param options Configuration options to massage the returned data.
3225
+ * @returns A promise that resolves with matched and scored vectors.
3226
+ */
3227
+ public query(
3228
+ vector: VectorFloatArray | number[],
3229
+ options: VectorizeQueryOptions
3230
+ ): Promise<VectorizeMatches>;
3231
+ /**
3232
+ * Insert a list of vectors into the index dataset. If a provided id exists, an error will be thrown.
3233
+ * @param vectors List of vectors that will be inserted.
3234
+ * @returns A promise that resolves with the ids & count of records that were successfully processed.
3235
+ */
3236
+ public insert(vectors: VectorizeVector[]): Promise<VectorizeVectorMutation>;
3237
+ /**
3238
+ * Upsert a list of vectors into the index dataset. If a provided id exists, it will be replaced with the new values.
3239
+ * @param vectors List of vectors that will be upserted.
3240
+ * @returns A promise that resolves with the ids & count of records that were successfully processed.
3241
+ */
3242
+ public upsert(vectors: VectorizeVector[]): Promise<VectorizeVectorMutation>;
3243
+ /**
3244
+ * Delete a list of vectors with a matching id.
3245
+ * @param ids List of vector ids that should be deleted.
3246
+ * @returns A promise that resolves with the ids & count of records that were successfully processed (and thus deleted).
3247
+ */
3248
+ public deleteByIds(ids: string[]): Promise<VectorizeVectorMutation>;
3249
+ /**
3250
+ * Get a list of vectors with a matching id.
3251
+ * @param ids List of vector ids that should be returned.
3252
+ * @returns A promise that resolves with the raw unscored vectors matching the id set.
3253
+ */
3254
+ public getByIds(ids: string[]): Promise<VectorizeVector[]>;
3255
+ }
3082
3256
  export interface DynamicDispatchLimits {
3083
3257
  /**
3084
3258
  * Limit CPU time in milliseconds.