4
4
5
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.*
6
6
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
+
7
16
## Quickstart
8
17
9
18
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:
96
105
- [ Data API reference] ( https://docs.datastax.com/en/astra/astra-db-vector/api-reference/data-api-commands.html )
97
106
- Package on [ npm] ( https://www.npmjs.com/package/@datastax/astra-db-ts )
98
107
99
- ## astra-db-ts's API
100
-
101
- ### Abstraction diagram
108
+ ## High-level architecture
102
109
103
110
` astra-db-ts ` 's abstractions for working at the data and admin layers are structured as depicted by this diagram:
104
111
@@ -125,7 +132,7 @@ const admin = client.admin();
125
132
})();
126
133
```
127
134
128
- ### Getting the most out of the typing
135
+ ## Getting the most out of the typing
129
136
130
137
` astra-db-ts ` is a typescript-first library, performing minimal runtime type-checking. As such, it provides
131
138
a rich set of types to help you write type-safe code.
@@ -182,7 +189,7 @@ interface Person {
182
189
})();
183
190
```
184
191
185
- ### Working with Dates
192
+ ## Working with Dates
186
193
187
194
Native JS ` Date ` objects can be used anywhere in documents to represent dates and times.
188
195
@@ -222,7 +229,7 @@ const db = client.db('*ENDPOINT*', { namespace: '*NAMESPACE*' });
222
229
})();
223
230
```
224
231
225
- ### Working with ObjectIds and UUIDs
232
+ ## Working with ObjectIds and UUIDs
226
233
227
234
` astra-db-ts ` exports an ` ObjectId ` and ` UUID ` class for working with these types in the database.
228
235
@@ -271,7 +278,7 @@ const db = client.db('*ENDPOINT*', { namespace: '*NAMESPACE*' });
271
278
})();
272
279
```
273
280
274
- ### Monitoring/logging
281
+ ## Monitoring/logging
275
282
276
283
[ Like Mongo] ( https://www.mongodb.com/docs/drivers/node/current/fundamentals/logging/ ) , ` astra-db-ts ` doesn't provide a
277
284
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) => {
323
330
await collection .drop ();
324
331
})();
325
332
```
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