Skip to content

Commit

Permalink
Merge pull request #884 from bratelefant/master
Browse files Browse the repository at this point in the history
Meteor 3.0: Adding Async Methods to server
  • Loading branch information
dr-dimitru authored Jan 18, 2025
2 parents 3757d61 + 0d6707e commit 61e8250
Show file tree
Hide file tree
Showing 17 changed files with 3,905 additions and 485 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"node": true,
"browser": false
},
"ignorePatterns": ["worker*.js"],
"globals": {
"Package": true,
"Tinytest": true,
Expand Down Expand Up @@ -107,7 +108,8 @@
"afterColon": true
}],
"new-cap": [2, {
"newIsCap": true
"newIsCap": true,
"capIsNewExceptionPattern": "^Match\\.."
}],
"no-multiple-empty-lines": [2, {
"max": 2
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Lint

on: [push, pull_request]

jobs:
lintcode:
name: lint
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3

- name: setup node
uses: actions/setup-node@v3
with:
node-version: '14.x'

- name: cache dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm install
- run: npm run lint
29 changes: 29 additions & 0 deletions .github/workflows/testsuite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Test suite

on: [push, pull_request]

jobs:
tests:
name: tests
runs-on: ubuntu-latest
# needs: [lintcode,lintstyle,lintdocs] # we could add prior jobs for linting, if desired
steps:
- name: checkout
uses: actions/checkout@v3

- name: Setup meteor
uses: meteorengineer/setup-meteor@v1
with:
meteor-release: '2.14'

- name: cache dependencies
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: meteor npm install && meteor npm run test:mocha
166 changes: 151 additions & 15 deletions .npm/package/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion client.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,13 @@ class FilesCollection extends FilesCollectionCore {
Meteor._debug('[FilesCollection] [insert()] Upload is disabled with [disableUpload]!');
return {};
}
return (new UploadInstance(config, this))[autoStart ? 'start' : 'manual']();
const uploadInstance = new UploadInstance(config, this);
if (autoStart) {
uploadInstance.start().catch((error) => {
console.error('[FilesCollection] [insert] Error starting upload:', error);

Check warning on line 261 in client.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check warning on line 261 in client.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
});
}
return uploadInstance;
}

/**
Expand Down
21 changes: 11 additions & 10 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export default class FilesCollectionCore extends EventEmitter {
*/
_debug() {
if (this.debug) {
(console.info || console.log || function () { }).apply(void 0, arguments);
// eslint-disable-next-line no-console
(console.info || console.log || function () {}).apply(void 0, arguments);
}
}

Expand Down Expand Up @@ -203,18 +204,18 @@ export default class FilesCollectionCore extends EventEmitter {
/*
* @locus Anywhere
* @memberOf FilesCollectionCore
* @name findOne
* @name findOneAsync
* @param {String|Object} selector - Mongo-Style selector (http://docs.meteor.com/api/collections.html#selectors)
* @param {Object} options - Mongo-Style selector Options (http://docs.meteor.com/api/collections.html#sortspecifiers)
* @summary Find and return Cursor for matching document Object
* @returns {FileCursor} Instance
* @returns {Promise<FileCursor>} Instance
*/
findOne(selector = {}, options) {
this._debug(`[FilesCollection] [findOne(${JSON.stringify(selector)}, ${JSON.stringify(options)})]`);
async findOneAsync(selector = {}, options) {
this._debug(`[FilesCollection] [findOneAsync(${JSON.stringify(selector)}, ${JSON.stringify(options)})]`);
check(selector, Match.Optional(Match.OneOf(Object, String, Boolean, Number, null)));
check(options, Match.Optional(Object));

const doc = this.collection.findOne(selector, options);
const doc = await this.collection.findOneAsync(selector, options);
if (doc) {
return new FileCursor(doc, this);
}
Expand All @@ -241,13 +242,13 @@ export default class FilesCollectionCore extends EventEmitter {
/*
* @locus Anywhere
* @memberOf FilesCollectionCore
* @name update
* @name updateAsync
* @see http://docs.meteor.com/#/full/update
* @summary link Mongo.Collection update method
* @returns {Mongo.Collection} Instance
* @returns {Promise<Mongo.Collection>} Instance
*/
update() {
this.collection.update.apply(this.collection, arguments);
async updateAsync() {
await this.collection.updateAsync.apply(this.collection, arguments);
return this.collection;
}

Expand Down
Loading

0 comments on commit 61e8250

Please sign in to comment.