Skip to content

Commit a9ada5d

Browse files
authored
added TOC + non-standard runtime support bumf (#40)
1 parent 46f62da commit a9ada5d

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

README.md

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
*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.*
66

7+
## Table of contents
8+
- [Quickstart](#quickstart)
9+
- [High-level architecture](#high-level-architecture)
10+
- [Getting the most out of the typing](#getting-the-most-out-of-the-typing)
11+
- [Working with Dates](#working-with-dates)
12+
- [Working with ObjectIds and UUIDs](#working-with-objectids-and-uuids)
13+
- [Monitoring/logging](#monitoringlogging)
14+
- [Non-standard runtime support](#non-standard-runtime-support)
15+
716
## Quickstart
817

918
Use your preferred package manager to install `@datastax/astra-db-ts`. Note that this is not supported in browsers.
@@ -96,9 +105,7 @@ Next steps:
96105
- [Data API reference](https://docs.datastax.com/en/astra/astra-db-vector/api-reference/data-api-commands.html)
97106
- Package on [npm](https://www.npmjs.com/package/@datastax/astra-db-ts)
98107

99-
## astra-db-ts's API
100-
101-
### Abstraction diagram
108+
## High-level architecture
102109

103110
`astra-db-ts`'s abstractions for working at the data and admin layers are structured as depicted by this diagram:
104111

@@ -125,7 +132,7 @@ const admin = client.admin();
125132
})();
126133
```
127134

128-
### Getting the most out of the typing
135+
## Getting the most out of the typing
129136

130137
`astra-db-ts` is a typescript-first library, performing minimal runtime type-checking. As such, it provides
131138
a rich set of types to help you write type-safe code.
@@ -182,7 +189,7 @@ interface Person {
182189
})();
183190
```
184191

185-
### Working with Dates
192+
## Working with Dates
186193

187194
Native JS `Date` objects can be used anywhere in documents to represent dates and times.
188195

@@ -222,7 +229,7 @@ const db = client.db('*ENDPOINT*', { namespace: '*NAMESPACE*' });
222229
})();
223230
```
224231

225-
### Working with ObjectIds and UUIDs
232+
## Working with ObjectIds and UUIDs
226233

227234
`astra-db-ts` exports an `ObjectId` and `UUID` class for working with these types in the database.
228235

@@ -271,7 +278,7 @@ const db = client.db('*ENDPOINT*', { namespace: '*NAMESPACE*' });
271278
})();
272279
```
273280

274-
### Monitoring/logging
281+
## Monitoring/logging
275282

276283
[Like Mongo](https://www.mongodb.com/docs/drivers/node/current/fundamentals/logging/), `astra-db-ts` doesn't provide a
277284
traditional logging system—instead, it uses a "monitoring" system based on event emitters, which allow you to listen to
@@ -323,3 +330,29 @@ client.on('commandFailed', (event) => {
323330
await collection.drop();
324331
})();
325332
```
333+
334+
## Non-standard runtime support
335+
336+
`astra-db-ts` is designed foremost to work in Node.js environments, and it's not supported in browsers. It will work
337+
in edge runtimes and other non-node environments as well, though it'll use the native `fetch` API for HTTP requests,
338+
as opposed to `fetch-h2` which provides extended HTTP/2 and HTTP/1.1 support for performance.
339+
340+
On Node (exactly node; not Bun or Deno with node compat on) environments, it'll use `fetch-h2` by default; on others,
341+
it'll use `fetch`. You can explicitly set the fetch implementation when instantiating the client:
342+
343+
```typescript
344+
import { DataAPIClient } from '@datastax/astra-db-ts';
345+
346+
const client = new DataAPIClient('*TOKEN*', {
347+
httpOptions: {
348+
client: 'fetch', // or 'default' for fetch-h2
349+
},
350+
});
351+
```
352+
353+
Note that setting the `httpOptions` implicitly sets the fetch implementation to default (fetch-h2),
354+
so you'll need to set it explicitly if you want to use the native fetch implementation.
355+
356+
On some environments, such as Cloudflare Workers, you may additionally need to use the events
357+
polyfill for the client to work properly (i.e. `npm i events`). Cloudflare's node-compat won't
358+
work here.

0 commit comments

Comments
 (0)