From 31979735d67dfec919d3afd7a64522b38ccba1d6 Mon Sep 17 00:00:00 2001 From: aherlihy Date: Mon, 15 Jun 2020 19:01:36 +0200 Subject: [PATCH 1/4] eslint fixes --- package.json | 5 +- .../src/components/utils/inspect.spec.ts | 24 ++--- .../src/interpreter/interpreter.spec.ts | 54 +++++------ .../preprocessor/wrap-object-literal.spec.ts | 10 +- packages/build/.eslintignore | 4 + packages/build/.eslintrc.js | 1 + packages/cli-repl/.eslintignore | 1 + packages/cli-repl/src/arg-mapper.spec.ts | 18 ++-- packages/i18n/.eslintignore | 2 + packages/i18n/.eslintrc.js | 1 + packages/i18n/package.json | 4 +- packages/i18n/src/catalog.ts | 3 +- packages/i18n/src/translator.spec.ts | 2 +- packages/i18n/src/translator.ts | 5 +- .../service-provider-browser/.eslintignore | 4 + .../service-provider-browser/.eslintrc.js | 1 + .../service-provider-browser/package.json | 4 +- .../src/stitch-client.ts | 4 +- .../src/stitch-mongo-client.ts | 3 +- ...rvice-provider-browser.integration.spec.ts | 13 +-- .../src/stitch-service-provider-browser.ts | 92 ++++++++----------- .../src/stitch-transport.spec.ts | 34 +++---- .../src/stitch-transport.ts | 56 +++++------ .../src/unsupported-cursor.ts | 61 ++++++------ packages/service-provider-core/.eslintignore | 2 + packages/service-provider-core/.eslintrc.js | 1 + packages/service-provider-core/package.json | 4 +- packages/service-provider-core/src/admin.ts | 4 +- .../src/bulk-write-result.ts | 8 +- .../service-provider-core/src/closable.ts | 2 +- .../src/command-options.ts | 4 +- packages/service-provider-core/src/cursor.ts | 5 +- .../src/database-options.ts | 8 +- .../service-provider-core/src/document.ts | 8 +- packages/service-provider-core/src/index.ts | 2 +- .../src/read-preference.ts | 4 +- .../service-provider-core/src/readable.ts | 16 ++-- packages/service-provider-core/src/result.ts | 1 + .../src/service-provider.ts | 4 +- .../service-provider-core/src/writable.ts | 44 +++++---- packages/shell-api/src/shell-bson.ts | 14 +-- .../src/shell-evaluator.spec.ts | 2 +- 42 files changed, 267 insertions(+), 272 deletions(-) create mode 100644 packages/build/.eslintignore create mode 100644 packages/build/.eslintrc.js create mode 100644 packages/i18n/.eslintignore create mode 100644 packages/i18n/.eslintrc.js create mode 100644 packages/service-provider-browser/.eslintignore create mode 100644 packages/service-provider-browser/.eslintrc.js create mode 100644 packages/service-provider-core/.eslintignore create mode 100644 packages/service-provider-core/.eslintrc.js diff --git a/package.json b/package.json index 8a5424648f..349b3280ad 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,8 @@ "prebootstrap": "npm install", "bootstrap": "lerna bootstrap", "clean": "lerna clean -y && rm -Rf node_modules", - "check": "echo", - "check-ci": "echo", - "lint": "lerna run check --since HEAD --exclude-dependents", + "check": "lerna run check --since HEAD --exclude-dependents", + "check-ci": "lerna run check", "test": "lerna run test", "test-ci": "lerna run test-ci", "compile-ts": "lerna run compile-ts", diff --git a/packages/browser-repl/src/components/utils/inspect.spec.ts b/packages/browser-repl/src/components/utils/inspect.spec.ts index ae9203da64..b82d74273c 100644 --- a/packages/browser-repl/src/components/utils/inspect.spec.ts +++ b/packages/browser-repl/src/components/utils/inspect.spec.ts @@ -38,18 +38,18 @@ describe('inspect', () => { ).to.equal('undefined'); }); - it.skip('inspects Symbol', () => { - expect( - inspect(Symbol('123')) - ).to.equal('Symbol(123)'); - }); - - it.skip('inspects BigInt', () => { - expect( - // eslint-disable-next-line no-undef - inspect(BigInt(1)) - ).to.equal('1n'); - }); + // it('inspects Symbol', () => { + // expect( + // inspect(Symbol('123')) + // ).to.equal('Symbol(123)'); + // }); + // + // it('inspects BigInt', () => { + // expect( + // // eslint-disable-next-line no-undef + // inspect(BigInt(1)) + // ).to.equal('1n'); + // }); }); context('with BSON types', () => { diff --git a/packages/browser-runtime-core/src/interpreter/interpreter.spec.ts b/packages/browser-runtime-core/src/interpreter/interpreter.spec.ts index 81a17a7c5f..3e64d2f16e 100644 --- a/packages/browser-runtime-core/src/interpreter/interpreter.spec.ts +++ b/packages/browser-runtime-core/src/interpreter/interpreter.spec.ts @@ -71,15 +71,15 @@ describe('Interpreter', () => { ).to.deep.equal({ x: 1 }); }); - it.skip('evaluates object literal after other statements as block', async() => { - // TODO: for some reason this is the default behaviour in node repl and devtools, - // as is now it wraps everything, which breaks the code. - expect( - await testEvaluate( - ';{x: 1}' - ) - ).to.equal(1); - }); + // it('evaluates object literal after other statements as block', async() => { + // // TODO: for some reason this is the default behaviour in node repl and devtools, + // // as is now it wraps everything, which breaks the code. + // expect( + // await testEvaluate( + // ';{x: 1}' + // ) + // ).to.equal(1); + // }); it('can declare a top level variable with let', async() => { expect( @@ -159,24 +159,24 @@ describe('Interpreter', () => { ).to.equal(3); }); - it.skip('can redeclare a top level function as function', async() => { - expect( - await testEvaluate( - 'function f() { return 1; }', - 'function f() { return 2; }', - 'f()' - ) - ).to.equal(2); - }); - - it.skip('can redeclare a top level function as var', async() => { - expect( - await testEvaluate( - 'function sum(a, b) { return a + b; }', - 'var sum = 1' - ) - ).to.equal(1); - }); + // it('can redeclare a top level function as function', async() => { + // expect( + // await testEvaluate( + // 'function f() { return 1; }', + // 'function f() { return 2; }', + // 'f()' + // ) + // ).to.equal(2); + // }); + // + // it('can redeclare a top level function as var', async() => { + // expect( + // await testEvaluate( + // 'function sum(a, b) { return a + b; }', + // 'var sum = 1' + // ) + // ).to.equal(1); + // }); it('cannot re-declare a top level function as let', async() => { const error = await testEvaluate( diff --git a/packages/browser-runtime-core/src/interpreter/preprocessor/wrap-object-literal.spec.ts b/packages/browser-runtime-core/src/interpreter/preprocessor/wrap-object-literal.spec.ts index 51f211c1bc..15e8e95369 100644 --- a/packages/browser-runtime-core/src/interpreter/preprocessor/wrap-object-literal.spec.ts +++ b/packages/browser-runtime-core/src/interpreter/preprocessor/wrap-object-literal.spec.ts @@ -18,10 +18,10 @@ describe('wrapObjectLiteral', () => { expect(wrapObjectLiteral('\n {x: 2} \n ')).to.equal('(\n {x: 2} \n )'); }); - it.skip('should not wrap multiple statements', () => { - // TODO: for some reason this is the default behaviour in node repl and devtools, - // as is now it wraps everything, which breaks the code. - expect(wrapObjectLiteral('{x: 2}; {x: 2}')).to.equal('{x: 2}; {x: 2}'); - }); + // it('should not wrap multiple statements', () => { + // // TODO: for some reason this is the default behaviour in node repl and devtools, + // // as is now it wraps everything, which breaks the code. + // expect(wrapObjectLiteral('{x: 2}; {x: 2}')).to.equal('{x: 2}; {x: 2}'); + // }); }); diff --git a/packages/build/.eslintignore b/packages/build/.eslintignore new file mode 100644 index 0000000000..c176f20c35 --- /dev/null +++ b/packages/build/.eslintignore @@ -0,0 +1,4 @@ +node_modules +lib +coverage + diff --git a/packages/build/.eslintrc.js b/packages/build/.eslintrc.js new file mode 100644 index 0000000000..4a958b44bd --- /dev/null +++ b/packages/build/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('../../config/eslintrc.base'); diff --git a/packages/cli-repl/.eslintignore b/packages/cli-repl/.eslintignore index ea3f37f224..f7ace5541d 100644 --- a/packages/cli-repl/.eslintignore +++ b/packages/cli-repl/.eslintignore @@ -1,3 +1,4 @@ node_modules bin lib +dist diff --git a/packages/cli-repl/src/arg-mapper.spec.ts b/packages/cli-repl/src/arg-mapper.spec.ts index f154904b43..e045eed374 100644 --- a/packages/cli-repl/src/arg-mapper.spec.ts +++ b/packages/cli-repl/src/arg-mapper.spec.ts @@ -23,15 +23,15 @@ describe('arg-mapper.mapCliToDriver', () => { }); }); - context('when cli args have disableImplicitSessions', () => { - const cliOptions: CliOptions = { disableImplicitSessions: true }; - - it.skip('maps to explicitlyIgnoreSession', () => { - expect(mapCliToDriver(cliOptions)).to.deep.equal({ - explicitlyIgnoreSession: true - }); - }); - }); + // context('when cli args have disableImplicitSessions', () => { + // const cliOptions: CliOptions = { disableImplicitSessions: true }; + // + // it('maps to explicitlyIgnoreSession', () => { + // expect(mapCliToDriver(cliOptions)).to.deep.equal({ + // explicitlyIgnoreSession: true + // }); + // }); + // }); context('when cli args have quiet', () => { const cliOptions: CliOptions = { quiet: true }; diff --git a/packages/i18n/.eslintignore b/packages/i18n/.eslintignore new file mode 100644 index 0000000000..491fc35975 --- /dev/null +++ b/packages/i18n/.eslintignore @@ -0,0 +1,2 @@ +node_modules +lib diff --git a/packages/i18n/.eslintrc.js b/packages/i18n/.eslintrc.js new file mode 100644 index 0000000000..4a958b44bd --- /dev/null +++ b/packages/i18n/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('../../config/eslintrc.base'); diff --git a/packages/i18n/package.json b/packages/i18n/package.json index 904ef21c60..d2fb3217a3 100644 --- a/packages/i18n/package.json +++ b/packages/i18n/package.json @@ -15,7 +15,9 @@ "compile-ts": "tsc -p tsconfig.json", "prepublish": "npm run compile-ts", "test": "mocha --timeout 60000 --colors -r ts-node/register \"./src/**/*.spec.ts\"", - "test-ci": "mocha --timeout 60000 -r ts-node/register \"./src/**/*.spec.ts\"" + "test-ci": "mocha --timeout 60000 -r ts-node/register \"./src/**/*.spec.ts\"", + "lint": "eslint \"**/*.{js,ts,tsx}\"", + "check": "npm run lint" }, "license": "Apache-2.0", "publishConfig": { diff --git a/packages/i18n/src/catalog.ts b/packages/i18n/src/catalog.ts index 54901cb320..16cf712555 100644 --- a/packages/i18n/src/catalog.ts +++ b/packages/i18n/src/catalog.ts @@ -1,5 +1,4 @@ -interface Catalog { +export default interface Catalog { [prop: string]: any; } -export default Catalog; diff --git a/packages/i18n/src/translator.spec.ts b/packages/i18n/src/translator.spec.ts index fd2797a861..c4bd340299 100644 --- a/packages/i18n/src/translator.spec.ts +++ b/packages/i18n/src/translator.spec.ts @@ -75,7 +75,7 @@ describe('Translator', () => { }); context('when the key uses object notation', () => { - const translator = new Translator({ test: { test: 'value' }}); + const translator = new Translator({ test: { test: 'value' } }); context('when the key is found', () => { it('returns the translation', () => { diff --git a/packages/i18n/src/translator.ts b/packages/i18n/src/translator.ts index fe81823a22..66df0a3a67 100644 --- a/packages/i18n/src/translator.ts +++ b/packages/i18n/src/translator.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/camelcase */ import Mustache from 'mustache'; import Catalog from './catalog'; import en_US from './locales/en_US'; @@ -60,7 +61,7 @@ class Translator { * * @param {string} locale - The locale. */ - setLocale(locale: string) { + setLocale(locale: string): void { if (MAPPINGS.hasOwnProperty(locale)) { this.locale = locale; this.catalog = MAPPINGS[locale]; @@ -100,7 +101,7 @@ class Translator { return Mustache.render(TEMPLATE, value); } - private find(key) { + private find(key): any { return key.split('.').reduce((a, b) => { return a ? a[b] : undefined; }, this.catalog); diff --git a/packages/service-provider-browser/.eslintignore b/packages/service-provider-browser/.eslintignore new file mode 100644 index 0000000000..c176f20c35 --- /dev/null +++ b/packages/service-provider-browser/.eslintignore @@ -0,0 +1,4 @@ +node_modules +lib +coverage + diff --git a/packages/service-provider-browser/.eslintrc.js b/packages/service-provider-browser/.eslintrc.js new file mode 100644 index 0000000000..4a958b44bd --- /dev/null +++ b/packages/service-provider-browser/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('../../config/eslintrc.base'); diff --git a/packages/service-provider-browser/package.json b/packages/service-provider-browser/package.json index 2c4ff95f7e..03e3094728 100644 --- a/packages/service-provider-browser/package.json +++ b/packages/service-provider-browser/package.json @@ -15,7 +15,9 @@ "compile-ts": "tsc -p tsconfig.json", "test": "karma start --colors", "test-ci": "karma start --colors", - "prepublish": "npm run compile-ts" + "prepublish": "npm run compile-ts", + "lint": "eslint \"**/*.{js,ts,tsx}\"", + "check": "npm run lint" }, "license": "Apache-2.0", "publishConfig": { diff --git a/packages/service-provider-browser/src/stitch-client.ts b/packages/service-provider-browser/src/stitch-client.ts index 73eae9c08c..61338ed97e 100644 --- a/packages/service-provider-browser/src/stitch-client.ts +++ b/packages/service-provider-browser/src/stitch-client.ts @@ -2,8 +2,6 @@ * Defines behaviour common to both the Stitch server and browser * client APIs. */ -interface StitchClient { +export default interface StitchClient { auth: any; } - -export default StitchClient; diff --git a/packages/service-provider-browser/src/stitch-mongo-client.ts b/packages/service-provider-browser/src/stitch-mongo-client.ts index 94355428bc..42b916d74d 100644 --- a/packages/service-provider-browser/src/stitch-mongo-client.ts +++ b/packages/service-provider-browser/src/stitch-mongo-client.ts @@ -2,8 +2,7 @@ * Defines behaviour common to both the Stitch server and browser * mongo client APIs. */ -interface StitchMongoClient { +export default interface StitchMongoClient { db(name: string): any; } -export default StitchMongoClient; diff --git a/packages/service-provider-browser/src/stitch-service-provider-browser.integration.spec.ts b/packages/service-provider-browser/src/stitch-service-provider-browser.integration.spec.ts index 7c34bfb855..64e11f5f85 100644 --- a/packages/service-provider-browser/src/stitch-service-provider-browser.integration.spec.ts +++ b/packages/service-provider-browser/src/stitch-service-provider-browser.integration.spec.ts @@ -20,6 +20,7 @@ describe('StitchServiceProviderBrowser [ integration ]', function() { before(async() => { stitchTransport = await StitchServiceProviderBrowser.fromAppId(stitchAppId, serviceName); + // eslint-disable-next-line @typescript-eslint/camelcase testScope = { testId: testId, owner_id: stitchTransport.userId }; }); @@ -35,7 +36,7 @@ describe('StitchServiceProviderBrowser [ integration ]', function() { beforeEach(async() => { result = await stitchTransport. - aggregate('music', 'bands', [{ $match: { ...testScope, name: 'Aphex Twin' }}]); + aggregate('music', 'bands', [{ $match: { ...testScope, name: 'Aphex Twin' } }]); }); it('executes the command and resolves the result', async() => { @@ -45,8 +46,8 @@ describe('StitchServiceProviderBrowser [ integration ]', function() { }); context('when running against a database', () => { - it.skip('it rejects the action', () => { - return stitchTransport.aggregate('admin', null, [{ $currentOp: {}}]).catch((err) => { + it('it rejects the action', () => { + return stitchTransport.aggregate('admin', null, [{ $currentOp: {} }]).catch((err) => { expect(err).to.not.equal(null); }); }); @@ -181,7 +182,7 @@ describe('StitchServiceProviderBrowser [ integration ]', function() { beforeEach(async() => { const filter = { ...testScope, name: 'Aphex Twin' }; - const update = { $set: { name: 'Richard James' }}; + const update = { $set: { name: 'Richard James' } }; result = await stitchTransport. findOneAndUpdate('music', 'bands', filter, update); @@ -253,7 +254,7 @@ describe('StitchServiceProviderBrowser [ integration ]', function() { beforeEach(async() => { const filter = { ...testScope, name: 'Aphex Twin' }; - const update = { $set: { name: 'Richard James' }}; + const update = { $set: { name: 'Richard James' } }; result = await stitchTransport. updateMany('music', 'bands', filter, update); @@ -271,7 +272,7 @@ describe('StitchServiceProviderBrowser [ integration ]', function() { beforeEach(async() => { const filter = { ...testScope, name: 'Aphex Twin' }; - const update = { $set: { name: 'Richard James' }}; + const update = { $set: { name: 'Richard James' } }; result = await stitchTransport. updateOne('music', 'bands', filter, update); diff --git a/packages/service-provider-browser/src/stitch-service-provider-browser.ts b/packages/service-provider-browser/src/stitch-service-provider-browser.ts index 121f8cb85f..621535476c 100644 --- a/packages/service-provider-browser/src/stitch-service-provider-browser.ts +++ b/packages/service-provider-browser/src/stitch-service-provider-browser.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { ServiceProvider, Result, @@ -52,8 +53,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { */ static async fromAppId( stitchAppId: string, - serviceName: string) : Promise { - + serviceName: string): Promise { const client = Stitch.initializeDefaultAppClient(stitchAppId); try { await client.auth.loginWithCredential(new AnonymousCredential()); @@ -64,7 +64,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { return new StitchServiceProviderBrowser(client, serviceName); } - async getNewConnection(uri, options) { + async getNewConnection(uri, options): Promise { throw new MongoshUnimplementedError(); } @@ -106,8 +106,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { aggregate( database: string, collection: string, - pipeline: object[] = []) : Cursor { - + pipeline: object[] = []): Cursor { return this.stitchTransport.aggregate(database, collection, pipeline); } @@ -116,7 +115,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { * * @returns {Promise} The rejected promise. */ - bulkWrite() : Promise { + bulkWrite(): Promise { return this.stitchTransport.bulkWrite(); } @@ -134,8 +133,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { database: string, collection: string, filter: object = {}, - options: object = {}) : Promise { - + options: object = {}): Promise { return this.stitchTransport.countDocuments(database, collection, filter, options); } @@ -156,71 +154,71 @@ class StitchServiceProviderBrowser implements ServiceProvider { } aggregateDb(database: string, pipeline: Document[], options?: Document, dbOptions?: DatabaseOptions): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } count(db: string, coll: string, query?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } isCapped(database: string, collection: string, dbOptions?: DatabaseOptions): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } getIndexes(database: string, collection: string, dbOptions?: DatabaseOptions): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } listCollections(database: string, filter?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } stats(database: string, collection: string, options?: Document, dbOptions?: DatabaseOptions): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } dropDatabase(database: string, writeConcern?: WriteConcern, dbOptions?: DatabaseOptions): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } - findAndModify(database: string, collection: string, query: Document, sort: any[] | Document, update: Document, options?: Document, dbOptions?: DatabaseOptions) { - throw new Error("Method not implemented."); + findAndModify(database: string, collection: string, query: Document, sort: any[] | Document, update: Document, options?: Document, dbOptions?: DatabaseOptions): Promise { + throw new Error('Method not implemented.'); } save(database: string, collection: string, doc: Document, options?: Document, dbOptions?: DatabaseOptions): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } remove(database: string, collection: string, query: Document, options?: Document, dbOptions?: DatabaseOptions): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } convertToCapped(database: string, collection: string, size: number, options?: CommandOptions): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } createIndexes(database: string, collection: string, indexSpecs: Document[], options?: Document, dbOptions?: DatabaseOptions): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } dropIndexes(database: string, collection: string, indexes: string | Document | Document[] | string[], commandOptions?: CommandOptions, dbOptions?: DatabaseOptions): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } reIndex(database: string, collection: string, options?: CommandOptions, dbOptions?: DatabaseOptions): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } dropCollection(database: string, collection: string, dbOptions?: DatabaseOptions): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } renameCollection(database: string, oldName: string, newName: string, options?: Document, dbOptions?: DatabaseOptions): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } close(boolean: any): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } getCmdLineOpts(): Promise { @@ -236,7 +234,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { } listDatabases(database: string): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } /** @@ -252,8 +250,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { deleteMany( database: string, collection: string, - filter: object = {}) : Promise { - + filter: object = {}): Promise { return this.stitchTransport.deleteMany(database, collection, filter); } @@ -270,8 +267,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { deleteOne( database: string, collection: string, - filter: object = {}) : Promise { - + filter: object = {}): Promise { return this.stitchTransport.deleteOne(database, collection, filter); } @@ -280,7 +276,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { * * @returns {Cursor} The unsupported cursor. */ - distinct() : Promise { + distinct(): Promise { return this.stitchTransport.distinct(); } @@ -289,7 +285,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { * * @returns {Promise} The rejected promise. */ - estimatedDocumentCount() : Promise { + estimatedDocumentCount(): Promise { return this.stitchTransport.estimatedDocumentCount(); } @@ -307,8 +303,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { database: string, collection: string, filter: object = {}, - options: object = {}) : any { - + options: object = {}): any { return this.stitchTransport.find(database, collection, filter, options); } @@ -326,8 +321,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { database: string, collection: string, filter: object = {}, - options: object = {}) : Promise { - + options: object = {}): Promise { return this.stitchTransport.findOneAndDelete(database, collection, filter, options); } @@ -347,8 +341,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { collection: string, filter: object = {}, replacement: object = {}, - options: object = {}) : Promise { - + options: object = {}): Promise { return this.stitchTransport.findOneAndReplace(database, collection, filter, replacement, options); } @@ -368,8 +361,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { collection: string, filter: object = {}, update: object = {}, - options: object = {}) : Promise { - + options: object = {}): Promise { return this.stitchTransport.findOneAndUpdate(database, collection, filter, update, options); } @@ -387,8 +379,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { database: string, collection: string, docs: object[] = [], - options: object = {}) : Promise { - + options: object = {}): Promise { return this.stitchTransport.insertMany(database, collection, docs); } @@ -406,8 +397,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { database: string, collection: string, doc: object = {}, - options: object = {}) : Promise { - + options: object = {}): Promise { return this.stitchTransport.insertOne(database, collection, doc); } @@ -416,7 +406,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { * * @returns {Promise} The rejected promise. */ - replaceOne() : Promise { + replaceOne(): Promise { return this.stitchTransport.replaceOne(); } @@ -425,7 +415,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { * * @returns {Promise} The rejected promise. */ - runCommand() : Promise { + runCommand(): Promise { return this.stitchTransport.runCommand(); } @@ -445,8 +435,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { collection: string, filter: object = {}, update: object = {}, - options: object = {}) : Promise { - + options: object = {}): Promise { return this.stitchTransport.updateMany(database, collection, filter, update, options); } @@ -466,8 +455,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { collection: string, filter: object = {}, update: object = {}, - options: object = {}) : Promise { - + options: object = {}): Promise { return this.stitchTransport.updateOne(database, collection, filter, update, options); } @@ -476,7 +464,7 @@ class StitchServiceProviderBrowser implements ServiceProvider { * * @returns {String} The user id. */ - get userId() : string { + get userId(): string { return this.stitchTransport.userId; } } diff --git a/packages/service-provider-browser/src/stitch-transport.spec.ts b/packages/service-provider-browser/src/stitch-transport.spec.ts index 3d6bcf1d47..7e0301367d 100644 --- a/packages/service-provider-browser/src/stitch-transport.spec.ts +++ b/packages/service-provider-browser/src/stitch-transport.spec.ts @@ -16,7 +16,7 @@ import StitchMongoClient from './stitch-mongo-client'; * * @returns {Stub} The client stub to pass to the transport. */ -const createClientStub = (collectionStub) => { +const createClientStub = (collectionStub): any => { const dbStub = { collection: sinon.stub().returns(collectionStub) }; @@ -25,8 +25,8 @@ const createClientStub = (collectionStub) => { }; }; -const createStitchClientStub = (): StitchClient => ({auth: null}); -const createMongoClientStub = (): StitchMongoClient => ({db: () => {}}); +const createStitchClientStub = (): StitchClient => ({ auth: null }); +const createMongoClientStub = (): StitchMongoClient => ({ db: (): void => {} }); describe('StitchTransport', () => { const stitchClient = createStitchClientStub(); @@ -46,7 +46,7 @@ describe('StitchTransport', () => { describe('#aggregate', () => { let stitchTransport; - const pipeline = [{ $match: { name: 'Aphex Twin' }}]; + const pipeline = [{ $match: { name: 'Aphex Twin' } }]; const aggResult = [{ name: 'Aphex Twin' }]; const aggMock = sinon.mock().withArgs(pipeline). @@ -73,7 +73,7 @@ describe('StitchTransport', () => { describe('#bulkWrite', () => { let stitchTransport; - const requests = [{ insertOne: { name: 'Aphex Twin' }}]; + const requests = [{ insertOne: { name: 'Aphex Twin' } }]; beforeEach(() => { stitchTransport = new StitchTransport(stitchClient, createClientStub({})); @@ -115,7 +115,7 @@ describe('StitchTransport', () => { describe('#deleteMany', () => { let stitchTransport; - const commandResult = { result: { n: 1, ok: 1 }}; + const commandResult = { result: { n: 1, ok: 1 } }; const deleteMock = sinon.mock().once().withArgs({}).resolves(commandResult); beforeEach(() => { @@ -138,7 +138,7 @@ describe('StitchTransport', () => { describe('#deleteOne', () => { let stitchTransport; - const commandResult = { result: { n: 1, ok: 1 }}; + const commandResult = { result: { n: 1, ok: 1 } }; const deleteMock = sinon.mock().once().withArgs({}).resolves(commandResult); beforeEach(() => { @@ -223,7 +223,7 @@ describe('StitchTransport', () => { describe('#findOneAndDelete', () => { let stitchTransport; - const commandResult = { result: { n: 1, ok: 1 }}; + const commandResult = { result: { n: 1, ok: 1 } }; const findMock = sinon.mock().once().withArgs({}).resolves(commandResult); beforeEach(() => { @@ -246,7 +246,7 @@ describe('StitchTransport', () => { describe('#findOneAndReplace', () => { let stitchTransport; - const commandResult = { result: { n: 1, ok: 1 }}; + const commandResult = { result: { n: 1, ok: 1 } }; const filter = { name: 'Aphex Twin' }; const replacement = { name: 'Richard James' }; const findMock = sinon.mock().once().withArgs(filter, replacement). @@ -273,9 +273,9 @@ describe('StitchTransport', () => { describe('#findOneAndUpdate', () => { let stitchTransport; - const commandResult = { result: { n: 1, ok: 1 }}; + const commandResult = { result: { n: 1, ok: 1 } }; const filter = { name: 'Aphex Twin' }; - const update = { $set: { name: 'Richard James' }}; + const update = { $set: { name: 'Richard James' } }; const findMock = sinon.mock().once().withArgs(filter, update). resolves(commandResult); @@ -301,7 +301,7 @@ describe('StitchTransport', () => { describe('#insertMany', () => { let stitchTransport; const doc = { name: 'Aphex Twin' }; - const commandResult = { result: { n: 1, ok: 1 }}; + const commandResult = { result: { n: 1, ok: 1 } }; const insertMock = sinon.mock().once().withArgs([ doc ]).resolves(commandResult); beforeEach(() => { @@ -325,7 +325,7 @@ describe('StitchTransport', () => { describe('#insertOne', () => { let stitchTransport; const doc = { name: 'Aphex Twin' }; - const commandResult = { result: { n: 1, ok: 1 }}; + const commandResult = { result: { n: 1, ok: 1 } }; const insertMock = sinon.mock().once().withArgs(doc).resolves(commandResult); beforeEach(() => { @@ -387,8 +387,8 @@ describe('StitchTransport', () => { describe('#updateOne', () => { let stitchTransport; const filter = { name: 'Aphex Twin' }; - const update = { $set: { name: 'Richard James' }}; - const commandResult = { result: { n: 1, ok: 1 }}; + const update = { $set: { name: 'Richard James' } }; + const commandResult = { result: { n: 1, ok: 1 } }; const updateMock = sinon.mock().once().withArgs(filter, update). resolves(commandResult); @@ -413,8 +413,8 @@ describe('StitchTransport', () => { describe('#updateMany', () => { let stitchTransport; const filter = { name: 'Aphex Twin' }; - const update = { $set: { name: 'Richard James' }}; - const commandResult = { result: { n: 1, ok: 1 }}; + const update = { $set: { name: 'Richard James' } }; + const commandResult = { result: { n: 1, ok: 1 } }; const updateMock = sinon.mock().once().withArgs(filter, update). resolves(commandResult); diff --git a/packages/service-provider-browser/src/stitch-transport.ts b/packages/service-provider-browser/src/stitch-transport.ts index 1840137cde..af1b97fdea 100644 --- a/packages/service-provider-browser/src/stitch-transport.ts +++ b/packages/service-provider-browser/src/stitch-transport.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import i18n from '@mongosh/i18n'; import StitchClient from './stitch-client'; @@ -31,15 +32,13 @@ class StitchTransport { * @param {String} database - The database name. * @param {String} collection - The collection name. * @param {Array} pipeline - The aggregation pipeline. - * @param {Document} options - The pipeline options. * * @returns {Cursor} The aggregation cursor. */ aggregate( database: string, collection: string, - pipeline: Document[] = []) : Cursor { - + pipeline: Document[] = []): Cursor { if (collection === null) { return new UnsupportedCursor(i18n.__(AGG_ON_DB)); } @@ -52,7 +51,7 @@ class StitchTransport { * * @returns {Promise} The rejected promise. */ - bulkWrite() : Promise { + bulkWrite(): Promise { return Promise.reject(`Bulk write ${i18n.__(NOT_IMPLEMENTED)}`); } @@ -70,8 +69,7 @@ class StitchTransport { database: string, collection: string, filter: Document = {}, - options: Document = {}) : Promise { - + options: Document = {}): Promise { return this.db(database).collection(collection).count(filter, options); } @@ -93,15 +91,13 @@ class StitchTransport { * @param {String} database - The database name. * @param {String} collection - The collection name. * @param {Document} filter - The filter. - * @param {Document} options - The delete many options. * * @returns {Promise} The promise of the result. */ deleteMany( database: string, collection: string, - filter: Document = {}) : Promise { - + filter: Document = {}): Promise { return this.db(database).collection(collection). deleteMany(filter); } @@ -112,15 +108,13 @@ class StitchTransport { * @param {String} database - The database name. * @param {String} collection - The collection name. * @param {Document} filter - The filter. - * @param {Document} options - The delete one options. * * @returns {Promise} The promise of the result. */ deleteOne( database: string, collection: string, - filter: Document = {}) : Promise { - + filter: Document = {}): Promise { return this.db(database).collection(collection). deleteOne(filter); } @@ -130,7 +124,7 @@ class StitchTransport { * * @returns {Cursor} The rejected promise when toArray is called. */ - distinct() : Promise { + distinct(): Promise { return Promise.resolve(new UnsupportedCursor(`Distinct ${i18n.__(NOT_IMPLEMENTED)}`)); } @@ -139,7 +133,7 @@ class StitchTransport { * * @returns {Promise} The rejected promise. */ - estimatedDocumentCount() : Promise { + estimatedDocumentCount(): Promise { return Promise.reject(`Estimated document count ${i18n.__(NOT_IMPLEMENTED)}`); } @@ -157,8 +151,7 @@ class StitchTransport { database: string, collection: string, filter: Document = {}, - options: Document = {}) : Cursor { - + options: Document = {}): Cursor { return this.db(database).collection(collection). find(filter, options); } @@ -177,8 +170,7 @@ class StitchTransport { database: string, collection: string, filter: Document = {}, - options: Document = {}) : Promise { - + options: Document = {}): Promise { return this.db(database).collection(collection). findOneAndDelete(filter, options); } @@ -199,8 +191,7 @@ class StitchTransport { collection: string, filter: Document = {}, replacement: Document = {}, - options: Document = {}) : Promise { - + options: Document = {}): Promise { return this.db(database).collection(collection). findOneAndReplace(filter, replacement, options); } @@ -221,8 +212,7 @@ class StitchTransport { collection: string, filter: Document = {}, update: Document = {}, - options: Document = {}) : Promise { - + options: Document = {}): Promise { return this.db(database).collection(collection). findOneAndUpdate(filter, update, options); } @@ -241,8 +231,7 @@ class StitchTransport { database: string, collection: string, docs: Document[] = [], - options: Document = {}) : Promise { - + options: Document = {}): Promise { return this.db(database).collection(collection). insertMany(docs); } @@ -261,8 +250,7 @@ class StitchTransport { database: string, collection: string, doc: Document = {}, - options: Document = {}) : Promise { - + options: Document = {}): Promise { return this.db(database).collection(collection). insertOne(doc); } @@ -272,7 +260,7 @@ class StitchTransport { * * @returns {Promise} The rejected promise. */ - replaceOne() : Promise { + replaceOne(): Promise { return Promise.reject(`Replace one ${i18n.__(NOT_IMPLEMENTED)}`); } @@ -281,7 +269,7 @@ class StitchTransport { * * @returns {Promise} The rejected promise. */ - runCommand() : Promise { + runCommand(): Promise { return Promise.reject(`Running a direct command ${i18n.__(NOT_IMPLEMENTED)}`); } @@ -301,8 +289,7 @@ class StitchTransport { collection: string, filter: Document = {}, update: Document = {}, - options: Document = {}) : Promise { - + options: Document = {}): Promise { return this.db(database).collection(collection). updateMany(filter, update, options); } @@ -323,8 +310,7 @@ class StitchTransport { collection: string, filter: Document = {}, update: Document = {}, - options: Document = {}) : Promise { - + options: Document = {}): Promise { return this.db(database).collection(collection). updateOne(filter, update, options); } @@ -334,7 +320,7 @@ class StitchTransport { * * @returns {String} The user id. */ - get userId() : string { + get userId(): string { return this.stitchClient.auth.user.id; } @@ -343,9 +329,9 @@ class StitchTransport { * * @param {String} name - The database name. * - * @returns {RemoteMongoDaatabase} The database. + * @returns {RemoteMongoDatabase} The database. */ - private db(name: string) { + private db(name: string): any { return this.mongoClient.db(name); } } diff --git a/packages/service-provider-browser/src/unsupported-cursor.ts b/packages/service-provider-browser/src/unsupported-cursor.ts index fa8b24e6b2..5a4be2ac43 100644 --- a/packages/service-provider-browser/src/unsupported-cursor.ts +++ b/packages/service-provider-browser/src/unsupported-cursor.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { Document, Cursor } from '@mongosh/service-provider-core'; /** @@ -16,123 +17,123 @@ class UnsupportedCursor implements Cursor { } addOption(option: number): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } allowPartialResults(): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } batchSize(size: number): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } close(options: Document): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } clone(): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } isClosed(): boolean { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } collation(spec: Document): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } comment(cmt: string): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } count(): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } forEach(f: any): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } hasNext(): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } hint(index: string): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } isExhausted(): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } itcount(): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } limit(value: number): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } map(f: any): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } max(indexBounds: Document): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } maxTimeMS(value: number): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } min(indexBounds: Document): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } next(): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } noCursorTimeout(): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } oplogReplay(): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } projection(spec: Document): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } readPref(preference: string, tagSet?: Document[]): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } returnKey(enabled: boolean): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } size(): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } skip(value: number): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } sort(spec: Document): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } tailable(): Cursor { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } explain(verbosity: string): Promise { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } /** diff --git a/packages/service-provider-core/.eslintignore b/packages/service-provider-core/.eslintignore new file mode 100644 index 0000000000..491fc35975 --- /dev/null +++ b/packages/service-provider-core/.eslintignore @@ -0,0 +1,2 @@ +node_modules +lib diff --git a/packages/service-provider-core/.eslintrc.js b/packages/service-provider-core/.eslintrc.js new file mode 100644 index 0000000000..4a958b44bd --- /dev/null +++ b/packages/service-provider-core/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('../../config/eslintrc.base'); diff --git a/packages/service-provider-core/package.json b/packages/service-provider-core/package.json index 9be9603da9..3e2d449ce5 100644 --- a/packages/service-provider-core/package.json +++ b/packages/service-provider-core/package.json @@ -13,7 +13,9 @@ }, "scripts": { "compile-ts": "tsc -p tsconfig.json", - "prepublish": "npm run compile-ts" + "prepublish": "npm run compile-ts", + "lint": "eslint \"**/*.{js,ts,tsx}\"", + "check": "npm run lint" }, "license": "Apache-2.0", "publishConfig": { diff --git a/packages/service-provider-core/src/admin.ts b/packages/service-provider-core/src/admin.ts index 5a8f0a5dfa..35fa068695 100644 --- a/packages/service-provider-core/src/admin.ts +++ b/packages/service-provider-core/src/admin.ts @@ -1,5 +1,5 @@ -import Result from "./result"; -import { ReplPlatform } from "./platform"; +import Result from './result'; +import { ReplPlatform } from './platform'; export default interface Admin { /** diff --git a/packages/service-provider-core/src/bulk-write-result.ts b/packages/service-provider-core/src/bulk-write-result.ts index 23c13649bf..9e58968499 100644 --- a/packages/service-provider-core/src/bulk-write-result.ts +++ b/packages/service-provider-core/src/bulk-write-result.ts @@ -1,6 +1,6 @@ export default interface BulkWriteResult { result: { - ok: number + ok: number; }; /** @@ -31,10 +31,10 @@ export default interface BulkWriteResult { /** * Ids of upserted documents. */ - upsertedIds: {[index: number]: any} + upsertedIds: {[index: number]: any}; /** * Ids of inserted documents. */ - insertedIds: {[index: number]: any} -} \ No newline at end of file + insertedIds: {[index: number]: any}; +} diff --git a/packages/service-provider-core/src/closable.ts b/packages/service-provider-core/src/closable.ts index dbdd086031..c3fb5464c6 100644 --- a/packages/service-provider-core/src/closable.ts +++ b/packages/service-provider-core/src/closable.ts @@ -5,4 +5,4 @@ export default interface Closable { * @param {boolean} force - Whether to force close. */ close(boolean): Promise; -} \ No newline at end of file +} diff --git a/packages/service-provider-core/src/command-options.ts b/packages/service-provider-core/src/command-options.ts index 2e07e4ea83..7b849437cd 100644 --- a/packages/service-provider-core/src/command-options.ts +++ b/packages/service-provider-core/src/command-options.ts @@ -1,5 +1,5 @@ -import WriteConcern from "./write-concern"; +import WriteConcern from './write-concern'; export default interface CommandOptions { - writeConcern?: WriteConcern + writeConcern?: WriteConcern; } diff --git a/packages/service-provider-core/src/cursor.ts b/packages/service-provider-core/src/cursor.ts index 035e845e2a..e047e445b6 100644 --- a/packages/service-provider-core/src/cursor.ts +++ b/packages/service-provider-core/src/cursor.ts @@ -1,6 +1,6 @@ import Document from './document'; -interface Cursor { +export default interface Cursor { /** * Add a cursor flag as an option to the cursor. * @@ -8,7 +8,7 @@ interface Cursor { * * @returns {Cursor} The cursor. */ - addOption(option: number): Cursor + addOption(option: number): Cursor; /** * Set cursor to allow partial results. @@ -223,4 +223,3 @@ interface Cursor { explain(verbosity: string): Promise; } -export default Cursor; diff --git a/packages/service-provider-core/src/database-options.ts b/packages/service-provider-core/src/database-options.ts index 153bb2870e..4b9a01397d 100644 --- a/packages/service-provider-core/src/database-options.ts +++ b/packages/service-provider-core/src/database-options.ts @@ -1,9 +1,9 @@ -import WriteConcern from "./write-concern"; -import ReadConcern from "./read-concern"; -import ReadPreference from "./read-preference"; +import WriteConcern from './write-concern'; +import ReadConcern from './read-concern'; +import ReadPreference from './read-preference'; export default interface DatabaseOptions extends WriteConcern { returnNonCachedInstance?: boolean; readConcern?: ReadConcern; - readPreference?: ReadPreference + readPreference?: ReadPreference; } diff --git a/packages/service-provider-core/src/document.ts b/packages/service-provider-core/src/document.ts index 74b63c4421..f82f322436 100644 --- a/packages/service-provider-core/src/document.ts +++ b/packages/service-provider-core/src/document.ts @@ -1,5 +1,3 @@ -interface Document { - [prop: string]: any -}; - -export default Document; +export default interface Document { + [prop: string]: any; +} diff --git a/packages/service-provider-core/src/index.ts b/packages/service-provider-core/src/index.ts index 38315fff55..94aa8c463b 100644 --- a/packages/service-provider-core/src/index.ts +++ b/packages/service-provider-core/src/index.ts @@ -10,7 +10,7 @@ import DatabaseOptions from './database-options'; import getConnectInfo from './connect-info'; import { ReplPlatform } from './platform'; import CliOptions from './cli-options'; -import generateUri, { Scheme } from './uri-generator'; +import generateUri, { Scheme } from './uri-generator'; const DEFAULT_DB = 'test'; export { diff --git a/packages/service-provider-core/src/read-preference.ts b/packages/service-provider-core/src/read-preference.ts index 9f7579abe6..d30b90bff8 100644 --- a/packages/service-provider-core/src/read-preference.ts +++ b/packages/service-provider-core/src/read-preference.ts @@ -1,4 +1,4 @@ export default interface ReadPreference { - mode: string, - tags?: Record[] + mode: string; + tags?: Record[]; } diff --git a/packages/service-provider-core/src/readable.ts b/packages/service-provider-core/src/readable.ts index 2c287b3af7..03c6a3e44b 100644 --- a/packages/service-provider-core/src/readable.ts +++ b/packages/service-provider-core/src/readable.ts @@ -6,7 +6,7 @@ import DatabaseOptions from './database-options'; /** * Interface for read operations in the CRUD specification. */ -interface Readable { +export default interface Readable { /** * Run an aggregation pipeline. * @@ -23,7 +23,7 @@ interface Readable { collection: string, pipeline: Document[], options?: Document, - dbOptions?: DatabaseOptions) : Cursor; + dbOptions?: DatabaseOptions): Cursor; /** * Run an aggregation pipeline on the DB. @@ -31,6 +31,7 @@ interface Readable { * @param {String} database - The database name. * @param {Array} pipeline - The aggregation pipeline. * @param {Document} options - The pipeline options. + * @param {Object} dbOptions - Optional options. * * @returns {Cursor} A cursor. */ @@ -39,7 +40,7 @@ interface Readable { pipeline: Document[], options?: Document, dbOptions?: DatabaseOptions - ) : Cursor; + ): Cursor; /** * Returns the count of documents that would match a find() query for the @@ -98,7 +99,7 @@ interface Readable { fieldName: string, filter?: Document, options?: Document, - dbOptions?: DatabaseOptions) : Promise; + dbOptions?: DatabaseOptions): Promise; /** * Get an estimated document count from the collection. @@ -114,7 +115,7 @@ interface Readable { database: string, collection: string, options?: Document, - dbOptions?: DatabaseOptions) : Promise; + dbOptions?: DatabaseOptions): Promise; /** * Find documents in the collection. @@ -132,7 +133,7 @@ interface Readable { collection: string, filter?: Document, options?: Document, - dbOptions?: DatabaseOptions) : Cursor; + dbOptions?: DatabaseOptions): Cursor; /** * Returns the server version. @@ -201,7 +202,6 @@ interface Readable { collection: string, options?: Document, dbOptions?: DatabaseOptions - ): Promise + ): Promise; } -export default Readable; diff --git a/packages/service-provider-core/src/result.ts b/packages/service-provider-core/src/result.ts index 8009cd5a5f..95c07558ce 100644 --- a/packages/service-provider-core/src/result.ts +++ b/packages/service-provider-core/src/result.ts @@ -1,3 +1,4 @@ +/* eslint no-undef: 0 */ type Result = any; export default Result; diff --git a/packages/service-provider-core/src/service-provider.ts b/packages/service-provider-core/src/service-provider.ts index e2a4494326..cc5c0beee2 100644 --- a/packages/service-provider-core/src/service-provider.ts +++ b/packages/service-provider-core/src/service-provider.ts @@ -6,6 +6,4 @@ import Admin from './admin'; /** * Interface for all service providers. */ -interface ServiceProvider extends Readable, Writable, Closable, Admin {}; - -export default ServiceProvider; +export default interface ServiceProvider extends Readable, Writable, Closable, Admin {} diff --git a/packages/service-provider-core/src/writable.ts b/packages/service-provider-core/src/writable.ts index 72e1fd57ee..8cf4f81d78 100644 --- a/packages/service-provider-core/src/writable.ts +++ b/packages/service-provider-core/src/writable.ts @@ -8,13 +8,14 @@ import DatabaseOptions from './database-options'; /** * Interface for write operations in the CRUD specification. */ -interface Writable { +export default interface Writable { /** * @param {String} db - the db name * @param spec * @param options - * @return {any} + * @param {DatabaseOptions} dbOptions - The database options + * @return {Promise} */ runCommand( db: string, @@ -27,7 +28,8 @@ interface Writable { * Drop a database * * @param {String} database - The database name. - * @param {WriteConcernDoc} writeConcern - The write concern. + * @param {WriteConcern} writeConcern - The write concern. + * @param {DatabaseOptions} dbOptions - The database options * * @returns {Promise} The result of the operation. */ @@ -35,7 +37,7 @@ interface Writable { database: string, writeConcern?: WriteConcern, dbOptions?: DatabaseOptions - ) : Promise; + ): Promise; /** * Execute a mix of write operations. @@ -53,7 +55,7 @@ interface Writable { collection: string, requests: Document, options?: Document, - dbOptions?: DatabaseOptions) : Promise; + dbOptions?: DatabaseOptions): Promise; /** * Delete multiple documents from the collection. @@ -71,7 +73,7 @@ interface Writable { collection: string, filter: Document, options?: Document, - dbOptions?: DatabaseOptions) : Promise; + dbOptions?: DatabaseOptions): Promise; /** * Delete one document from the collection. @@ -89,7 +91,7 @@ interface Writable { collection: string, filter: Document, options?: Document, - dbOptions?: DatabaseOptions) : Promise; + dbOptions?: DatabaseOptions): Promise; /** * Find one document and delete it. @@ -107,7 +109,7 @@ interface Writable { collection: string, filter: Document, options?: Document, - dbOptions?: DatabaseOptions) : Promise; + dbOptions?: DatabaseOptions): Promise; /** * Find one document and replace it. @@ -127,7 +129,7 @@ interface Writable { filter: Document, replacement: Document, options?: Document, - dbOptions?: DatabaseOptions) : Promise; + dbOptions?: DatabaseOptions): Promise; /** * Find one document and update it. @@ -147,7 +149,7 @@ interface Writable { filter: Document, update: Document, options?: Document, - dbOptions?: DatabaseOptions) : Promise; + dbOptions?: DatabaseOptions): Promise; /** * Insert many documents into the colleciton. @@ -165,7 +167,7 @@ interface Writable { collection: string, docs: Document[], options?: Document, - dbOptions?: DatabaseOptions) : Promise; + dbOptions?: DatabaseOptions): Promise; /** * Insert one document into the collection. @@ -183,7 +185,7 @@ interface Writable { collection: string, doc: Document, options?: Document, - dbOptions?: DatabaseOptions) : Promise; + dbOptions?: DatabaseOptions): Promise; /** * Replace a document with another. @@ -203,7 +205,7 @@ interface Writable { filter: Document, replacement: Document, options?: Document, - dbOptions?: DatabaseOptions) : Promise; + dbOptions?: DatabaseOptions): Promise; /** * Update many document. @@ -223,7 +225,7 @@ interface Writable { filter: Document, update: Document, options?: Document, - dbOptions?: DatabaseOptions) : Promise; + dbOptions?: DatabaseOptions): Promise; /** * find and update or remove a document. @@ -246,7 +248,7 @@ interface Writable { update: Document, options?: Document, dbOptions?: DatabaseOptions - ) + ); /** * Update a document. @@ -266,7 +268,7 @@ interface Writable { filter: Document, update: Document, options?: Document, - dbOptions?: DatabaseOptions) : Promise; + dbOptions?: DatabaseOptions): Promise; /** * Deprecated save command. @@ -283,7 +285,7 @@ interface Writable { collection: string, doc: Document, options?: Document, - dbOptions?: DatabaseOptions): Promise + dbOptions?: DatabaseOptions): Promise; /** * Deprecated remove command. @@ -310,7 +312,7 @@ interface Writable { * @param {String} database - The db name. * @param {String} collection - The collection name. * @param {String} size - The maximum size, in bytes, for the capped collection. - * @param {CommandOptions} commandOptions - The command options + * @param {CommandOptions} options - The command options * * @return {Promise} */ @@ -318,7 +320,7 @@ interface Writable { database: string, collection: string, size: number, - options?: CommandOptions): Promise + options?: CommandOptions): Promise; /** * Adds new indexes to a collection. @@ -344,6 +346,7 @@ interface Writable { * @param {String} collection - The collection name. * @param {string|string[]|Object|Object[]} indexes the indexes to be removed. * @param {CommandOptions} commandOptions - The command options. + * @param {DatabaseOptions} dbOptions - The database options * @return {Promise} */ dropIndexes( @@ -359,6 +362,7 @@ interface Writable { * @param {String} database - The db name. * @param {String} collection - The collection name. * @param {CommandOptions} options - The command options. + * @param {DatabaseOptions} dbOptions - The database options * @return {Promise} */ reIndex( @@ -388,6 +392,7 @@ interface Writable { * @param {String} oldName - The collection name. * @param {String} newName - The new collection name. * @param {String} options - The options. + * @param {DatabaseOptions} dbOptions - The database options */ renameCollection( database: string, @@ -397,4 +402,3 @@ interface Writable { dbOptions?: DatabaseOptions): Promise; } -export default Writable; diff --git a/packages/shell-api/src/shell-bson.ts b/packages/shell-api/src/shell-bson.ts index 4c8c1b3b67..b32d142ace 100644 --- a/packages/shell-api/src/shell-bson.ts +++ b/packages/shell-api/src/shell-bson.ts @@ -13,26 +13,26 @@ function dateHelper(...args: DateConstructorArguments): Date { } export default { RegExp: RegExp, - DBRef: function(...args) { + DBRef: function(...args): bson.DBRef { return new bson.DBRef(...args); }, - DBPointer: function(...args) { + DBPointer: function(...args): bson.DBPointer { return new bson.DBPointer(...args); }, Map: bson.Map, - MaxKey: function(...args) { + MaxKey: function(...args): bson.MaxKey { return new bson.MaxKey(...args); }, - MinKey: function(...args) { + MinKey: function(...args): bson.MinKey { return new bson.MinKey(...args); }, - ObjectId: function(...args) { + ObjectId: function(...args): bson.ObjectID { return new bson.ObjectID(...args); }, - Symbol: function(...args) { + Symbol: function(...args): bson.Symbol { return new bson.BSONSymbol(...args); }, - Timestamp: function(...args) { + Timestamp: function(...args): bson.Timestamp { return new bson.Timestamp(...args); }, Code: function(c, s): bson.Code { diff --git a/packages/shell-evaluator/src/shell-evaluator.spec.ts b/packages/shell-evaluator/src/shell-evaluator.spec.ts index 6de348f97d..d2d68776de 100644 --- a/packages/shell-evaluator/src/shell-evaluator.spec.ts +++ b/packages/shell-evaluator/src/shell-evaluator.spec.ts @@ -19,7 +19,7 @@ describe('ShellEvaluator', () => { messageBus: busMock, shellApi: { use: useSpy }, asyncWriter: { - process: i => (i), + process: (i): string => (i), symbols: { saveState: sinon.spy(), revertState: sinon.spy() } From 7d15dd55760781b0990ce9579a169a25fbae9e68 Mon Sep 17 00:00:00 2001 From: aherlihy Date: Mon, 15 Jun 2020 19:17:53 +0200 Subject: [PATCH 2/4] readd skip --- ...ch-service-provider-browser.integration.spec.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/service-provider-browser/src/stitch-service-provider-browser.integration.spec.ts b/packages/service-provider-browser/src/stitch-service-provider-browser.integration.spec.ts index 64e11f5f85..ba0213037b 100644 --- a/packages/service-provider-browser/src/stitch-service-provider-browser.integration.spec.ts +++ b/packages/service-provider-browser/src/stitch-service-provider-browser.integration.spec.ts @@ -45,13 +45,13 @@ describe('StitchServiceProviderBrowser [ integration ]', function() { }); }); - context('when running against a database', () => { - it('it rejects the action', () => { - return stitchTransport.aggregate('admin', null, [{ $currentOp: {} }]).catch((err) => { - expect(err).to.not.equal(null); - }); - }); - }); + // context('when running against a database', () => { + // it('it rejects the action', () => { + // return stitchTransport.aggregate('admin', null, [{ $currentOp: {} }]).catch((err) => { + // expect(err).to.not.equal(null); + // }); + // }); + // }); }); describe('#bulkWrite', () => { From 4627b68614b5311baf91416b71c048da6c36f9f8 Mon Sep 17 00:00:00 2001 From: aherlihy Date: Tue, 16 Jun 2020 15:38:27 +0200 Subject: [PATCH 3/4] cr comments --- package.json | 1 - .../src/components/utils/inspect.spec.ts | 13 ----- .../src/interpreter/interpreter.spec.ts | 56 ++++++++++--------- .../preprocessor/wrap-object-literal.spec.ts | 10 ++-- ...rvice-provider-browser.integration.spec.ts | 14 ++--- 5 files changed, 41 insertions(+), 53 deletions(-) diff --git a/package.json b/package.json index 349b3280ad..035e3ac566 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "test": "lerna run test", "test-ci": "lerna run test-ci", "compile-ts": "lerna run compile-ts", - "start-async": "lerna exec npm run start-async --scope @mongosh/cli-repl", "compile-cli": "lerna run compile-ts --scope @mongosh/cli-repl --include-dependencies", "prestart-cli": "npm run compile-cli", "start-cli": "lerna exec npm start --scope @mongosh/cli-repl", diff --git a/packages/browser-repl/src/components/utils/inspect.spec.ts b/packages/browser-repl/src/components/utils/inspect.spec.ts index b82d74273c..4f49a3bf08 100644 --- a/packages/browser-repl/src/components/utils/inspect.spec.ts +++ b/packages/browser-repl/src/components/utils/inspect.spec.ts @@ -37,19 +37,6 @@ describe('inspect', () => { inspect(undefined) ).to.equal('undefined'); }); - - // it('inspects Symbol', () => { - // expect( - // inspect(Symbol('123')) - // ).to.equal('Symbol(123)'); - // }); - // - // it('inspects BigInt', () => { - // expect( - // // eslint-disable-next-line no-undef - // inspect(BigInt(1)) - // ).to.equal('1n'); - // }); }); context('with BSON types', () => { diff --git a/packages/browser-runtime-core/src/interpreter/interpreter.spec.ts b/packages/browser-runtime-core/src/interpreter/interpreter.spec.ts index 3e64d2f16e..e15660949c 100644 --- a/packages/browser-runtime-core/src/interpreter/interpreter.spec.ts +++ b/packages/browser-runtime-core/src/interpreter/interpreter.spec.ts @@ -71,15 +71,15 @@ describe('Interpreter', () => { ).to.deep.equal({ x: 1 }); }); - // it('evaluates object literal after other statements as block', async() => { - // // TODO: for some reason this is the default behaviour in node repl and devtools, - // // as is now it wraps everything, which breaks the code. - // expect( - // await testEvaluate( - // ';{x: 1}' - // ) - // ).to.equal(1); - // }); + it.skip('evaluates object literal after other statements as block', async() => { + // TODO: for some reason this is the default behaviour in node repl and devtools, + // as is now it wraps everything, which breaks the code. + expect( + await testEvaluate( + ';{x: 1}' + ) + ).to.equal(1); + }); it('can declare a top level variable with let', async() => { expect( @@ -159,24 +159,26 @@ describe('Interpreter', () => { ).to.equal(3); }); - // it('can redeclare a top level function as function', async() => { - // expect( - // await testEvaluate( - // 'function f() { return 1; }', - // 'function f() { return 2; }', - // 'f()' - // ) - // ).to.equal(2); - // }); - // - // it('can redeclare a top level function as var', async() => { - // expect( - // await testEvaluate( - // 'function sum(a, b) { return a + b; }', - // 'var sum = 1' - // ) - // ).to.equal(1); - // }); + describe.skip('redeclare top level vars', () => { + it('can redeclare a top level function as function', async() => { + expect( + await testEvaluate( + 'function f() { return 1; }', + 'function f() { return 2; }', + 'f()' + ) + ).to.equal(2); + }); + + it('can redeclare a top level function as var', async() => { + expect( + await testEvaluate( + 'function sum(a, b) { return a + b; }', + 'var sum = 1' + ) + ).to.equal(1); + }); + }); it('cannot re-declare a top level function as let', async() => { const error = await testEvaluate( diff --git a/packages/browser-runtime-core/src/interpreter/preprocessor/wrap-object-literal.spec.ts b/packages/browser-runtime-core/src/interpreter/preprocessor/wrap-object-literal.spec.ts index 15e8e95369..51f211c1bc 100644 --- a/packages/browser-runtime-core/src/interpreter/preprocessor/wrap-object-literal.spec.ts +++ b/packages/browser-runtime-core/src/interpreter/preprocessor/wrap-object-literal.spec.ts @@ -18,10 +18,10 @@ describe('wrapObjectLiteral', () => { expect(wrapObjectLiteral('\n {x: 2} \n ')).to.equal('(\n {x: 2} \n )'); }); - // it('should not wrap multiple statements', () => { - // // TODO: for some reason this is the default behaviour in node repl and devtools, - // // as is now it wraps everything, which breaks the code. - // expect(wrapObjectLiteral('{x: 2}; {x: 2}')).to.equal('{x: 2}; {x: 2}'); - // }); + it.skip('should not wrap multiple statements', () => { + // TODO: for some reason this is the default behaviour in node repl and devtools, + // as is now it wraps everything, which breaks the code. + expect(wrapObjectLiteral('{x: 2}; {x: 2}')).to.equal('{x: 2}; {x: 2}'); + }); }); diff --git a/packages/service-provider-browser/src/stitch-service-provider-browser.integration.spec.ts b/packages/service-provider-browser/src/stitch-service-provider-browser.integration.spec.ts index ba0213037b..64e11f5f85 100644 --- a/packages/service-provider-browser/src/stitch-service-provider-browser.integration.spec.ts +++ b/packages/service-provider-browser/src/stitch-service-provider-browser.integration.spec.ts @@ -45,13 +45,13 @@ describe('StitchServiceProviderBrowser [ integration ]', function() { }); }); - // context('when running against a database', () => { - // it('it rejects the action', () => { - // return stitchTransport.aggregate('admin', null, [{ $currentOp: {} }]).catch((err) => { - // expect(err).to.not.equal(null); - // }); - // }); - // }); + context('when running against a database', () => { + it('it rejects the action', () => { + return stitchTransport.aggregate('admin', null, [{ $currentOp: {} }]).catch((err) => { + expect(err).to.not.equal(null); + }); + }); + }); }); describe('#bulkWrite', () => { From cedd4b24774dfc91133eb1f3ced97767d0240567 Mon Sep 17 00:00:00 2001 From: aherlihy Date: Tue, 16 Jun 2020 16:53:27 +0200 Subject: [PATCH 4/4] remove commented tests --- packages/cli-repl/src/arg-mapper.spec.ts | 10 ---------- ...stitch-service-provider-browser.integration.spec.ts | 8 -------- 2 files changed, 18 deletions(-) diff --git a/packages/cli-repl/src/arg-mapper.spec.ts b/packages/cli-repl/src/arg-mapper.spec.ts index e045eed374..f2b688a606 100644 --- a/packages/cli-repl/src/arg-mapper.spec.ts +++ b/packages/cli-repl/src/arg-mapper.spec.ts @@ -23,16 +23,6 @@ describe('arg-mapper.mapCliToDriver', () => { }); }); - // context('when cli args have disableImplicitSessions', () => { - // const cliOptions: CliOptions = { disableImplicitSessions: true }; - // - // it('maps to explicitlyIgnoreSession', () => { - // expect(mapCliToDriver(cliOptions)).to.deep.equal({ - // explicitlyIgnoreSession: true - // }); - // }); - // }); - context('when cli args have quiet', () => { const cliOptions: CliOptions = { quiet: true }; diff --git a/packages/service-provider-browser/src/stitch-service-provider-browser.integration.spec.ts b/packages/service-provider-browser/src/stitch-service-provider-browser.integration.spec.ts index 64e11f5f85..d4b4554bd8 100644 --- a/packages/service-provider-browser/src/stitch-service-provider-browser.integration.spec.ts +++ b/packages/service-provider-browser/src/stitch-service-provider-browser.integration.spec.ts @@ -44,14 +44,6 @@ describe('StitchServiceProviderBrowser [ integration ]', function() { expect(docs).to.deep.equal([]); }); }); - - context('when running against a database', () => { - it('it rejects the action', () => { - return stitchTransport.aggregate('admin', null, [{ $currentOp: {} }]).catch((err) => { - expect(err).to.not.equal(null); - }); - }); - }); }); describe('#bulkWrite', () => {