You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Like the class hierarchy aforementioned, the options for each class also form an [adjacent hierarchy](https://github.com/datastax/astra-db-ts/tree/b2b79c15a388d2373e884e8921530d81f3593431?tab=readme-ov-file#options-hierarchy).
65
+
*
66
+
* The options for any class are a deep merge of the options for the class itself and the options for its parent classes.
67
+
*
68
+
* For example, you may set default {@link CollectionOptions.logging} options in {@link DataAPIClientOptions.logging}, and override them in the {@link CollectionOptions} themselves as desired.
69
+
*
70
+
* @example
71
+
* ```ts
72
+
* const client = new DataAPIClient({
73
+
* logging: [{ events: 'all', emits: 'event' }],
74
+
* });
75
+
* const db = client.db('https://<db_id>-<region>.apps.astra.datastax.com', { token });
76
+
*
77
+
* // Everything will still be emitted as an event,
78
+
* // But now, `commandFailed` events from this collection will also log to stderr
* @param token - The default token to use when spawning new instances of {@link Db} or {@link AstraAdmin}.
@@ -138,28 +178,52 @@ export class DataAPIClient extends HierarchicalLogger<DataAPIClientEventMap> {
138
178
}
139
179
140
180
/**
181
+
* ##### Overview
182
+
*
141
183
* Spawns a new {@link Db} instance using a direct endpoint and given options.
142
184
*
143
-
* **NB. This method does not validate the existence of the database—it simply creates a reference.**
185
+
* ---
144
186
*
145
-
* This endpoint should include the protocol and the hostname, but not the path. It's typically in the form of
146
-
* `https://<db_id>-<region>.apps.astra.datastax.com`, but it can be used with DSE or any other Data-API-compatible
147
-
* endpoint.
187
+
* ##### Disclaimer
148
188
*
149
-
* The given options will override any default options set when creating the {@link DataAPIClient} through
150
-
* a deep merge (i.e. unset properties in the options object will just default to the default options).
189
+
* This method does *not* validate the existence of the database—it simply creates a reference.**
190
+
*
191
+
* Note that this does not perform any I/O or validation on if the endpoint is valid or not. It's up to the user to
192
+
* ensure that the endpoint is correct. If you want to create an actual database, see {@link AstraAdmin.createDatabase}
193
+
* instead.
194
+
*
195
+
* ---
196
+
*
197
+
* ##### The API endpoint
198
+
*
199
+
* This endpoint should include the protocol and the hostname, but not the path.
200
+
*
201
+
* If you're using Astra, this will typically be of the form `https://<db_id>-<region>.apps.astra.datastax.com` (the exception being private endpoints); any other database may have a completely unique domain.
202
+
*
203
+
* Spawning a db via just an ID and region is no longer supported in `astra-db-ts 2.0+`. Use the {@link buildAstraEndpoint} to create the endpoint if you need to.
thrownewError(`.db() no longer allows the .db('<id>', '<region>') overload; please pass in the full endpoint url (e.g. .db('<endpoint>')). You may use the exported \`buildAstraEndpoint\` utility function if you need to create an endpoint from just an ID and a region.`);
* Spawns a new {@link AstraAdmin} instance using the given options to work with the DevOps API (for admin
182
251
* work such as creating/managing databases).
183
252
*
184
-
* **NB. This method is only available for Astra databases.**
185
-
*
186
-
* The given options will override any default options set when creating the {@link DataAPIClient} through
187
-
* a deep merge (i.e. unset properties in the options object will just default to the default options).
253
+
* **Note: this method is only available for Astra databases.**
188
254
*
189
255
* @example
190
256
* ```typescript
@@ -195,6 +261,12 @@ export class DataAPIClient extends HierarchicalLogger<DataAPIClientEventMap> {
195
261
* console.log(dbs);
196
262
* ```
197
263
*
264
+
* ---
265
+
*
266
+
* ##### The options hierarchy
267
+
*
268
+
* The options for the {@link AstraAdmin} instance are a deep merge of the options for the {@link DataAPIClient} and the options for the {@link AstraAdmin} itself.
269
+
*
198
270
* @param options - Any options to override the default options set when creating the {@link DataAPIClient}.
199
271
*
200
272
* @returns A new {@link AstraAdmin} instance.
@@ -207,24 +279,34 @@ export class DataAPIClient extends HierarchicalLogger<DataAPIClientEventMap> {
207
279
}
208
280
209
281
/**
282
+
* ##### Overview
283
+
*
210
284
* Closes the client and disconnects all underlying connections. This should be called when the client is no longer
211
285
* needed to free up resources.
212
286
*
213
287
* The client will be no longer usable after this method is called.
214
288
*
215
-
* @remarks
216
289
* This method is idempotent and can be called multiple times without issue.
217
290
*
218
-
* --
291
+
* @example
292
+
* ```ts
293
+
* const client = new DataAPIClient(...);
294
+
* await client.close();
295
+
*
296
+
* // Error: Can't make requests on a closed client
297
+
* const coll = client.db(...).collection(...);
298
+
* await coll.findOne();
299
+
* ```
300
+
* ---
301
+
*
302
+
* ##### When to call this method
219
303
*
220
304
* For most users, this method isn't necessary to call, as resources will be freed up when the
221
-
* server is shut down or the process is killed. However, it's useful in long-running processes or when you want to
222
-
* free up resources immediately.
305
+
* server is shut down or the process is killed.
223
306
*
224
-
* --
307
+
* However, it's useful in long-running processes or when you want to free up resources immediately.
225
308
*
226
-
* Think of it as using malloc or using a file descriptor. Freeing them isn't always strictly necessary for
227
-
* long-running usages, but it's there for when you need it.
309
+
* Think of it as using malloc or using a file descriptor. Freeing them isn't *strictly* necessary when they're used for the duration of the program, but it's there for when you need it.
228
310
*
229
311
* @returns A promise that resolves when the client has been closed.
0 commit comments