Skip to content

Commit dd55ddc

Browse files
authored
Minor 1.3.0 updates (#49)
- `replaceOne` now uses `projection: { '*': 0 }` under the hood - made `distinct` *much* faster - added token providers - extra bug fixes, refactoring, documentation, etc.
1 parent e7f3d5f commit dd55ddc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+840
-343
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-env node */
22
module.exports = {
3-
ignorePatterns: ['dist/*'],
3+
ignorePatterns: ['dist/*', 'scripts/*'],
44
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
55
parser: '@typescript-eslint/parser',
66
plugins: ['@typescript-eslint'],

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,4 @@ build.zip
137137
temp
138138
tsdoc-metadata.json
139139

140-
tests/vectorize_credentials.json
140+
vectorize_credentials.json

DEVGUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ test suite harder to manage.
7474

7575
### Running vectorize tests
7676
To run vectorize tests, you need to have a vectorize-enabled kube running, with the correct tags enabled.
77-
You must create a file, `tests/vectorize_tests.json`, with the following format:
77+
You must create a file, `vectorize_tests.json`, in the root folder, with the following format:
7878

7979
```ts
8080
interface Config {

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ const db = client.db('*ENDPOINT*', { namespace: '*NAMESPACE*' });
101101
})();
102102
```
103103

104-
Next steps:
104+
### Next steps
105+
105106
- More info and usage patterns are given in the ts-doc of classes and methods
106107
- [TS client reference](https://docs.datastax.com/en/astra/astra-db-vector/clients/typescript.html)
107108
- [Data API reference](https://docs.datastax.com/en/astra/astra-db-vector/api-reference/data-api-commands.html)

etc/astra-db-ts.api.md

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class AdminCommandSucceededEvent extends AdminCommandEvent {
6363

6464
// @public
6565
export interface AdminSpawnOptions {
66-
adminToken?: string;
66+
adminToken?: string | TokenProvider | null;
6767
endpointUrl?: string;
6868
monitorCommands?: boolean;
6969
}
@@ -101,11 +101,7 @@ export class AstraAdmin {
101101
// Warning: (ae-forgotten-export) The symbol "InternalRootClientOpts" needs to be exported by the entry point index.d.ts
102102
//
103103
// @internal
104-
constructor(options: InternalRootClientOpts & {
105-
adminOptions: {
106-
adminToken: string;
107-
};
108-
});
104+
constructor(options: InternalRootClientOpts);
109105
createDatabase(config: DatabaseConfig, options?: CreateDatabaseOptions): Promise<AstraDbAdmin>;
110106
db(endpoint: string, options?: DbSpawnOptions): Db;
111107
db(id: string, region: string, options?: DbSpawnOptions): Db;
@@ -333,7 +329,8 @@ export interface CustomHttpClientOptions {
333329
// @public
334330
export class DataAPIClient extends DataAPIClientEventEmitterBase {
335331
[Symbol.asyncDispose]: () => Promise<void>;
336-
constructor(token: string, options?: DataAPIClientOptions | null);
332+
constructor(options?: DataAPIClientOptions | nullish);
333+
constructor(token: string | TokenProvider | nullish, options?: DataAPIClientOptions | nullish);
337334
admin(options?: AdminSpawnOptions): AstraAdmin;
338335
close(): Promise<void>;
339336
db(endpoint: string, options?: DbSpawnOptions): Db;
@@ -525,7 +522,7 @@ export interface DbSpawnOptions {
525522
dataApiPath?: string;
526523
monitorCommands?: boolean;
527524
namespace?: string;
528-
token?: string;
525+
token?: string | TokenProvider | null;
529526
}
530527

531528
// @public
@@ -615,6 +612,12 @@ export class DevOpsUnexpectedStateError extends DevOpsAPIError {
615612
export interface DropCollectionOptions extends WithTimeout, WithNamespace {
616613
}
617614

615+
// @public
616+
export class DSEUsernamePasswordTokenProvider extends TokenProvider {
617+
constructor(username: string, password: string);
618+
getTokenAsString(): Promise<string>;
619+
}
620+
618621
// @public
619622
export class FailedToLoadDefaultClientError extends Error {
620623
// @internal
@@ -923,6 +926,9 @@ export interface NoUpsertUpdateOptions {
923926
upsertedId?: never;
924927
}
925928

929+
// @public
930+
export type nullish = null | undefined;
931+
926932
// @public
927933
export type NumberUpdate<Schema> = {
928934
[K in keyof Schema as IsNum<Schema[K]> extends true ? K : never]?: number | bigint;
@@ -1023,6 +1029,12 @@ export type Sort = Record<string, SortDirection> | {
10231029
// @public
10241030
export type SortDirection = 1 | -1 | 'asc' | 'desc' | 'ascending' | 'descending';
10251031

1032+
// @public
1033+
export class StaticTokenProvider extends TokenProvider {
1034+
constructor(token: string);
1035+
getTokenAsString(): Promise<string>;
1036+
}
1037+
10261038
// @public
10271039
export type StrictDateUpdate<Schema extends SomeDoc, InNotation = ToDotNotation<Schema>> = ContainsDate<InNotation> extends true ? {
10281040
[K in keyof InNotation as ContainsDate<InNotation[K]> extends true ? K : never]?: Date | {
@@ -1110,6 +1122,13 @@ export interface StrictUpdateFilter<Schema extends SomeDoc> {
11101122
// @public
11111123
export type ToDotNotation<Schema extends SomeDoc> = Merge<_ToDotNotation<Schema, ''>>;
11121124

1125+
// @public
1126+
export abstract class TokenProvider {
1127+
abstract getTokenAsString(): Promise<string>;
1128+
// @internal
1129+
static parseToken(token: unknown): TokenProvider | nullish;
1130+
}
1131+
11131132
// @public
11141133
export class TooManyDocumentsToCountError extends DataAPIError {
11151134
// @internal

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"test:prerelease": "npm run lint && npm run test:types && npm run test:all -- -b --exit",
5757
"api-extractor": "api-extractor run -c ./api-extractor.jsonc --local",
5858
"build": "sh ./scripts/build.sh",
59+
"find-missing-licensing": "sh ./scripts/check-licensing.sh",
5960
"version": "npm run build && git add src/version.ts etc/astra-db-ts.api.md"
6061
},
6162
"bugs": {
@@ -78,7 +79,7 @@
7879
"dependencies": {
7980
"bson-objectid": "^2.0.4",
8081
"fetch-h2": "^3.0.2",
81-
"object-hash": "^3.0.0",
82+
"safe-stable-stringify": "^2.4.3",
8283
"typed-emitter": "^2.1.0",
8384
"uuidv7": "^0.6.3"
8485
},

scripts/build-version-file.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
console.log([
2+
`// Copyright DataStax, Inc.`,
3+
`//`,
4+
`// Licensed under the Apache License, Version 2.0 (the "License");`,
5+
`// you may not use this file except in compliance with the License.`,
6+
`// You may obtain a copy of the License at`,
7+
`//`,
8+
`// http://www.apache.org/licenses/LICENSE-2.0`,
9+
`//`,
10+
`// Unless required by applicable law or agreed to in writing, software`,
11+
`// distributed under the License is distributed on an "AS IS" BASIS,`,
12+
`// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.`,
13+
`// See the License for the specific language governing permissions and`,
14+
`// limitations under the License.`,
15+
``,
16+
`export const LIB_NAME = 'astra-db-ts';`,
17+
`export const LIB_VERSION = '${require('../package.json').version}';`,
18+
].join('\n'));

scripts/build.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
rm -rf ./dist
55

66
# Creates the version file
7-
echo "export const LIB_NAME = 'astra-db-ts';" > src/version.ts
8-
node -p "'export const LIB_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'" >> src/version.ts
7+
node scripts/build-version-file.js > src/version.ts
98

109
# Transpiles the project
11-
npx tsc --project tsconfig.build.json
10+
yes | npx tsc --project tsconfig.build.json
1211

1312
# Replaces alias paths with relative paths (e.g. `@/src/version` -> `../../src/version`)
14-
npx tsc-alias -p tsconfig.build.json
13+
yes | npx tsc-alias -p tsconfig.build.json
1514

1615
# Creates the rollup .d.ts and generates an API report in etc/
1716
npm run api-extractor

scripts/check-licensing.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
find tests/ src/ -type f -exec grep -L "^// Copyright DataStax, Inc." {} +

0 commit comments

Comments
 (0)