Skip to content

Commit 11e4cf3

Browse files
authored
Reduce package size (#54)
* let data api deal with overlapping vector and vectorize * deprecated vectorize * update api report * reduced pack size * removed bson-objectid dependency * add missing license bumf to rollup .d.ts file
1 parent bd7d30d commit 11e4cf3

File tree

13 files changed

+200
-26
lines changed

13 files changed

+200
-26
lines changed

.eslintrc.cjs

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

etc/astra-db-ts.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ export interface NumFilterOps {
953953

954954
// @public
955955
export class ObjectId {
956-
constructor(id?: string | null, validate?: boolean);
956+
constructor(id?: string | number | null, validate?: boolean);
957957
equals(other: unknown): boolean;
958958
getTimestamp(): Date;
959959
inspect(): string;

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@
7272
"dotenv": "^16.0.1",
7373
"eslint": "^8.57.0",
7474
"nyc": "^15.1.0",
75+
"strip-comments": "^2.0.1",
7576
"ts-mocha": "^10.0.0",
7677
"tsc-alias": "^1.8.8",
7778
"typescript": "^5.3.3"
7879
},
7980
"dependencies": {
80-
"bson-objectid": "^2.0.4",
8181
"fetch-h2": "^3.0.2",
8282
"safe-stable-stringify": "^2.4.3",
8383
"typed-emitter": "^2.1.0",

scripts/add-license-bumf.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const fs = require('fs');
2+
3+
const bumf = `// Copyright DataStax, Inc.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.`;
16+
17+
const filePath = process.argv[2];
18+
19+
if (!filePath) {
20+
throw new Error('no file path provided');
21+
}
22+
23+
fs.readFile(filePath, 'utf8', (err, data) => {
24+
if (err) {
25+
throw new Error('Error reading file ${filePath}: ${err}');
26+
}
27+
28+
fs.writeFile(filePath, bumf + '\n\n' + data, 'utf8', (err) => {
29+
if (err) {
30+
throw new Error('Error writing file ${filePath}: ${err}');
31+
}
32+
});
33+
});

scripts/build.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ yes | npx tsc --project tsconfig.build.json
1212
# Replaces alias paths with relative paths (e.g. `@/src/version` -> `../../src/version`)
1313
yes | npx tsc-alias -p tsconfig.build.json
1414

15-
# Creates the rollup .d.ts and generates an API report in etc/
16-
npm run api-extractor
15+
# Creates the rollup .d.ts, generates an API report in etc/, and cleans up any temp files
16+
npm run api-extractor && rm -r ./temp
1717

18-
# Deletes the temp folder that was created by API extractor
19-
rm -r ./temp
18+
# Uses a more succinct licence notice + removes block comments (the rollup .d.ts file already contains the ts-doc)
19+
find ./dist -type f -name '*.js' -exec node scripts/reduce-comments.js {} \;
20+
21+
# Adds the missing license notice to the rollup .d.ts
22+
node scripts/add-license-bumf.js dist/astra-db-ts.d.ts
2023

2124
# Removes all .d.ts files except the main rollup .d.ts
2225
cd dist || return 1

scripts/reduce-comments.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const fs = require('fs');
2+
const strip = require('strip-comments');
3+
4+
const longBumf = `// Copyright DataStax, Inc.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.`;
17+
18+
const shortBumf = `// Copyright Datastax, Inc
19+
// SPDX-License-Identifier: Apache-2.0`;
20+
21+
const filePath = process.argv[2];
22+
23+
if (!filePath) {
24+
throw new Error('no file path provided');
25+
}
26+
27+
fs.readFile(filePath, 'utf8', (err, data) => {
28+
if (err) {
29+
throw new Error('Error reading file ${filePath}: ${err}');
30+
}
31+
32+
const withShortenedLicense = data.replace(longBumf, shortBumf);
33+
const withStrippedBlockComments = strip.block(withShortenedLicense);
34+
35+
fs.writeFile(filePath, withStrippedBlockComments, 'utf8', (err) => {
36+
if (err) {
37+
throw new Error('Error writing file ${filePath}: ${err}');
38+
}
39+
});
40+
});

src/common/token-providers/dse-token-providers.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright DataStax, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
import { TokenProvider } from '@/src/common/token-providers/token-provider';
216

317
/**
@@ -38,7 +52,7 @@ export class DSEUsernamePasswordTokenProvider extends TokenProvider {
3852

3953
private _encodeB64(input: string) {
4054
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
41-
return window.btoa(decodeURIComponent(encodeURIComponent(input)));
55+
return window.btoa(input);
4256
} else if (typeof Buffer === 'function') {
4357
return Buffer.from(input, 'utf-8').toString('base64');
4458
} else {

src/common/token-providers/static-token-provider.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright DataStax, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
import { TokenProvider } from '@/src/common/token-providers/token-provider';
216

317
/**

src/common/token-providers/token-provider.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright DataStax, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
import { nullish, StaticTokenProvider } from '@/src/common';
216

317
/**

0 commit comments

Comments
 (0)