| 
2 | 2 | 
 
  | 
3 | 3 | `astra-db-ts` is a TypeScript client for interacting with [DataStax Astra DB](https://astra.datastax.com/signup).  | 
4 | 4 | 
 
  | 
5 |  | -*This README targets v1.0.0+, which introduces a whole new API. Click [here](https://github.com/datastax/astra-db-ts/tree/90ebeac6fec53fd951126c2bcc010c87f7f678f8?tab=readme-ov-file#datastaxastra-db-ts) for the pre-existing client readme.*  | 
 | 5 | +> **Warning**  | 
 | 6 | +> This README is still under construction; parts of it may be incomplete or outdated.  | 
 | 7 | +
  | 
 | 8 | +*This README targets v2.0.0+, which introduces a whole new API. Click [here](https://github.com/datastax/astra-db-ts/tree/v1.x?tab=readme-ov-file#datastaxastra-db-ts) for the pre-existing client readme.*  | 
6 | 9 | 
 
  | 
7 | 10 | ## Table of contents  | 
8 | 11 | - [Quickstart](#quickstart)  | 
@@ -243,18 +246,6 @@ interface Person {  | 
243 | 246 |  // @ts-expect-error - 'eyeColor' does not exist in type MaybeId<Person>  | 
244 | 247 |  eyeColor: 'blue',  | 
245 | 248 |  });  | 
246 |  | - | 
247 |  | - // You can use the 'Strict*' version of Sort/Projection/Filter/UpdateFilter for proper type-checking and autocomplete  | 
248 |  | - await collection.findOne({  | 
249 |  | - // @ts-expect-error - Type number is not assignable to type FilterExpr<UUID | undefined>  | 
250 |  | - 'interests.friend': 3,  | 
251 |  | - } satisfies StrictFilter<Person>, {  | 
252 |  | - sort: {  | 
253 |  | - name: 1,  | 
254 |  | - // @ts-expect-error - 'interests.favoriteColor' does not exist in type StrictProjection<Person>  | 
255 |  | - 'interests.favoriteColor': 1 as const,  | 
256 |  | - } satisfies StrictSort<Person>,  | 
257 |  | - });  | 
258 | 249 | })();  | 
259 | 250 | ```  | 
260 | 251 | 
 
  | 
@@ -347,59 +338,6 @@ const db = client.db('*ENDPOINT*', { namespace: '*NAMESPACE*' });  | 
347 | 338 | })();  | 
348 | 339 | ```  | 
349 | 340 | 
 
  | 
350 |  | -## Monitoring/logging  | 
351 |  | - | 
352 |  | -[Like Mongo](https://www.mongodb.com/docs/drivers/node/current/fundamentals/logging/), `astra-db-ts` doesn't provide a  | 
353 |  | -traditional logging system—instead, it uses a "monitoring" system based on event emitters, which allow you to listen to  | 
354 |  | -events and log them as you see fit.  | 
355 |  | - | 
356 |  | -Supported events include `commandStarted`, `commandSucceeded`, `commandFailed`, and `adminCommandStarted`,  | 
357 |  | -`adminCommandPolling`, `adminCommandSucceeded`, `adminCommandFailed`.  | 
358 |  | - | 
359 |  | -Note that it's disabled by default, and it can be enabled by passing `monitorCommands: true` option to the root options'  | 
360 |  | -`dbOptions` and `adminOptions`.  | 
361 |  | - | 
362 |  | -```typescript  | 
363 |  | -import { DataAPIClient } from '@datastax/astra-db-ts';  | 
364 |  | - | 
365 |  | -const client = new DataAPIClient('*TOKEN*', {  | 
366 |  | - dbOptions: {  | 
367 |  | - monitorCommands: true,  | 
368 |  | - },  | 
369 |  | -});  | 
370 |  | -const db = client.db('*ENDPOINT*');  | 
371 |  | - | 
372 |  | -client.on('commandStarted', (event) => {  | 
373 |  | - console.log(`Running command ${event.commandName}`);  | 
374 |  | -});  | 
375 |  | - | 
376 |  | -client.on('commandSucceeded', (event) => {  | 
377 |  | - console.log(`Command ${event.commandName} succeeded in ${event.duration}ms`);  | 
378 |  | -});  | 
379 |  | - | 
380 |  | -client.on('commandFailed', (event) => {  | 
381 |  | - console.error(`Command ${event.commandName} failed w/ error ${event.error}`);  | 
382 |  | -});  | 
383 |  | - | 
384 |  | -(async () => {  | 
385 |  | - // Should log  | 
386 |  | - // - "Running command createCollection"  | 
387 |  | - // - "Command createCollection succeeded in <time>ms"  | 
388 |  | - const collection = await db.createCollection('my_collection', { checkExists: false });  | 
389 |  | - | 
390 |  | - // Should log  | 
391 |  | - // - "Running command insertOne"  | 
392 |  | - // - "Command insertOne succeeded in <time>ms"  | 
393 |  | - await collection.insertOne({ name: 'Queen' });  | 
394 |  | - | 
395 |  | - // Remove all monitoring listeners  | 
396 |  | - client.removeAllListeners();  | 
397 |  | - | 
398 |  | - // Cleanup (if desired) (with no logging)  | 
399 |  | - await collection.drop();  | 
400 |  | -})();  | 
401 |  | -```  | 
402 |  | - | 
403 | 341 | ## Non-astra support  | 
404 | 342 | 
 
  | 
405 | 343 | `astra-db-ts` officially supports Data API instances using non-Astra backends, such as Data API on DSE or HCD.   | 
 | 
0 commit comments