Skip to content

Commit d0c6e0b

Browse files
authored
Rough, complete, roughly complete Table implementation (#78)
* documented table-schema file * tsdoc work * remove checkExists * ser/des work * playground script * started adding custom inspects and work on datetimes * made _httpClient fully public * work on DataAPIVector stuff * some resturcturing * made all Promise<true> methods just reutrn Promise<void> * removed rackstackk hack * cqlblob type * additionalHeaders * started documenting table-related stuff * formatting for events logging * documentation for logging * document collection class * created CursorError * set up test suite for table tests * move dropIndex to db level * lot of work on bignumbers hack... * remove CollectionNotFoundError * added table.deifnition() * super basic insertOne test * basic findone tests * toomanyrowstocount error * start documenting serdes * split cumulative errors + some more bignumber serdes work * changed $PrimaryKeyType to be a string + some test typing fixes * added sparse data support
1 parent bee45ab commit d0c6e0b

File tree

158 files changed

+7102
-2359
lines changed

Some content is hidden

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

158 files changed

+7102
-2359
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,6 @@ tsdoc-metadata.json
139139

140140
vectorize_test_spec.json
141141
etc/test-reports/
142+
etc/playgrounds/
142143

143144
.direnv

DEVGUIDE.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ The API for the test script is as the following:
6868
6. [-R | -no-report]
6969
7. [-c <http_client>]
7070
8. [-e <environment>]
71+
9. [-stargate]
72+
10. [-l | -logging]
73+
11. [-P | -skip-prelude]
7174
```
7275

7376
#### 1. The test file (`scripts/test.sh`)
@@ -156,6 +159,20 @@ By default, `astra-db-ts` assumes you're running on Astra, but you can specify t
156159
flag. It should be one of `dse`, `hcd`, `cassandra`, or `other`. You can also provide `astra`, but it wouldn't really
157160
do anything. But I'm not the boss of you; you can make your own big-boy/girl/other decisions.
158161

162+
#### 9. Running the tests on Stargate (`[-stargate]`)
163+
164+
If you're running the tests on a local Stargate instance, you can use this flag to set the `CLIENT_DB_URL` to
165+
`http://localhost:8080` and the `CLIENT_DB_TOKEN` to `cassandra:cassandra` without needing to modify your `.env` file.
166+
167+
#### 10. Logging (`[-l | -logging]`)
168+
169+
Logs all `[admin]CommandStarted` & `[admin]CommandFailed` events to the console. Useful for debugging.
170+
171+
#### 11. Skipping the prelude (`[-P | -skip-prelude]`)
172+
173+
By default, the test script will run a "prelude" script that sets up the database for the tests. This can be skipped
174+
to save some time, using this flag, if the DB is already setup (enough), and you just want to run a test really quickly.
175+
159176
### Test tags
160177

161178
The `astra-db-ts` test suite uses the concept of "test tags" to further advance test filtering. These are tags in

etc/astra-db-ts.api.md

Lines changed: 678 additions & 296 deletions
Large diffs are not rendered by default.

package-lock.json

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

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@eslint/eslintrc": "^3.1.0",
5555
"@eslint/js": "^9.10.0",
5656
"@microsoft/api-extractor": "^7.47.9",
57+
"@types/json-bigint": "^1.0.4",
5758
"@types/mocha": "^9.1.1",
5859
"@types/node": "^17.0.36",
5960
"@types/object-hash": "^3.0.6",
@@ -67,7 +68,9 @@
6768
"typescript": "^5.6.2"
6869
},
6970
"dependencies": {
71+
"bignumber.js": "^9.1.2",
7072
"fetch-h2": "^3.0.2",
73+
"json-bigint": "^1.0.0",
7174
"safe-stable-stringify": "^2.4.3",
7275
"typed-emitter": "^2.1.0",
7376
"typescript-eslint": "^8.7.0",

scripts/playground.sh

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env sh
2+
3+
tarball_dir=$(pwd)
4+
5+
case "$1" in
6+
create)
7+
if [ -d etc/playgrounds/"$2" ]; then
8+
echo "Playground '$2' already exists; do you want to delete and recreate it? [y/N]"
9+
read -r response
10+
11+
if [ "$response" != "y" ]; then
12+
echo "You can use 'update' to update the playground instead with the latest local build of \`astra-db-ts\`"
13+
exit 1
14+
fi
15+
fi
16+
17+
if [ -z "$2" ]; then
18+
echo "Usage: $0 create <name>"
19+
exit 1
20+
fi
21+
22+
npm run build
23+
npm pack
24+
25+
rm -rf etc/playgrounds/"$2"
26+
mkdir -p etc/playgrounds/"$2"
27+
cd etc/playgrounds/"$2" || exit 1
28+
29+
npm init -y
30+
npm i -D typescript tsx dotenv
31+
cp ../../../tsconfig.json .
32+
33+
npm i "${tarball_dir}"/datastax-astra-db-ts-*.tgz
34+
rm "${tarball_dir}"/datastax-astra-db-ts-*.tgz
35+
36+
echo "import * as $ from '@datastax/astra-db-ts';
37+
import dotenv from 'dotenv';
38+
39+
dotenv.configDotenv({ path: '../../../.env' });
40+
41+
const client = new $.DataAPIClient(process.env.CLIENT_DB_TOKEN, { environment: process.env.CLIENT_DB_ENVIRONMENT as any });
42+
const db = client.db(process.env.CLIENT_DB_URL!);
43+
const admin = client.admin();
44+
const dbAdmin = db.admin({ environment: process.env.CLIENT_DB_ENVIRONMENT as any });
45+
const coll = db.collection('test_coll');
46+
const table = db.table('test_table');
47+
48+
(async () => {
49+
50+
})();" > index.ts
51+
;;
52+
update)
53+
if [ -z "$2" ]; then
54+
echo "Usage: $0 update <name>"
55+
exit 1
56+
fi
57+
58+
if [ ! -d etc/playgrounds/"$2" ]; then
59+
echo "Playground '$2' not found"
60+
exit 1
61+
fi
62+
63+
npm run build
64+
npm pack
65+
66+
cd etc/playgrounds/"$2" || exit 1
67+
68+
npm i "${tarball_dir}"/datastax-astra-db-ts-*.tgz
69+
rm "${tarball_dir}"/datastax-astra-db-ts-*.tgz
70+
;;
71+
destroy)
72+
if [ -z "$2" ]; then
73+
echo "Usage: $0 destroy <name>"
74+
exit 1
75+
fi
76+
77+
if [ ! -d etc/playgrounds/"$2" ]; then
78+
echo "Playground '$2' not found"
79+
exit 1
80+
fi
81+
82+
rm -rf etc/playgrounds/"$2"
83+
;;
84+
*)
85+
if [ -z "$1" ]; then
86+
echo "Usage: $0 <name>"
87+
exit 1
88+
fi
89+
90+
if [ ! -d etc/playgrounds/"$1" ]; then
91+
echo "Playground '$1' not found"
92+
exit 1
93+
fi
94+
95+
cd etc/playgrounds/"$1" || exit 1
96+
npx tsx index.ts
97+
esac

scripts/repl.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ node -i -e "
1919
require('./node_modules/dotenv/config');
2020
2121
const $ = require('./dist');
22+
require('util').inspect.defaultOptions.depth = null;
2223
2324
let client = new $.DataAPIClient(process.env.CLIENT_DB_TOKEN, { environment: process.env.CLIENT_DB_ENVIRONMENT });
2425
let db = client.db(process.env.CLIENT_DB_URL);
2526
let admin = client.admin();
2627
let dbAdmin = db.admin({ environment: process.env.CLIENT_DB_ENVIRONMENT });
28+
let coll = db.collection('test_coll');
29+
let table = db.table('test_table');
2730
2831
Object.defineProperty(this, 'cl', {
2932
get() {

scripts/test.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,20 @@ while [ $# -gt 0 ]; do
8080
shift
8181
environment="$1"
8282
;;
83+
"-l" | "-logging")
84+
logging=1
85+
;;
86+
"-P" | "-skip-prelude")
87+
skip_prelude=1
88+
;;
8389
"-stargate")
8490
stargate=1
8591
;;
8692
*)
8793
echo "Invalid flag $1"
8894
echo ""
8995
echo "Usage:"
90-
echo "scripts/test.sh [-all | -light | -coverage] [-for] [-f/F <filter>]+ [-g/G <regex>]+ [-w/W <vectorize_whitelist>] [-b | -bail] [-R | -no-report] [-c <http_client>] [-e <environment>] [-stargate]"
96+
echo "scripts/test.sh [-all | -light | -coverage] [-for] [-f/F <filter>]+ [-g/G <regex>]+ [-w/W <vectorize_whitelist>] [-b | -bail] [-R | -no-report] [-c <http_client>] [-e <environment>] [-stargate] [-l | -logging] [-P | -skip-prelude]"
9197
echo "or"
9298
echo "scripts/test.sh [-lint] [-tc]"
9399
exit
@@ -97,7 +103,7 @@ while [ $# -gt 0 ]; do
97103
done
98104

99105
# Ensure the flags are compatible with each other
100-
if [ "$test_type" = "code" ] && { [ -n "$bail_early" ] || [ -n "$filter" ] || [ -n "$filter_combinator" ] || [ -n "$whitelist" ] || [ -n "$no_err_report" ] || [ -n "$http_client" ] || [ -n "$environment" ]; }; then
106+
if [ "$test_type" = "code" ] && { [ -n "$bail_early" ] || [ -n "$filter" ] || [ -n "$filter_combinator" ] || [ -n "$whitelist" ] || [ -n "$no_err_report" ] || [ -n "$http_client" ] || [ -n "$environment" ] || [ -n "$logging" ] || [ -n "$skip_prelude" ]; }; then
101107
echo "Can't use a filter, bail, whitelist flags when typechecking/linting"
102108
exit 1
103109
fi
@@ -165,6 +171,13 @@ fi
165171
if [ -n "$stargate" ]; then
166172
export USING_LOCAL_STARGATE=1
167173
fi
174+
if [ -n "$logging" ]; then
175+
export LOG_ALL_TO_STDOUT=1
176+
fi
177+
178+
if [ -n "$skip_prelude" ]; then
179+
export SKIP_PRELUDE=1
180+
fi
168181

169182
# Get embedding providers, if desired, to build the vectorize part of the command
170183
if [ -n "$CLIENT_RUN_VECTORIZE_TESTS" ] && [ "$test_type" != 'code' ]; then

src/administration/astra-admin.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ import { DevOpsAPIHttpClient } from '@/src/lib/api/clients/devops-api-http-clien
2828
import { TokenProvider, WithTimeout } from '@/src/lib';
2929
import { parseAdminSpawnOpts } from '@/src/client/parsers/spawn-admin';
3030
import { InternalRootClientOpts } from '@/src/client/types/internal';
31-
import { DbSpawnOptions, Logger } from '@/src/client';
3231
import { buildAstraEndpoint } from '@/src/lib/utils';
32+
import { Logger } from '@/src/lib/logging/logger';
33+
import { DbSpawnOptions } from '@/src/client';
34+
import { $CustomInspect } from '@/src/lib/constants';
3335

3436
/**
3537
* An administrative class for managing Astra databases, including creating, listing, and deleting databases.
@@ -77,6 +79,7 @@ export class AstraAdmin {
7779
endpointUrl: adminOpts?.endpointUrl || rootOpts.adminOptions.endpointUrl,
7880
adminToken: token,
7981
logging: Logger.advanceConfig(rootOpts.adminOptions.logging, adminOpts?.logging),
82+
additionalHeaders: { ...rootOpts.adminOptions.additionalHeaders, ...adminOpts?.additionalHeaders },
8083
},
8184
dbOptions: {
8285
...rootOpts.dbOptions,
@@ -91,6 +94,11 @@ export class AstraAdmin {
9194
fetchCtx: rootOpts.fetchCtx,
9295
userAgent: rootOpts.userAgent,
9396
tokenProvider: this.#defaultOpts.adminOptions.adminToken,
97+
additionalHeaders: this.#defaultOpts.adminOptions.additionalHeaders,
98+
});
99+
100+
Object.defineProperty(this, $CustomInspect, {
101+
value: () => `AstraAdmin()`,
94102
});
95103
}
96104

src/administration/astra-db-admin.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { isNullish } from '@/src/lib/utils';
3131
import { parseAdminSpawnOpts } from '@/src/client/parsers/spawn-admin';
3232
import { InternalRootClientOpts } from '@/src/client/types/internal';
3333
import { Logger } from '@/src/lib/logging/logger';
34+
import { $CustomInspect } from '@/src/lib/constants';
3435

3536
/**
3637
* An administrative class for managing Astra databases, including creating, listing, and deleting keyspaces.
@@ -94,9 +95,14 @@ export class AstraDbAdmin extends DbAdmin {
9495
emitter: rootOpts.emitter,
9596
userAgent: rootOpts.userAgent,
9697
tokenProvider: adminToken,
98+
additionalHeaders: { ...rootOpts.adminOptions.additionalHeaders, ...adminOpts?.additionalHeaders },
9799
});
98100

99101
this.#db = db;
102+
103+
Object.defineProperty(this, $CustomInspect, {
104+
value: () => `AstraDbAdmin()`,
105+
});
100106
}
101107

102108
/**

0 commit comments

Comments
 (0)