Skip to content

Commit 9173b3c

Browse files
authored
Minor fixes (#28)
1. Updated createCollection documentation to mention `checkExists` 2. Fixed ragstack detection formatting slightly to keep in-line w/ codebase 3. Added couple replaceOne tests 4. Marked some things @internal that weren't already 5. `'*'` support for projections
1 parent 4d86f85 commit 9173b3c

File tree

7 files changed

+36
-9
lines changed

7 files changed

+36
-9
lines changed

etc/astra-db-ts.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,8 @@ export type StrictPop<Schema extends SomeDoc, InNotation = ToDotNotation<Schema>
986986
// @public
987987
export type StrictProjection<Schema extends SomeDoc> = {
988988
[K in keyof ToDotNotation<WithId<Schema>>]?: any[] extends (ToDotNotation<WithId<Schema>>)[K] ? 1 | 0 | true | false | ProjectionSlice : 1 | 0 | true | false;
989+
} & {
990+
'*': 1 | 0 | true | false;
989991
};
990992

991993
// @public

src/api/constants.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414

1515
import { LIB_NAME, LIB_VERSION } from '@/src/version';
1616

17+
/**
18+
* @internal
19+
*/
1720
export const RAGSTACK_REQUESTED_WITH = (() => {
1821
try {
19-
/**
20-
* Do not use require() here, it will break the build in some environments such as NextJS application^M
21-
* if @datastax/ragstack-ai is not installed (which is perfectly fine).
22-
*/
22+
// Do not use require() here, it will break the build in some environments such as NextJS application
23+
// if @datastax/ragstack-ai is not installed (which is perfectly fine).
2324
const ragstack = eval(`require('@datastax/ragstack-ai')`);
24-
const version = ragstack['RAGSTACK_VERSION'] || "?";
25+
const version = ragstack['RAGSTACK_VERSION'] || '?';
2526
return `ragstack-ai-ts/${version}`
2627
} catch (e) {
2728
return '';

src/api/http-client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ export function hrTimeMs(): number {
9191
return Math.floor(hrtime[0] * 1000 + hrtime[1] / 1000000);
9292
}
9393

94+
/**
95+
* @internal
96+
*/
9497
export function buildUserAgent(caller: Caller | Caller[] | undefined): string {
9598
const callers = (
9699
(!caller)

src/data-api/collection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ export class Collection<Schema extends SomeDoc = SomeDoc> {
551551
returnDocument: 'before',
552552
upsert: options?.upsert,
553553
},
554+
// projection: { '*': 0 },
554555
},
555556
};
556557

src/data-api/db.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ export class Db {
288288
* This is a blocking command which performs actual I/O unlike {@link Db.collection}, which simply creates an
289289
* unvalidated reference to a collection.
290290
*
291-
* **Creation is idempotent, so if the collection already exists with the same options, this method will not throw
292-
* an error. If the options differ though, it'll raise an error.**
291+
* **If `checkExists: false`, creation is idempotent, so if the collection already exists with the same options,
292+
* this method will not throw an error. If the options differ though, it'll raise an error.**
293293
*
294294
* Typed as `Collection<SomeDoc>` by default, but you can specify a schema type to get a typed collection. If left
295295
* as `SomeDoc`, the collection will be untyped.

src/data-api/types/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ export type StrictProjection<Schema extends SomeDoc> = {
156156
[K in keyof ToDotNotation<WithId<Schema>>]?: any[] extends (ToDotNotation<WithId<Schema>>)[K]
157157
? 1 | 0 | true | false | ProjectionSlice
158158
: 1 | 0 | true | false;
159+
} & {
160+
'*': 1 | 0 | true | false;
159161
};
160162

161163
/**

tests/integration/data-api/collection/replace-one.test.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,30 @@ describe('integration.data-api.collection.replace-one', () => {
6767
assert.strictEqual(resp.modifiedCount, 1);
6868
});
6969

70-
it('should replaceOne with upsert true', async () => {
70+
it('should replaceOne with upsert true if match', async () => {
71+
await collection.insertOne({ _id: 1 });
72+
const resp = await collection.replaceOne(
73+
{
74+
_id: 1,
75+
},
76+
createSampleDoc2WithMultiLevel(),
77+
{
78+
upsert: true,
79+
},
80+
);
81+
82+
assert.strictEqual(resp.matchedCount, 1);
83+
assert.strictEqual(resp.modifiedCount, 1);
84+
assert.strictEqual(resp.upsertedCount, 0);
85+
assert.strictEqual(resp.upsertedId, undefined);
86+
});
87+
88+
it('should replaceOne with upsert true if no match', async () => {
7189
await collection.insertOne(createSampleDocWithMultiLevel());
7290
const newDocId = '123';
7391
const resp = await collection.replaceOne(
7492
{
75-
'_id': newDocId,
93+
_id: newDocId,
7694
},
7795
createSampleDoc2WithMultiLevel(),
7896
{

0 commit comments

Comments
 (0)