Skip to content

Commit da8ccf7

Browse files
committed
Add return types
1 parent cdf1016 commit da8ccf7

File tree

4 files changed

+54
-33
lines changed

4 files changed

+54
-33
lines changed

__tests__/astra.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe("Astra", () => {
5858
namespace: "test",
5959
});
6060

61-
const collection = await astra.deleteCollection({name: "bah"});
61+
const collection = await astra.deleteCollection({ name: "bah" });
6262
expect(collection.status.ok).to.equal(1);
6363
});
6464
});

__tests__/collection.test.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { describe, test } from "mocha";
33
import { expect } from "chai";
44

55
const { ASTRA_DB_TOKEN, ASTRA_DB_ID } = process.env;
6-
const epoch = new Date().getTime();
6+
const epoch = new Date().getTime();
77

88
describe("Collections", () => {
99
let astra;
@@ -14,21 +14,19 @@ describe("Collections", () => {
1414
databaseRegion: "us-east1",
1515
namespace: "test",
1616
});
17-
})
17+
});
1818
describe("Namespaces", () => {
1919
test("should create collection", async () => {
2020
const collectionName = `test${epoch}`;
2121
const results = await astra.createCollection({ name: collectionName });
22-
console.log(results)
22+
console.log(results);
2323
expect(results.status.ok).to.equal(1);
2424
await astra.deleteCollection({ name: collectionName });
2525
});
2626
test("should count collection results", async () => {
2727
const collectionName = `test${epoch}`;
2828
const results = await astra.createCollection({ name: collectionName });
29-
const countResults = await astra
30-
.collection("test")
31-
.countDocuments();
29+
const countResults = await astra.collection("test").countDocuments();
3230
expect(countResults.status.count).to.be.greaterThan(0);
3331
await astra.deleteCollection({ name: collectionName });
3432
});
@@ -48,13 +46,16 @@ describe("Collections", () => {
4846
const collectionName = `test${epoch}`;
4947
await astra.createCollection({ name: collectionName });
5048
const insertResults = await astra.collection(collectionName).insertMany({
51-
documents: [{
52-
name: "Alex",
53-
age: 31,
54-
}, {
55-
name: "Claire",
56-
age: 31,
57-
}],
49+
documents: [
50+
{
51+
name: "Alex",
52+
age: 31,
53+
},
54+
{
55+
name: "Claire",
56+
age: 31,
57+
},
58+
],
5859
});
5960
expect(insertResults.status.insertedIds).length.to.have.length(2);
6061
await astra.deleteCollection({ name: collectionName });
@@ -66,17 +67,17 @@ describe("Collections", () => {
6667
document: {
6768
name: "Alex",
6869
age: 1,
69-
}
70+
},
7071
});
7172
const updateResults = await astra.collection(collectionName).updateOne({
7273
filter: {
7374
name: "Alex",
7475
},
7576
update: {
76-
'$set': {
77+
$set: {
7778
age: 2,
78-
}
79-
}
79+
},
80+
},
8081
});
8182
console.log(updateResults);
8283
// expect(insertResults.status.insertedIds).length.to.have.length(2);

src/astra.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Collection } from "./collection";
33
import { Components } from "../astra";
44
import CreateCollectionCommand = Components.Schemas.CreateCollectionCommand;
55
import DeleteCollectionCommand = Components.Schemas.DeleteCollectionCommand;
6+
import CommandResult = Components.Schemas.CommandResult;
67

78
export interface AstraClientConfig {
89
token: string;
@@ -28,7 +29,9 @@ export class Astra {
2829
};
2930
}
3031

31-
public createCollection = async (args: CreateCollectionCommand) => {
32+
public createCollection = async (
33+
args: CreateCollectionCommand,
34+
): Promise<CommandResult> => {
3235
const response = await axios.post(
3336
`${this.apiBase}/${this.namespace}`,
3437
{
@@ -41,7 +44,7 @@ export class Astra {
4144
);
4245
return response?.data;
4346
};
44-
public findCollections = async () => {
47+
public findCollections = async (): Promise<CommandResult> => {
4548
const response = await axios.post(
4649
`${this.apiBase}/${this.namespace}`,
4750
{
@@ -52,7 +55,9 @@ export class Astra {
5255
return response?.data;
5356
};
5457

55-
public deleteCollection = async (args: DeleteCollectionCommand) => {
58+
public deleteCollection = async (
59+
args: DeleteCollectionCommand,
60+
): Promise<CommandResult> => {
5661
const response = await axios.post(
5762
`${this.apiBase}/${this.namespace}`,
5863
{

src/collection.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import InsertOneCommand = Components.Schemas.InsertOneCommand;
1212
import InsertManyCommand = Components.Schemas.InsertManyCommand;
1313
import UpdateManyCommand = Components.Schemas.UpdateManyCommand;
1414
import UpdateOneCommand = Components.Schemas.UpdateOneCommand;
15+
import CommandResult = Components.Schemas.CommandResult;
1516

1617
export interface AstraCollectionArgs {
1718
collectionName: string;
@@ -36,7 +37,9 @@ export class Collection {
3637
this.apiConfig = args.apiConfig;
3738
}
3839

39-
public countDocuments = async (opts?: CountDocumentsCommands) => {
40+
public countDocuments = async (
41+
opts?: CountDocumentsCommands,
42+
): Promise<CommandResult> => {
4043
const response = await axios.post(
4144
`${this.apiConfig.base}/${this.namespace}/${this.collectionName}`,
4245
{
@@ -50,7 +53,7 @@ export class Collection {
5053
return response?.data;
5154
};
5255

53-
public deleteOne = async (opts: DeleteOneCommand) => {
56+
public deleteOne = async (opts: DeleteOneCommand): Promise<CommandResult> => {
5457
const response = await axios.post(
5558
`${this.apiConfig.base}/${this.namespace}/${this.collectionName}`,
5659
{
@@ -65,7 +68,9 @@ export class Collection {
6568
return response?.data;
6669
};
6770

68-
public deleteMany = async (opts?: DeleteManyCommand) => {
71+
public deleteMany = async (
72+
opts?: DeleteManyCommand,
73+
): Promise<CommandResult> => {
6974
const response = await axios.post(
7075
`${this.apiConfig.base}/${this.namespace}/${this.collectionName}`,
7176
{
@@ -79,7 +84,7 @@ export class Collection {
7984
return response?.data;
8085
};
8186

82-
public find = async (opts?: FindCommand) => {
87+
public find = async (opts?: FindCommand): Promise<CommandResult> => {
8388
const response = await axios.post(
8489
`${this.apiConfig.base}/${this.namespace}/${this.collectionName}`,
8590
{
@@ -95,7 +100,7 @@ export class Collection {
95100
return response?.data;
96101
};
97102

98-
public findOne = async (opts?: FindOneCommand) => {
103+
public findOne = async (opts?: FindOneCommand): Promise<CommandResult> => {
99104
const response = await axios.post(
100105
`${this.apiConfig.base}/${this.namespace}/${this.collectionName}`,
101106
{
@@ -110,7 +115,9 @@ export class Collection {
110115
);
111116
return response?.data;
112117
};
113-
public findOneAndDelete = async (opts: FindOneAndDeleteCommand) => {
118+
public findOneAndDelete = async (
119+
opts: FindOneAndDeleteCommand,
120+
): Promise<CommandResult> => {
114121
const response = await axios.post(
115122
`${this.apiConfig.base}/${this.namespace}/${this.collectionName}`,
116123
{
@@ -124,7 +131,9 @@ export class Collection {
124131
);
125132
return response?.data;
126133
};
127-
public findOneAndReplace = async (opts: FindOneAndReplaceCommand) => {
134+
public findOneAndReplace = async (
135+
opts: FindOneAndReplaceCommand,
136+
): Promise<CommandResult> => {
128137
const response = await axios.post(
129138
`${this.apiConfig.base}/${this.namespace}/${this.collectionName}`,
130139
{
@@ -140,7 +149,9 @@ export class Collection {
140149
);
141150
return response?.data;
142151
};
143-
public findOneAndUpdate = async (opts: FindOneAndUpdateCommand) => {
152+
public findOneAndUpdate = async (
153+
opts: FindOneAndUpdateCommand,
154+
): Promise<CommandResult> => {
144155
const response = await axios.post(
145156
`${this.apiConfig.base}/${this.namespace}/${this.collectionName}`,
146157
{
@@ -156,7 +167,7 @@ export class Collection {
156167
);
157168
return response?.data;
158169
};
159-
public insertOne = async (opts: InsertOneCommand) => {
170+
public insertOne = async (opts: InsertOneCommand): Promise<CommandResult> => {
160171
const response = await axios.post(
161172
`${this.apiConfig.base}/${this.namespace}/${this.collectionName}`,
162173
{
@@ -169,7 +180,9 @@ export class Collection {
169180
);
170181
return response?.data;
171182
};
172-
public insertMany = async (opts: InsertManyCommand) => {
183+
public insertMany = async (
184+
opts: InsertManyCommand,
185+
): Promise<CommandResult> => {
173186
const response = await axios.post(
174187
`${this.apiConfig.base}/${this.namespace}/${this.collectionName}`,
175188
{
@@ -182,7 +195,9 @@ export class Collection {
182195
);
183196
return response?.data;
184197
};
185-
public updateMany = async (opts: UpdateManyCommand) => {
198+
public updateMany = async (
199+
opts: UpdateManyCommand,
200+
): Promise<CommandResult> => {
186201
const response = await axios.post(
187202
`${this.apiConfig.base}/${this.namespace}/${this.collectionName}`,
188203
{
@@ -196,7 +211,7 @@ export class Collection {
196211
);
197212
return response?.data;
198213
};
199-
public updateOne = async (opts: UpdateOneCommand) => {
214+
public updateOne = async (opts: UpdateOneCommand): Promise<CommandResult> => {
200215
const response = await axios.post(
201216
`${this.apiConfig.base}/${this.namespace}/${this.collectionName}`,
202217
{

0 commit comments

Comments
 (0)