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