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