Skip to content

Commit

Permalink
add eslint rule to remote trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jan 3, 2025
1 parent 62d5b72 commit ca6ab11
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 35 deletions.
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ module.exports = [
],
'quotes': ['warn', 'single'],
'prefer-const': 'warn',
'no-extra-semi': 'warn'
'no-extra-semi': 'warn',
'no-trailing-spaces': 'warn'
}
},
{
Expand Down
6 changes: 3 additions & 3 deletions src/deserializeDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { DataAPIBlob, DataAPIVector } from '@datastax/astra-db-ts';

/**
* Transforms astra-db-ts document results into something Mongoose can deserialize:
*
*
* 1. DataAPIVector -> array
* 2. Map -> POJO since Mongoose doesn't expect maps from the underlying driver
*
* @param doc
*
* @param doc
* @returns void
*/

Expand Down
12 changes: 6 additions & 6 deletions src/driver/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class Collection<DocType extends Record<string, unknown> = Record<string,
? { ...options, sort: processSortOption(options.sort) }
: { ...options, sort: undefined };
filter = serialize(filter, this.useTables);

// Weirdness to work around astra-db-ts method overrides: `find()` with `projection: never` means we need a separate branch
if (this.collection instanceof AstraTable) {
return this.collection.find(filter as TableFilter<DocType>, requestOptions).map(doc => deserializeDoc<DocType>(doc));
Expand All @@ -139,7 +139,7 @@ export class Collection<DocType extends Record<string, unknown> = Record<string,
const requestOptions: FindOneOptionsInternal = options != null && options.sort != null
? { ...options, sort: processSortOption(options.sort) }
: { ...options, sort: undefined };

filter = serialize(filter, this.useTables);

// Weirdness to work around astra-db-ts method overrides: `findOne()` with `projection: never` means we need a separate branch
Expand Down Expand Up @@ -170,7 +170,7 @@ export class Collection<DocType extends Record<string, unknown> = Record<string,
} else {
return this.collection.insertMany(documents as DocType[], options);
}

}

/**
Expand Down Expand Up @@ -388,7 +388,7 @@ export class Collection<DocType extends Record<string, unknown> = Record<string,

/**
* Create a new index
*
*
* @param name
* @param column
* @param options
Expand All @@ -406,7 +406,7 @@ export class Collection<DocType extends Record<string, unknown> = Record<string,

/**
* Drop an existin index
*
*
* @param name
*/
async dropIndex(name: string) {
Expand Down Expand Up @@ -448,7 +448,7 @@ function processSortOption(sort: MongooseSortOption): SortOptionInternal {
result[key] = $meta as unknown as SortDirection;
}
}

return result;
}

Expand Down
8 changes: 4 additions & 4 deletions src/driver/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class Connection extends MongooseConnection {
/**
* Helper borrowed from Mongoose to wait for the connection to finish connecting. Because Mongoose
* supports creating a new connection, registering some models, and connecting to the database later.
*
*
* #### Example:
* const conn = mongoose.createConnection();
* // This may call `createCollection()` internally depending on `autoCreate` option, even though
Expand Down Expand Up @@ -174,7 +174,7 @@ export class Connection extends MongooseConnection {
/**
* Logic for creating a connection to Data API. Mongoose calls `openUri()` internally when the
* user calls `mongoose.create()` or `mongoose.createConnection(uri)`
*
*
* @param uri the connection string
* @param options
*/
Expand Down Expand Up @@ -316,7 +316,7 @@ interface ParsedUri {
applicationToken?: string;
authHeaderName?: string;
}

// Parse a connection URI in the format of: https://${baseUrl}/${baseAPIPath}/${keyspace}?applicationToken=${applicationToken}
export const parseUri = (uri: string): ParsedUri => {
const parsedUrl = url.parse(uri, true);
Expand All @@ -342,7 +342,7 @@ export const parseUri = (uri: string): ParsedUri => {
authHeaderName
};
};

// Removes the last part of the api path (which is assumed as the keyspace name). for example below are the sample input => output from this function
// /v1/testks1 => v1
// /apis/v1/testks1 => apis/v1
Expand Down
2 changes: 1 addition & 1 deletion src/driver/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class Db {

/**
* Create a new table with the specified name and definition
* @param name
* @param name
* @param definition
*/

Expand Down
28 changes: 14 additions & 14 deletions tests/driver/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('Mongoose Model API level tests', async () => {
if (process.env.DATA_API_TABLES) {
this.skip();
return;
}
}
const modelName = 'User';
const userSchema = new mongoose.Schema({
name: String,
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('Mongoose Model API level tests', async () => {
}
let collections = await Product.db.listCollections().then(collections => collections.map(coll => coll.name));
assert.ok(collections.includes(Product.collection.collectionName));

await Product.db.dropCollection(Product.collection.collectionName);
collections = await Product.db.listCollections().then(collections => collections.map(coll => coll.name));
assert.ok(!collections.includes(Product.collection.collectionName));
Expand Down Expand Up @@ -275,7 +275,7 @@ describe('Mongoose Model API level tests', async () => {
name: 'will_drop_index',
definition: { column: 'price', options: {} },
key: { price: 1 }
}
}
]);

const droppedIndexes = await Product.cleanIndexes();
Expand All @@ -292,7 +292,7 @@ describe('Mongoose Model API level tests', async () => {
options: { ascii: false, caseSensitive: true, normalize: false }
},
key: { name: 1 }
}
}
]);

await collection.dropIndex('name');
Expand Down Expand Up @@ -352,7 +352,7 @@ describe('Mongoose Model API level tests', async () => {
},
{ message: 'Cannot use createIndex() with collections' }
);
}
}
});
it('API ops tests Model.db', async () => {
const conn = Product.db as unknown as StargateMongooseDriver.Connection;
Expand All @@ -378,7 +378,7 @@ describe('Mongoose Model API level tests', async () => {
deleteManyResp = await Product.deleteMany({});
// Deleted an unknown number of rows
assert.strictEqual(deleteManyResp.deletedCount, -1);

const count = await Product.countDocuments();
assert.strictEqual(count, 0);
});
Expand Down Expand Up @@ -446,7 +446,7 @@ describe('Mongoose Model API level tests', async () => {
assert.ok(err instanceof OperationNotSupportedError);
assert.strictEqual(err.message, 'distinct() Not Implemented');
});

it('API ops tests Model.estimatedDocumentCount()', async function() {
if (process.env.DATA_API_TABLES) {
this.skip();
Expand All @@ -456,7 +456,7 @@ describe('Mongoose Model API level tests', async () => {
const product2 = new Product({name: 'Product 2', price: 10, isCertified: true, category: 'cat 2'});
const product3 = new Product({name: 'Product 3', price: 10, isCertified: true, category: 'cat 1'});
await Product.create([product1, product2, product3]);

const count = await Product.estimatedDocumentCount();
assert.equal(typeof count, 'number');
assert.ok(count >= 0);
Expand Down Expand Up @@ -664,7 +664,7 @@ describe('Mongoose Model API level tests', async () => {
options: { ascii: false, caseSensitive: true, normalize: false }
},
key: { name: 1 }
}
}
]);
await collection.dropIndex('test_index');
} else {
Expand Down Expand Up @@ -815,7 +815,7 @@ describe('Mongoose Model API level tests', async () => {
await Product.create(product1);
//UpdateOne
await Product.updateOne({ _id: product1._id }, { $push: { tags: { name: 'Home & Garden' } } });

const { tags } = await Product.findById(product1._id).orFail();
assert.deepStrictEqual(tags.toObject(), [{ name: 'Electronics' }, { name: 'Home & Garden' }]);
});
Expand All @@ -828,7 +828,7 @@ describe('Mongoose Model API level tests', async () => {
await cart.save();
//UpdateOne
await Cart.updateOne({ _id: cart._id }, { $set: { user: { name: 'test updated subdoc' } } });

const doc = await Cart.findById(cart._id).orFail();
assert.deepStrictEqual(doc.toObject().user, { name: 'test updated subdoc' });
});
Expand Down Expand Up @@ -1048,7 +1048,7 @@ describe('Mongoose Model API level tests', async () => {
options: { ascii: false, caseSensitive: true, normalize: false }
},
key: { name: 1 }
}
}
]);

await collection.dropIndex('test_index');
Expand Down Expand Up @@ -1160,10 +1160,10 @@ describe('Mongoose Model API level tests', async () => {
.find({}, null, { includeSortVector: true })
.sort({ $vector: { $meta: [1, 99] } })
.cursor();

await once(cursor, 'cursor');
const rawCursor = (cursor as unknown as { cursor: FindCursor<unknown> }).cursor;
assert.deepStrictEqual(await rawCursor.getSortVector().then(vec => vec?.asArray()), [1, 99]);
assert.deepStrictEqual(await rawCursor.getSortVector().then(vec => vec?.asArray()), [1, 99]);
});

it('supports sort() and similarity score with $meta with findOne()', async function() {
Expand Down
6 changes: 3 additions & 3 deletions tests/driver/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('Driver based tests', async () => {
await Person.createCollection();
}
}

});

after(async () => {
Expand Down Expand Up @@ -264,7 +264,7 @@ describe('Driver based tests', async () => {

await mongooseInstance.disconnect();
});

it('handles listCollections()', async function() {
if (process.env.DATA_API_TABLES) {
this.skip();
Expand Down Expand Up @@ -294,7 +294,7 @@ describe('Driver based tests', async () => {
mongooseInstance.set('autoCreate', false);
mongooseInstance.set('autoIndex', false);
const options = isAstra ? { isAstra: true } : { username: process.env.STARGATE_USERNAME, password: process.env.STARGATE_PASSWORD };

await mongooseInstance.connect(dbUri, options);

await assert.rejects(
Expand Down
2 changes: 1 addition & 1 deletion tests/driver/tables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('tables', function() {
}
});
const User = mongooseInstance.model(modelName, userSchema, TEST_TABLE_NAME);

const employeeIdVal = new Types.ObjectId();
//generate a random uuid
const uniqueIdVal = randomUUID();
Expand Down
4 changes: 2 additions & 2 deletions tests/driver/tables.vector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ describe('tables vector search', function() {
.find({}, null, { includeSortVector: true })
.sort({ vector: { $meta: [1, 99] } })
.cursor();

await once(cursor, 'cursor');
const rawCursor = (cursor as unknown as { cursor: FindCursor<unknown> }).cursor;
assert.deepStrictEqual(await rawCursor.getSortVector().then(vec => vec?.asArray()), [1, 99]);
assert.deepStrictEqual(await rawCursor.getSortVector().then(vec => vec?.asArray()), [1, 99]);
});

it('supports sort() with $meta with find()', async function() {
Expand Down

0 comments on commit ca6ab11

Please sign in to comment.