@vectorstores/azure 0.1.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.
@@ -0,0 +1,458 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ var core = require('@vectorstores/core');
4
+ var mongodb = require('mongodb');
5
+ var cosmos = require('@azure/cosmos');
6
+ var identity = require('@azure/identity');
7
+ var env = require('@vectorstores/env');
8
+
9
+ var version = "0.1.0";
10
+ var pkg = {
11
+ version: version};
12
+
13
+ const DEFAULT_CHAT_DATABASE$1 = "KVStoreDB";
14
+ const DEFAULT_CHAT_Collection = "KVStoreCollection";
15
+ class AzureCosmosVCoreKVStore extends core.BaseKVStore {
16
+ /**
17
+ * Create a new AzureCosmosDBNoSQLVectorStore instance.
18
+ */ constructor({ mongoClient, dbName = DEFAULT_CHAT_DATABASE$1, collectionName = DEFAULT_CHAT_Collection }){
19
+ super();
20
+ if (!mongoClient) {
21
+ throw new Error("MongoClient is required for AzureCosmosDBNoSQLVectorStore initialization");
22
+ }
23
+ mongoClient.appendMetadata({
24
+ name: "VECTORSTORES_AZURE_COSMOS_VCORE_KV_STORE",
25
+ version: pkg.version
26
+ });
27
+ this.mongoClient = mongoClient;
28
+ this.dbName = dbName;
29
+ this.collectionName = collectionName;
30
+ }
31
+ client() {
32
+ return this.mongoClient;
33
+ }
34
+ async ensureCollection() {
35
+ if (!this.collection) {
36
+ this.collection = this.mongoClient.db(this.dbName).collection(this.collectionName);
37
+ }
38
+ return this.collection;
39
+ }
40
+ async put(key, val) {
41
+ const collection = await this.ensureCollection();
42
+ await collection.insertOne({
43
+ id: key,
44
+ messages: val
45
+ });
46
+ }
47
+ async get(key) {
48
+ const collection = await this.ensureCollection();
49
+ const result = await collection.findOne({
50
+ id: key
51
+ });
52
+ return result || null;
53
+ }
54
+ async getAll() {
55
+ const collection = await this.ensureCollection();
56
+ const cursor = collection.find();
57
+ const output = {};
58
+ await cursor.forEach((item)=>{
59
+ output[item.id] = item.messages;
60
+ });
61
+ return output;
62
+ }
63
+ async delete(key) {
64
+ const collection = await this.ensureCollection();
65
+ await collection.deleteOne({
66
+ id: key
67
+ });
68
+ return true;
69
+ }
70
+ }
71
+
72
+ const DEFAULT_DATABASE$3 = "DocumentStoreDB";
73
+ const DEFAULT_COLLECTION$1 = "DocumentStoreCollection";
74
+ class AzureCosmosVCoreDocumentStore extends core.KVDocumentStore {
75
+ constructor({ azureCosmosVCoreKVStore, namespace }){
76
+ super(azureCosmosVCoreKVStore, namespace);
77
+ }
78
+ /**
79
+ * Static method for creating an instance using a MongoClient.
80
+ * @returns Instance of AzureCosmosVCoreDocumentStore
81
+ * @param mongoClient - MongoClient instance
82
+ * @param dbName - Database name
83
+ * @param collectionName - Collection name
84
+ * @example
85
+ * ```ts
86
+ * const mongoClient = new MongoClient("mongodb://localhost:27017");
87
+ * const indexStore = AzureCosmosVCoreDocumentStore.fromMongoClient(mongoClient, "my_db", "my_collection");
88
+ * ```
89
+ */ static fromMongoClient(mongoClient, dbName = DEFAULT_DATABASE$3, collectionName = DEFAULT_COLLECTION$1) {
90
+ const azureCosmosVCoreKVStore = new AzureCosmosVCoreKVStore({
91
+ mongoClient,
92
+ dbName,
93
+ collectionName
94
+ });
95
+ const namespace = `${dbName}.${collectionName}`;
96
+ return new AzureCosmosVCoreDocumentStore({
97
+ azureCosmosVCoreKVStore,
98
+ namespace
99
+ });
100
+ }
101
+ /**
102
+ * Static method for creating an instance using a connection string.
103
+ * @returns Instance of AzureCosmosVCoreDocumentStore
104
+ * @param connectionString - MongoDB connection string
105
+ * @param dbName - Database name
106
+ * @param collectionName - Collection name
107
+ * @example
108
+ * ```ts
109
+ * const indexStore = AzureCosmosVCoreDocumentStore.fromConnectionString("mongodb://localhost:27017", "my_db", "my_collection");
110
+ * ```
111
+ */ static fromConnectionString(connectionString, dbName = DEFAULT_DATABASE$3, collectionName = DEFAULT_COLLECTION$1) {
112
+ const mongoClient = new mongodb.MongoClient(connectionString, {
113
+ appName: "VECTORSTORES_JS"
114
+ });
115
+ return new AzureCosmosVCoreDocumentStore({
116
+ azureCosmosVCoreKVStore: new AzureCosmosVCoreKVStore({
117
+ mongoClient,
118
+ dbName,
119
+ collectionName
120
+ }),
121
+ namespace: `${dbName}.${collectionName}`
122
+ });
123
+ }
124
+ }
125
+
126
+ const USER_AGENT_SUFFIX = "vectorstores-cdbnosql-kvstore-javascript";
127
+ const DEFAULT_CHAT_DATABASE = "KVStoreDB";
128
+ const DEFAULT_CHAT_CONTAINER = "KVStoreContainer";
129
+ const DEFAULT_OFFER_THROUGHPUT = 400;
130
+ function parseConnectionString(connectionString) {
131
+ const parts = connectionString.split(";");
132
+ let endpoint = "";
133
+ let accountKey = "";
134
+ parts.forEach((part)=>{
135
+ const [key, value] = part.split("=");
136
+ if (key && key.trim() === "AccountEndpoint") {
137
+ endpoint = value?.trim() ?? "";
138
+ } else if ((key ?? "").trim() === "AccountKey") {
139
+ accountKey = value?.trim() ?? "";
140
+ }
141
+ });
142
+ if (!endpoint || !accountKey) {
143
+ throw new Error("Invalid connection string: missing AccountEndpoint or AccountKey.");
144
+ }
145
+ return {
146
+ endpoint,
147
+ key: accountKey
148
+ };
149
+ }
150
+ class AzureCosmosNoSqlKVStore extends core.BaseKVStore {
151
+ constructor({ cosmosClient, dbName = DEFAULT_CHAT_DATABASE, containerName = DEFAULT_CHAT_CONTAINER, cosmosContainerProperties = {
152
+ partitionKey: "/id"
153
+ }, cosmosDatabaseProperties = {} }){
154
+ super();
155
+ if (!cosmosClient) {
156
+ throw new Error("CosmosClient is required for AzureCosmosDBNoSQLKVStore initialization");
157
+ }
158
+ this.cosmosClient = cosmosClient;
159
+ this.dbName = dbName;
160
+ this.containerName = containerName;
161
+ this.cosmosContainerProperties = cosmosContainerProperties;
162
+ this.cosmosDatabaseProperties = cosmosDatabaseProperties;
163
+ this.initialize = ()=>{
164
+ if (this.initPromise === undefined) {
165
+ this.initPromise = this.init().catch((error)=>{
166
+ console.error("Error during AzureCosmosDBNoSQLKVStore initialization", error);
167
+ });
168
+ }
169
+ return this.initPromise;
170
+ };
171
+ }
172
+ client() {
173
+ return this.cosmosClient;
174
+ }
175
+ // Asynchronous initialization method to create database and container
176
+ async init() {
177
+ // Set default throughput if not provided
178
+ const throughput = this.cosmosDatabaseProperties?.throughput || DEFAULT_OFFER_THROUGHPUT;
179
+ // Create the database if it doesn't exist
180
+ const { database } = await this.cosmosClient.databases.createIfNotExists({
181
+ id: this.dbName,
182
+ throughput
183
+ });
184
+ this.database = database;
185
+ // Create the container if it doesn't exist
186
+ const { container } = await this.database.containers.createIfNotExists({
187
+ id: this.containerName,
188
+ throughput: this.cosmosContainerProperties?.throughput,
189
+ partitionKey: this.cosmosContainerProperties?.partitionKey,
190
+ indexingPolicy: this.cosmosContainerProperties?.indexingPolicy,
191
+ defaultTtl: this.cosmosContainerProperties?.defaultTtl,
192
+ uniqueKeyPolicy: this.cosmosContainerProperties?.uniqueKeyPolicy,
193
+ conflictResolutionPolicy: this.cosmosContainerProperties?.conflictResolutionPolicy,
194
+ computedProperties: this.cosmosContainerProperties?.computedProperties
195
+ });
196
+ this.container = container;
197
+ }
198
+ /**
199
+ * Static method for creating an instance using a connection string.
200
+ * If no connection string is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_CONNECTION_STRING` as connection string.
201
+ * @returns Instance of AzureCosmosNoSqlKVStore
202
+ */ static fromConnectionString(config = {}) {
203
+ const cosmosConnectionString = config.connectionString || env.getEnv("AZURE_COSMOSDB_NOSQL_CONNECTION_STRING");
204
+ if (!cosmosConnectionString) {
205
+ throw new Error("Azure CosmosDB connection string must be provided");
206
+ }
207
+ const { endpoint, key } = parseConnectionString(cosmosConnectionString);
208
+ const cosmosClient = new cosmos.CosmosClient({
209
+ endpoint,
210
+ key,
211
+ userAgentSuffix: USER_AGENT_SUFFIX
212
+ });
213
+ return new AzureCosmosNoSqlKVStore({
214
+ ...config,
215
+ cosmosClient
216
+ });
217
+ }
218
+ /**
219
+ * Static method for creating an instance using a account endpoint and key.
220
+ * If no endpoint and key is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as enpoint and `AZURE_COSMOSDB_NOSQL_ACCOUNT_KEY` as key.
221
+ * @returns Instance of AzureCosmosNoSqlKVStore
222
+ */ static fromAccountAndKey(config = {}) {
223
+ const cosmosEndpoint = config.endpoint || env.getEnv("AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT");
224
+ const cosmosKey = config.key || env.getEnv("AZURE_COSMOSDB_NOSQL_ACCOUNT_KEY");
225
+ if (!cosmosEndpoint || !cosmosKey) {
226
+ throw new Error("Azure CosmosDB account endpoint and key must be provided");
227
+ }
228
+ const cosmosClient = new cosmos.CosmosClient({
229
+ endpoint: cosmosEndpoint,
230
+ key: cosmosKey,
231
+ userAgentSuffix: USER_AGENT_SUFFIX
232
+ });
233
+ return new AzureCosmosNoSqlKVStore({
234
+ ...config,
235
+ cosmosClient
236
+ });
237
+ }
238
+ /**
239
+ * Static method for creating an instance using AAD token.
240
+ * If no endpoint and credentials are provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as endpoint and use DefaultAzureCredential() as credentials.
241
+ * @returns Instance of AzureCosmosNoSqlKVStore
242
+ */ static fromAadToken(config = {}) {
243
+ const cosmosEndpoint = config.endpoint || env.getEnv("AZURE_COSMOSDB_NOSQL_CONNECTION_STRING");
244
+ if (!cosmosEndpoint) {
245
+ throw new Error("Azure CosmosDB account endpoint must be provided");
246
+ }
247
+ const credentials = config.credential ?? new identity.DefaultAzureCredential();
248
+ const cosmosClient = new cosmos.CosmosClient({
249
+ endpoint: cosmosEndpoint,
250
+ aadCredentials: credentials,
251
+ userAgentSuffix: USER_AGENT_SUFFIX
252
+ });
253
+ return new AzureCosmosNoSqlKVStore({
254
+ ...config,
255
+ cosmosClient
256
+ });
257
+ }
258
+ async put(key, val) {
259
+ await this.initialize();
260
+ await this.container.items.upsert({
261
+ id: key,
262
+ messages: val
263
+ });
264
+ }
265
+ async get(key) {
266
+ await this.initialize();
267
+ try {
268
+ const { resource } = await this.container.item(key).read();
269
+ return resource?.messages || null;
270
+ } catch (error) {
271
+ console.error(`Error retrieving item with key ${key}:`, error);
272
+ return null;
273
+ }
274
+ }
275
+ async getAll() {
276
+ await this.initialize();
277
+ const querySpec = {
278
+ query: "SELECT * from c"
279
+ };
280
+ const { resources } = await this.container.items.query(querySpec).fetchAll();
281
+ const output = resources.reduce((res, item)=>{
282
+ res[item.id] = item.messages;
283
+ return res;
284
+ }, {});
285
+ return output;
286
+ }
287
+ async delete(key) {
288
+ await this.initialize();
289
+ try {
290
+ await this.container.item(key).delete();
291
+ return true;
292
+ } catch (error) {
293
+ console.error(`Error deleting item with key ${key}:`, error);
294
+ return false;
295
+ }
296
+ }
297
+ }
298
+
299
+ const DEFAULT_DATABASE$2 = "DocumentStoreDB";
300
+ const DEFAULT_CONTAINER$1 = "DocumentStoreContainer";
301
+ class AzureCosmosNoSqlDocumentStore extends core.KVDocumentStore {
302
+ constructor({ azureCosmosNoSqlKVStore, namespace }){
303
+ super(azureCosmosNoSqlKVStore, namespace);
304
+ }
305
+ /**
306
+ * Static method for creating an instance using a connection string.
307
+ * If no connection string is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_CONNECTION_STRING` as connection string.
308
+ * @returns Instance of AzureCosmosNoSqlDocumentStore
309
+ */ static fromConnectionString(options = {}) {
310
+ options.dbName = options.dbName || DEFAULT_DATABASE$2;
311
+ options.containerName = options.containerName || DEFAULT_CONTAINER$1;
312
+ const azureCosmosNoSqlKVStore = AzureCosmosNoSqlKVStore.fromConnectionString(options);
313
+ const namespace = `${options.dbName}.${options.containerName}`;
314
+ return new AzureCosmosNoSqlDocumentStore({
315
+ azureCosmosNoSqlKVStore,
316
+ namespace
317
+ });
318
+ }
319
+ /**
320
+ * Static method for creating an instance using a account endpoint and key.
321
+ * If no endpoint and key is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as enpoint and `AZURE_COSMOSDB_NOSQL_ACCOUNT_KEY` as key.
322
+ * @returns Instance of AzureCosmosNoSqlDocumentStore
323
+ */ static fromAccountAndKey(options = {}) {
324
+ options.dbName = options.dbName || DEFAULT_DATABASE$2;
325
+ options.containerName = options.containerName || DEFAULT_CONTAINER$1;
326
+ const azureCosmosNoSqlKVStore = AzureCosmosNoSqlKVStore.fromAccountAndKey(options);
327
+ const namespace = `${options.dbName}.${options.containerName}`;
328
+ return new AzureCosmosNoSqlDocumentStore({
329
+ azureCosmosNoSqlKVStore,
330
+ namespace
331
+ });
332
+ }
333
+ /**
334
+ * Static method for creating an instance using AAD token.
335
+ * If no endpoint and credentials are provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as endpoint and use DefaultAzureCredential() as credentials.
336
+ * @returns Instance of AzureCosmosNoSqlDocumentStore
337
+ */ static fromAadToken(options = {}) {
338
+ options.dbName = options.dbName || DEFAULT_DATABASE$2;
339
+ options.containerName = options.containerName || DEFAULT_CONTAINER$1;
340
+ const azureCosmosNoSqlKVStore = AzureCosmosNoSqlKVStore.fromAadToken(options);
341
+ const namespace = `${options.dbName}.${options.containerName}`;
342
+ return new AzureCosmosNoSqlDocumentStore({
343
+ azureCosmosNoSqlKVStore,
344
+ namespace
345
+ });
346
+ }
347
+ }
348
+
349
+ const DEFAULT_DATABASE$1 = "IndexStoreDB";
350
+ const DEFAULT_COLLECTION = "IndexStoreCollection";
351
+ class AzureCosmosVCoreIndexStore extends core.KVIndexStore {
352
+ constructor({ azureCosmosVCoreKVStore, namespace }){
353
+ super(azureCosmosVCoreKVStore, namespace);
354
+ }
355
+ /**
356
+ * Static method for creating an instance using a MongoClient.
357
+ * @returns Instance of AzureCosmosVCoreIndexStore
358
+ * @param mongoClient - MongoClient instance
359
+ * @param dbName - Database name
360
+ * @param collectionName - Collection name
361
+ * @example
362
+ * ```ts
363
+ * const mongoClient = new MongoClient("mongodb://localhost:27017");
364
+ * const indexStore = AzureCosmosVCoreIndexStore.fromMongoClient(mongoClient, "my_db", "my_collection");
365
+ * ```
366
+ */ static fromMongoClient(mongoClient, dbName = DEFAULT_DATABASE$1, collectionName = DEFAULT_COLLECTION) {
367
+ const azureCosmosVCoreKVStore = new AzureCosmosVCoreKVStore({
368
+ mongoClient,
369
+ dbName,
370
+ collectionName
371
+ });
372
+ const namespace = `${dbName}.${collectionName}`;
373
+ return new AzureCosmosVCoreIndexStore({
374
+ azureCosmosVCoreKVStore,
375
+ namespace
376
+ });
377
+ }
378
+ /**
379
+ * Static method for creating an instance using a connection string.
380
+ * @returns Instance of AzureCosmosVCoreIndexStore
381
+ * @param connectionString - MongoDB connection string
382
+ * @param dbName - Database name
383
+ * @param collectionName - Collection name
384
+ * @example
385
+ * ```ts
386
+ * const indexStore = AzureCosmosVCoreIndexStore.fromConnectionString("mongodb://localhost:27017", "my_db", "my_collection");
387
+ * ```
388
+ */ static fromConnectionString(connectionString, dbName = DEFAULT_DATABASE$1, collectionName = DEFAULT_COLLECTION) {
389
+ const mongoClient = new mongodb.MongoClient(connectionString, {
390
+ appName: "VECTORSTORES_JS"
391
+ });
392
+ return new AzureCosmosVCoreIndexStore({
393
+ azureCosmosVCoreKVStore: new AzureCosmosVCoreKVStore({
394
+ mongoClient,
395
+ dbName,
396
+ collectionName
397
+ }),
398
+ namespace: `${dbName}.${collectionName}`
399
+ });
400
+ }
401
+ }
402
+
403
+ const DEFAULT_DATABASE = "IndexStoreDB";
404
+ const DEFAULT_CONTAINER = "IndexStoreContainer";
405
+ class AzureCosmosNoSqlIndexStore extends core.KVIndexStore {
406
+ constructor({ azureCosmosNoSqlKVStore, namespace }){
407
+ super(azureCosmosNoSqlKVStore, namespace);
408
+ }
409
+ /**
410
+ * Static method for creating an instance using a connection string.
411
+ * If no connection string is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_CONNECTION_STRING` as connection string.
412
+ * @returns Instance of AzureCosmosNoSqlIndexStore
413
+ */ static fromConnectionString(options = {}) {
414
+ options.dbName = options.dbName || DEFAULT_DATABASE;
415
+ options.containerName = options.containerName || DEFAULT_CONTAINER;
416
+ const azureCosmosNoSqlKVStore = AzureCosmosNoSqlKVStore.fromConnectionString(options);
417
+ const namespace = `${options.dbName}.${options.containerName}`;
418
+ return new AzureCosmosNoSqlIndexStore({
419
+ azureCosmosNoSqlKVStore,
420
+ namespace
421
+ });
422
+ }
423
+ /**
424
+ * Static method for creating an instance using a account endpoint and key.
425
+ * If no endpoint and key is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as enpoint and `AZURE_COSMOSDB_NOSQL_ACCOUNT_KEY` as key.
426
+ * @returns Instance of AzureCosmosNoSqlIndexStore
427
+ */ static fromAccountAndKey(options = {}) {
428
+ options.dbName = options.dbName || DEFAULT_DATABASE;
429
+ options.containerName = options.containerName || DEFAULT_CONTAINER;
430
+ const azureCosmosNoSqlKVStore = AzureCosmosNoSqlKVStore.fromAccountAndKey(options);
431
+ const namespace = `${options.dbName}.${options.containerName}`;
432
+ return new AzureCosmosNoSqlIndexStore({
433
+ azureCosmosNoSqlKVStore,
434
+ namespace
435
+ });
436
+ }
437
+ /**
438
+ * Static method for creating an instance using AAD token.
439
+ * If no endpoint and credentials are provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as endpoint and use DefaultAzureCredential() as credentials.
440
+ * @returns Instance of AzureCosmosNoSqlIndexStore
441
+ */ static fromAadToken(options = {}) {
442
+ options.dbName = options.dbName || DEFAULT_DATABASE;
443
+ options.containerName = options.containerName || DEFAULT_CONTAINER;
444
+ const azureCosmosNoSqlKVStore = AzureCosmosNoSqlKVStore.fromAadToken(options);
445
+ const namespace = `${options.dbName}.${options.containerName}`;
446
+ return new AzureCosmosNoSqlIndexStore({
447
+ azureCosmosNoSqlKVStore,
448
+ namespace
449
+ });
450
+ }
451
+ }
452
+
453
+ exports.AzureCosmosNoSqlDocumentStore = AzureCosmosNoSqlDocumentStore;
454
+ exports.AzureCosmosNoSqlIndexStore = AzureCosmosNoSqlIndexStore;
455
+ exports.AzureCosmosNoSqlKVStore = AzureCosmosNoSqlKVStore;
456
+ exports.AzureCosmosVCoreDocumentStore = AzureCosmosVCoreDocumentStore;
457
+ exports.AzureCosmosVCoreIndexStore = AzureCosmosVCoreIndexStore;
458
+ exports.AzureCosmosVCoreKVStore = AzureCosmosVCoreKVStore;
@@ -0,0 +1,220 @@
1
+ import { BaseKVStore, KVDocumentStore, KVIndexStore } from '@vectorstores/core';
2
+ import { MongoClient } from 'mongodb';
3
+ import { CosmosClient } from '@azure/cosmos';
4
+ import { TokenCredential } from '@azure/identity';
5
+
6
+ interface VcoreConnectionStringOptions extends AzureCosmosVCoreKVStoreConfig {
7
+ connectionString?: string;
8
+ }
9
+ interface AzureCosmosVCoreKVStoreConfig {
10
+ mongoClient?: MongoClient;
11
+ dbName?: string;
12
+ collectionName?: string;
13
+ }
14
+ declare class AzureCosmosVCoreKVStore extends BaseKVStore {
15
+ private mongoClient;
16
+ private dbName;
17
+ private collectionName;
18
+ private collection?;
19
+ /**
20
+ * Create a new AzureCosmosDBNoSQLVectorStore instance.
21
+ */
22
+ constructor({ mongoClient, dbName, collectionName, }: AzureCosmosVCoreKVStoreConfig);
23
+ client(): MongoClient;
24
+ private ensureCollection;
25
+ put(key: string, val: Record<string, any>): Promise<void>;
26
+ get(key: string): Promise<Record<string, any> | null>;
27
+ getAll(): Promise<Record<string, Record<string, any>>>;
28
+ delete(key: string): Promise<boolean>;
29
+ }
30
+
31
+ interface AzureCosmosVCoreDocumentStoreArgs {
32
+ azureCosmosVCoreKVStore: AzureCosmosVCoreKVStore;
33
+ namespace?: string;
34
+ }
35
+ declare class AzureCosmosVCoreDocumentStore extends KVDocumentStore {
36
+ constructor({ azureCosmosVCoreKVStore, namespace, }: AzureCosmosVCoreDocumentStoreArgs);
37
+ /**
38
+ * Static method for creating an instance using a MongoClient.
39
+ * @returns Instance of AzureCosmosVCoreDocumentStore
40
+ * @param mongoClient - MongoClient instance
41
+ * @param dbName - Database name
42
+ * @param collectionName - Collection name
43
+ * @example
44
+ * ```ts
45
+ * const mongoClient = new MongoClient("mongodb://localhost:27017");
46
+ * const indexStore = AzureCosmosVCoreDocumentStore.fromMongoClient(mongoClient, "my_db", "my_collection");
47
+ * ```
48
+ */
49
+ static fromMongoClient(mongoClient: MongoClient, dbName?: string, collectionName?: string): AzureCosmosVCoreDocumentStore;
50
+ /**
51
+ * Static method for creating an instance using a connection string.
52
+ * @returns Instance of AzureCosmosVCoreDocumentStore
53
+ * @param connectionString - MongoDB connection string
54
+ * @param dbName - Database name
55
+ * @param collectionName - Collection name
56
+ * @example
57
+ * ```ts
58
+ * const indexStore = AzureCosmosVCoreDocumentStore.fromConnectionString("mongodb://localhost:27017", "my_db", "my_collection");
59
+ * ```
60
+ */
61
+ static fromConnectionString(connectionString: string, dbName?: string, collectionName?: string): AzureCosmosVCoreDocumentStore;
62
+ }
63
+
64
+ interface CosmosDatabaseProperties {
65
+ throughput?: number;
66
+ }
67
+ interface CosmosContainerProperties {
68
+ partitionKey: any;
69
+ [key: string]: any;
70
+ }
71
+ interface ConnectionStringOptions extends AzureCosmosNoSqlKVStoreConfig {
72
+ connectionString?: string;
73
+ }
74
+ interface AccountAndKeyOptions extends AzureCosmosNoSqlKVStoreConfig {
75
+ endpoint?: string;
76
+ key?: string;
77
+ }
78
+ interface AadTokenOptions extends AzureCosmosNoSqlKVStoreConfig {
79
+ endpoint?: string;
80
+ credential?: TokenCredential;
81
+ }
82
+ interface AzureCosmosNoSqlKVStoreConfig {
83
+ cosmosClient?: CosmosClient;
84
+ dbName?: string;
85
+ containerName?: string;
86
+ cosmosContainerProperties?: CosmosContainerProperties;
87
+ cosmosDatabaseProperties?: CosmosDatabaseProperties;
88
+ }
89
+ declare class AzureCosmosNoSqlKVStore extends BaseKVStore {
90
+ private cosmosClient;
91
+ private database;
92
+ private container;
93
+ private initPromise?;
94
+ private dbName;
95
+ private containerName;
96
+ private cosmosContainerProperties;
97
+ private cosmosDatabaseProperties;
98
+ private initialize;
99
+ constructor({ cosmosClient, dbName, containerName, cosmosContainerProperties, cosmosDatabaseProperties, }: AzureCosmosNoSqlKVStoreConfig);
100
+ client(): CosmosClient;
101
+ private init;
102
+ /**
103
+ * Static method for creating an instance using a connection string.
104
+ * If no connection string is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_CONNECTION_STRING` as connection string.
105
+ * @returns Instance of AzureCosmosNoSqlKVStore
106
+ */
107
+ static fromConnectionString(config?: {
108
+ connectionString?: string;
109
+ } & AzureCosmosNoSqlKVStoreConfig): AzureCosmosNoSqlKVStore;
110
+ /**
111
+ * Static method for creating an instance using a account endpoint and key.
112
+ * If no endpoint and key is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as enpoint and `AZURE_COSMOSDB_NOSQL_ACCOUNT_KEY` as key.
113
+ * @returns Instance of AzureCosmosNoSqlKVStore
114
+ */
115
+ static fromAccountAndKey(config?: {
116
+ endpoint?: string;
117
+ key?: string;
118
+ } & AzureCosmosNoSqlKVStoreConfig): AzureCosmosNoSqlKVStore;
119
+ /**
120
+ * Static method for creating an instance using AAD token.
121
+ * If no endpoint and credentials are provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as endpoint and use DefaultAzureCredential() as credentials.
122
+ * @returns Instance of AzureCosmosNoSqlKVStore
123
+ */
124
+ static fromAadToken(config?: {
125
+ endpoint?: string;
126
+ credential?: TokenCredential;
127
+ } & AzureCosmosNoSqlKVStoreConfig): AzureCosmosNoSqlKVStore;
128
+ put(key: string, val: Record<string, any>): Promise<void>;
129
+ get(key: string): Promise<Record<string, any> | null>;
130
+ getAll(): Promise<Record<string, Record<string, any>>>;
131
+ delete(key: string): Promise<boolean>;
132
+ }
133
+
134
+ interface AzureCosmosNoSqlDocumentStoreArgs {
135
+ azureCosmosNoSqlKVStore: AzureCosmosNoSqlKVStore;
136
+ namespace?: string;
137
+ }
138
+ declare class AzureCosmosNoSqlDocumentStore extends KVDocumentStore {
139
+ constructor({ azureCosmosNoSqlKVStore, namespace, }: AzureCosmosNoSqlDocumentStoreArgs);
140
+ /**
141
+ * Static method for creating an instance using a connection string.
142
+ * If no connection string is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_CONNECTION_STRING` as connection string.
143
+ * @returns Instance of AzureCosmosNoSqlDocumentStore
144
+ */
145
+ static fromConnectionString(options?: ConnectionStringOptions): AzureCosmosNoSqlDocumentStore;
146
+ /**
147
+ * Static method for creating an instance using a account endpoint and key.
148
+ * If no endpoint and key is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as enpoint and `AZURE_COSMOSDB_NOSQL_ACCOUNT_KEY` as key.
149
+ * @returns Instance of AzureCosmosNoSqlDocumentStore
150
+ */
151
+ static fromAccountAndKey(options?: AccountAndKeyOptions): AzureCosmosNoSqlDocumentStore;
152
+ /**
153
+ * Static method for creating an instance using AAD token.
154
+ * If no endpoint and credentials are provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as endpoint and use DefaultAzureCredential() as credentials.
155
+ * @returns Instance of AzureCosmosNoSqlDocumentStore
156
+ */
157
+ static fromAadToken(options?: AadTokenOptions): AzureCosmosNoSqlDocumentStore;
158
+ }
159
+
160
+ interface AzureCosmosVCoreIndexStoreArgs {
161
+ azureCosmosVCoreKVStore: AzureCosmosVCoreKVStore;
162
+ namespace?: string;
163
+ }
164
+ declare class AzureCosmosVCoreIndexStore extends KVIndexStore {
165
+ constructor({ azureCosmosVCoreKVStore, namespace, }: AzureCosmosVCoreIndexStoreArgs);
166
+ /**
167
+ * Static method for creating an instance using a MongoClient.
168
+ * @returns Instance of AzureCosmosVCoreIndexStore
169
+ * @param mongoClient - MongoClient instance
170
+ * @param dbName - Database name
171
+ * @param collectionName - Collection name
172
+ * @example
173
+ * ```ts
174
+ * const mongoClient = new MongoClient("mongodb://localhost:27017");
175
+ * const indexStore = AzureCosmosVCoreIndexStore.fromMongoClient(mongoClient, "my_db", "my_collection");
176
+ * ```
177
+ */
178
+ static fromMongoClient(mongoClient: MongoClient, dbName?: string, collectionName?: string): AzureCosmosVCoreIndexStore;
179
+ /**
180
+ * Static method for creating an instance using a connection string.
181
+ * @returns Instance of AzureCosmosVCoreIndexStore
182
+ * @param connectionString - MongoDB connection string
183
+ * @param dbName - Database name
184
+ * @param collectionName - Collection name
185
+ * @example
186
+ * ```ts
187
+ * const indexStore = AzureCosmosVCoreIndexStore.fromConnectionString("mongodb://localhost:27017", "my_db", "my_collection");
188
+ * ```
189
+ */
190
+ static fromConnectionString(connectionString: string, dbName?: string, collectionName?: string): AzureCosmosVCoreIndexStore;
191
+ }
192
+
193
+ interface AzureCosmosNoSqlIndexStoreArgs {
194
+ azureCosmosNoSqlKVStore: AzureCosmosNoSqlKVStore;
195
+ namespace?: string;
196
+ }
197
+ declare class AzureCosmosNoSqlIndexStore extends KVIndexStore {
198
+ constructor({ azureCosmosNoSqlKVStore, namespace, }: AzureCosmosNoSqlIndexStoreArgs);
199
+ /**
200
+ * Static method for creating an instance using a connection string.
201
+ * If no connection string is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_CONNECTION_STRING` as connection string.
202
+ * @returns Instance of AzureCosmosNoSqlIndexStore
203
+ */
204
+ static fromConnectionString(options?: ConnectionStringOptions): AzureCosmosNoSqlIndexStore;
205
+ /**
206
+ * Static method for creating an instance using a account endpoint and key.
207
+ * If no endpoint and key is provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as enpoint and `AZURE_COSMOSDB_NOSQL_ACCOUNT_KEY` as key.
208
+ * @returns Instance of AzureCosmosNoSqlIndexStore
209
+ */
210
+ static fromAccountAndKey(options?: AccountAndKeyOptions): AzureCosmosNoSqlIndexStore;
211
+ /**
212
+ * Static method for creating an instance using AAD token.
213
+ * If no endpoint and credentials are provided, it will attempt to use the env variable `AZURE_COSMOSDB_NOSQL_ACCOUNT_ENDPOINT` as endpoint and use DefaultAzureCredential() as credentials.
214
+ * @returns Instance of AzureCosmosNoSqlIndexStore
215
+ */
216
+ static fromAadToken(options?: AadTokenOptions): AzureCosmosNoSqlIndexStore;
217
+ }
218
+
219
+ export { AzureCosmosNoSqlDocumentStore, AzureCosmosNoSqlIndexStore, AzureCosmosNoSqlKVStore, AzureCosmosVCoreDocumentStore, AzureCosmosVCoreIndexStore, AzureCosmosVCoreKVStore };
220
+ export type { AadTokenOptions, AccountAndKeyOptions, AzureCosmosNoSqlDocumentStoreArgs, AzureCosmosNoSqlIndexStoreArgs, AzureCosmosNoSqlKVStoreConfig, AzureCosmosVCoreDocumentStoreArgs, AzureCosmosVCoreIndexStoreArgs, AzureCosmosVCoreKVStoreConfig, ConnectionStringOptions, CosmosContainerProperties, CosmosDatabaseProperties, VcoreConnectionStringOptions };