diff --git a/.gitignore b/.gitignore index d8ead34..574e251 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ npm-debug.log coverage /*.env .kube/**/secret.yml -dist +dist/ .vscode/ .migrations assets.json diff --git a/.npmignore b/.npmignore index ed535ee..a535bed 100644 --- a/.npmignore +++ b/.npmignore @@ -1,5 +1,6 @@ test/ coverage/ +src/ .nyc_output .npmignore .npmrc @@ -7,3 +8,8 @@ coverage/ .nycrc .eslintignore .eslintrc.json +.github +.yarnrc.yml +.yarn +.editorconfig +tsconfig.json diff --git a/.nycrc b/.nycrc index 1296baf..bf351b2 100644 --- a/.nycrc +++ b/.nycrc @@ -1,13 +1,11 @@ { - "cache": true, "all": true, "exclude": [ "node_modules/**", "test/**", - "testUtils/**", - "tap-snapshots/**", "coverage/**", "migrations/**", - "src/migrationTemplates/**" + "migrationTemplates/**", + "dist/**" ] } diff --git a/dist/adapter.js b/dist/adapter.js deleted file mode 100644 index dbeccbb..0000000 --- a/dist/adapter.js +++ /dev/null @@ -1,42 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const path_1 = __importDefault(require("path")); -const mongodb_1 = require("mongodb"); -class MongoAdapter { - constructor(params) { - this.params = params; - if (!this.params.url) { - throw new Error('`url` parameter required'); - } - } - getTemplatePath() { - return path_1.default.join(__dirname, 'migrationTemplates', 'async.ts'); - } - async connect() { - const client = await mongodb_1.MongoClient.connect(this.params.url, this.params.options); - this.client = client; - this.db = client.db(); - this.collection = this.db.collection('_migrations'); - return client; - } - async disconnect() { - return this.client?.close(); - } - async getExecutedMigrationNames() { - return this.collection?.find({}).toArray().then((docs) => { - return docs.map((doc) => doc._id.toString()); - }); - } - async markExecuted(name) { - this.collection?.replaceOne({ _id: new mongodb_1.ObjectId(name) }, { _id: name }, { upsert: true }); - } - async unmarkExecuted(name) { - this.collection?.deleteOne({ _id: new mongodb_1.ObjectId(name) }); - } -} -const _ = MongoAdapter; -exports.default = MongoAdapter; -//# sourceMappingURL=adapter.js.map \ No newline at end of file diff --git a/dist/adapter.js.map b/dist/adapter.js.map deleted file mode 100644 index 25cba5a..0000000 --- a/dist/adapter.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AACxB,qCAAgE;AAIhE,MAAM,YAAY;IAMhB,YAAY,MAAyC;QACnD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;SAC7C;IACH,CAAC;IAED,eAAe;QACb,OAAO,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,oBAAoB,EAAE,UAAU,CAAC,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,MAAM,GAAG,MAAM,qBAAW,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAC9E,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,EAAE,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;QAEpD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,yBAAyB;QAC7B,OAAO,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;YACvD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,IAAY;QAC7B,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE,IAAI,kBAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5F,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,IAAY;QAC/B,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,EAAE,GAAG,EAAE,IAAI,kBAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1D,CAAC;CACF;AAGD,MAAM,CAAC,GAAoC,YAAY,CAAC;AAExD,kBAAe,YAAY,CAAC"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b3df5e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,8 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const adapter_1 = __importDefault(require("./adapter")); -exports.default = adapter_1.default; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 17d0e7f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,wDAAgC;AAChC,kBAAe,iBAAO,CAAC"} \ No newline at end of file diff --git a/dist/migrationTemplates/async.js b/dist/migrationTemplates/async.js deleted file mode 100644 index f09c807..0000000 --- a/dist/migrationTemplates/async.js +++ /dev/null @@ -1,8 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.tags = []; -exports.migrate = async (client) => { -}; -exports.rollback = async (client) => { -}; -//# sourceMappingURL=async.js.map \ No newline at end of file diff --git a/dist/migrationTemplates/async.js.map b/dist/migrationTemplates/async.js.map deleted file mode 100644 index b1cb6c7..0000000 --- a/dist/migrationTemplates/async.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"async.js","sourceRoot":"","sources":["../../src/migrationTemplates/async.ts"],"names":[],"mappings":";;AAEA,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC;AAElB,OAAO,CAAC,OAAO,GAAG,KAAK,EAAE,MAAmB,EAAE,EAAE;AAChD,CAAC,CAAC;AAEF,OAAO,CAAC,QAAQ,GAAG,KAAK,EAAE,MAAmB,EAAE,EAAE;AACjD,CAAC,CAAC"} \ No newline at end of file diff --git a/src/migrationTemplates/async.ts b/migrationTemplates/async.ts similarity index 100% rename from src/migrationTemplates/async.ts rename to migrationTemplates/async.ts diff --git a/package.json b/package.json index c0031ae..b3f6850 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "type": "git", "url": "git://github.com/feedbackfruits/east-mongo.git" }, - "main": "lib/index.js", + "main": "dist/index.js", "keywords": [ "database", "db", @@ -22,7 +22,7 @@ }, "scripts": { "build": "tsc", - "lint": "eslint \"./src/**/*.ts\" --max-warnings 0 --ignore-pattern \"src/migrationTemplates/**/*.ts\"", + "lint": "eslint \"./src/**/*.ts\" --max-warnings 0", "lint:tests": "eslint \"./test/**/*.ts\" --max-warnings 0", "test": "NODE_ENV=test nyc tsx node_modules/jasmine/bin/jasmine \"test/**/*.spec.ts\"" }, diff --git a/src/adapter.ts b/src/adapter.ts index 00b6493..21e5948 100644 --- a/src/adapter.ts +++ b/src/adapter.ts @@ -18,17 +18,8 @@ class MongoAdapter implements Adapter { } } - async isConnected(): Promise { - try { - const count = await this.collection.estimatedDocumentCount(); - return !isNaN(count); - } catch (e) { - return false; - } - } - getTemplatePath(): string { - return path.join(__dirname, 'migrationTemplates', 'async.ts'); + return path.join(__dirname, '../migrationTemplates', 'async.ts'); } async connect(): Promise { diff --git a/test/adapter/constructor.spec.ts b/test/adapter/constructor.spec.ts new file mode 100644 index 0000000..ac66b3a --- /dev/null +++ b/test/adapter/constructor.spec.ts @@ -0,0 +1,14 @@ + +import MongoAdapter from '../../src/adapter'; + +describe('constructor', () => { + it('should construct with URL', async () => { + const adapter = new MongoAdapter({ url: 'mongodb://localhost:27017/test' }); + + expect(adapter).toBeDefined(); + }); + + it ('should throw without URL', async () => { + expect(() => new MongoAdapter({ url: '' })).toThrow(); + }); +}); diff --git a/test/adapter/getTemplatePath.spec.ts b/test/adapter/getTemplatePath.spec.ts index 4b29df8..9920f72 100644 --- a/test/adapter/getTemplatePath.spec.ts +++ b/test/adapter/getTemplatePath.spec.ts @@ -17,7 +17,7 @@ describe('getTemplatePath', () => { adapter.getTemplatePath() ); - expect(templatePath).toBe('../../src/migrationTemplates/async.ts'); + expect(templatePath).toBe('../../migrationTemplates/async.ts'); }); }); }); diff --git a/test/migrationTemplates.spec.ts b/test/migrationTemplates.spec.ts index 22e4979..f2ad1ea 100644 --- a/test/migrationTemplates.spec.ts +++ b/test/migrationTemplates.spec.ts @@ -3,7 +3,7 @@ import path from 'path'; describe('migrationTemplates', () => { const templatesPath = path.resolve( __dirname, - '../src/migrationTemplates' + '../migrationTemplates' ); it('can load async template', async () => { diff --git a/tsconfig.json b/tsconfig.json index 7d596e9..fd572a8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,7 @@ "isolatedModules": false, "experimentalDecorators": true, "emitDecoratorMetadata": true, - "declaration": false, + "declaration": true, "sourceMap": true, "exactOptionalPropertyTypes": false, "strictNullChecks": false, @@ -31,11 +31,7 @@ "test/**/*.ts", "node_modules", "typings/browser", - "typings/browser.d.ts" - ], - "compileOnSave": true, - "buildOnSave": false, - "atom": { - "rewriteTsconfig": false - } + "typings/browser.d.ts", + "migrationTemplates" + ] }