Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bratelefant master to Migration 3.0 branch #896

Open
wants to merge 4 commits into
base: migration-branch/3.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 7 additions & 1 deletion client.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
}
}

check(this.onbeforeunloadMessage, Match.OneOf(String, Function));

Check failure on line 136 in client.js

View workflow job for this annotation

GitHub Actions / lint

A function with a name starting with an uppercase letter should only be used as a constructor

try {
const _URL = window.URL || window.webkitURL || window.mozURL || window.msURL || window.oURL || false;
Expand Down Expand Up @@ -161,8 +161,8 @@
check(this.chunkSize, Number);
check(this.downloadRoute, String);
check(this.disableUpload, Boolean);
check(this.namingFunction, Match.OneOf(false, Function));

Check failure on line 164 in client.js

View workflow job for this annotation

GitHub Actions / lint

A function with a name starting with an uppercase letter should only be used as a constructor
check(this.onBeforeUpload, Match.OneOf(false, Function));

Check failure on line 165 in client.js

View workflow job for this annotation

GitHub Actions / lint

A function with a name starting with an uppercase letter should only be used as a constructor
check(this.allowClientCode, Boolean);
check(this.ddp, Match.Any);

Expand Down Expand Up @@ -255,7 +255,13 @@
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
});
}
return uploadInstance;
}

/**
Expand All @@ -269,8 +275,8 @@
*/
remove(selector = {}, callback) {
this._debug(`[FilesCollection] [remove(${JSON.stringify(selector)})]`);
check(selector, Match.OneOf(Object, String));

Check failure on line 278 in client.js

View workflow job for this annotation

GitHub Actions / lint

A function with a name starting with an uppercase letter should only be used as a constructor
check(callback, Match.Optional(Function));

Check failure on line 279 in client.js

View workflow job for this annotation

GitHub Actions / lint

A function with a name starting with an uppercase letter should only be used as a constructor

if (this.allowClientCode) {
this.ddp.call(this._methodNames._Remove, selector, (callback || NOOP));
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 @@
*/
_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 @@
/*
* @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 failure on line 215 in core.js

View workflow job for this annotation

GitHub Actions / lint

A function with a name starting with an uppercase letter should only be used as a constructor

Check failure on line 215 in core.js

View workflow job for this annotation

GitHub Actions / lint

A function with a name starting with an uppercase letter should only be used as a constructor
check(options, Match.Optional(Object));

Check failure on line 216 in core.js

View workflow job for this annotation

GitHub Actions / lint

A function with a name starting with an uppercase letter should only be used as a constructor

const doc = this.collection.findOne(selector, options);
const doc = await this.collection.findOneAsync(selector, options);
if (doc) {
return new FileCursor(doc, this);
}
Expand All @@ -232,7 +233,7 @@
*/
find(selector = {}, options) {
this._debug(`[FilesCollection] [find(${JSON.stringify(selector)}, ${JSON.stringify(options)})]`);
check(selector, Match.Optional(Match.OneOf(Object, String, Boolean, Number, null)));

Check failure on line 236 in core.js

View workflow job for this annotation

GitHub Actions / lint

A function with a name starting with an uppercase letter should only be used as a constructor

Check failure on line 236 in core.js

View workflow job for this annotation

GitHub Actions / lint

A function with a name starting with an uppercase letter should only be used as a constructor
check(options, Match.Optional(Object));

return new FilesCursor(selector, options, this);
Expand All @@ -241,13 +242,13 @@
/*
* @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
129 changes: 64 additions & 65 deletions cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ export class FileCursor {
/*
* @locus Anywhere
* @memberOf FileCursor
* @name remove
* @param callback {Function} - Triggered asynchronously after item is removed or failed to be removed
* @name removeAsync
* @throws {Meteor.Error} - If no file reference is provided
* @summary Remove document
* @returns {FileCursor}
* @returns {Promise<FileCursor>}
*/
remove(callback) {
this._collection._debug('[FilesCollection] [FileCursor] [remove()]');
async removeAsync() {
this._collection._debug('[FilesCollection] [FileCursor] [removeAsync()]');
if (this._fileRef) {
this._collection.remove(this._fileRef._id, callback);
await this._collection.removeAsync(this._fileRef._id);
} else {
callback && callback(new Meteor.Error(404, 'No such file'));
throw new Meteor.Error(404, 'No such file');
}
return this;
}
Expand Down Expand Up @@ -113,11 +113,11 @@ export class FilesCursor {
* @memberOf FilesCursor
* @name get
* @summary Returns all matching document(s) as an Array. Alias of `.fetch()`
* @returns {[Object]}
* @returns {Promise<[Object]>}
*/
get() {
this._collection._debug('[FilesCollection] [FilesCursor] [get()]');
return this.cursor.fetch();
async get() {
this._collection._debug('[FilesCollection] [FilesCursor] [getAsync()]');
return this.cursor.fetchAsync();
}

/*
Expand All @@ -127,21 +127,21 @@ export class FilesCursor {
* @summary Returns `true` if there is next item available on Cursor
* @returns {Boolean}
*/
hasNext() {
this._collection._debug('[FilesCollection] [FilesCursor] [hasNext()]');
return this._current < (this.cursor.count() - 1);
async hasNext() {
this._collection._debug('[FilesCollection] [FilesCursor] [hasNextAsync()]');
return this._current < (await this.cursor.countAsync()) - 1;
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name next
* @summary Returns next item on Cursor, if available
* @returns {Object|undefined}
* @returns {Promise<Object|undefined>}
*/
next() {
this._collection._debug('[FilesCollection] [FilesCursor] [next()]');
this.cursor.fetch()[++this._current];
async next() {
this._collection._debug('[FilesCollection] [FilesCursor] [nextAsync()]');
return (await this.cursor.fetchAsync())[++this._current];
}

/*
Expand All @@ -161,89 +161,88 @@ export class FilesCursor {
* @memberOf FilesCursor
* @name previous
* @summary Returns previous item on Cursor, if available
* @returns {Object|undefined}
* @returns {Promise<Object|undefined>}
*/
previous() {
this._collection._debug('[FilesCollection] [FilesCursor] [previous()]');
this.cursor.fetch()[--this._current];
async previous() {
this._collection._debug('[FilesCollection] [FilesCursor] [previousAsync()]');
return (this.cursor.fetchAsync())[--this._current];
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name fetch
* @name fetchAsync
* @summary Returns all matching document(s) as an Array.
* @returns {[Object]}
* @returns {Promise<[Object]>}
*/
fetch() {
this._collection._debug('[FilesCollection] [FilesCursor] [fetch()]');
return this.cursor.fetch() || [];
async fetchAsync() {
this._collection._debug('[FilesCollection] [FilesCursor] [fetchAsync()]');
return (await this.cursor.fetchAsync()) || [];
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name first
* @summary Returns first item on Cursor, if available
* @returns {Object|undefined}
* @returns {Promise<Object|undefined>}
*/
first() {
this._collection._debug('[FilesCollection] [FilesCursor] [first()]');
async first() {
this._collection._debug('[FilesCollection] [FilesCursor] [firstAsync()]');
this._current = 0;
return this.fetch()[this._current];
return (await this.fetchAsync())[this._current];
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name last
* @summary Returns last item on Cursor, if available
* @returns {Object|undefined}
* @returns {Promise<Object|undefined>}
*/
last() {
async last() {
this._collection._debug('[FilesCollection] [FilesCursor] [last()]');
this._current = this.count() - 1;
return this.fetch()[this._current];
this._current = (await this.countAsync()) - 1;
return (await this.fetchAsync())[this._current];
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name count
* @name countAsync
* @summary Returns the number of documents that match a query
* @returns {Number}
* @returns {Promise<Number>}
*/
count() {
this._collection._debug('[FilesCollection] [FilesCursor] [count()]');
return this.cursor.count();
async countAsync() {
this._collection._debug('[FilesCollection] [FilesCursor] [countAsync()]');
return this.cursor.countAsync();
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name remove
* @param callback {Function} - Triggered asynchronously after item is removed or failed to be removed
* @name removeAsync
* @summary Removes all documents that match a query
* @returns {FilesCursor}
* @returns {Promise<FilesCursor>}
*/
remove(callback) {
this._collection._debug('[FilesCollection] [FilesCursor] [remove()]');
this._collection.remove(this._selector, callback);
async removeAsync() {
this._collection._debug('[FilesCollection] [FilesCursor] [removeAsync()]');
await this._collection.removeAsync(this._selector);
return this;
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name forEach
* @name forEachAsync
* @param callback {Function} - Function to call. It will be called with three arguments: the `file`, a 0-based index, and cursor itself
* @param context {Object} - An object which will be the value of `this` inside `callback`
* @summary Call `callback` once for each matching document, sequentially and synchronously.
* @returns {undefined}
* @returns {Promise<undefined>}
*/
forEach(callback, context = {}) {
this._collection._debug('[FilesCollection] [FilesCursor] [forEach()]');
this.cursor.forEach(callback, context);
async forEachAsync(callback, context = {}) {
this._collection._debug('[FilesCollection] [FilesCursor] [forEachAsync()]');
await this.cursor.forEachAsync(callback, context);
}

/*
Expand All @@ -252,41 +251,41 @@ export class FilesCursor {
* @name each
* @summary Returns an Array of FileCursor made for each document on current cursor
* Useful when using in {{#each FilesCursor#each}}...{{/each}} block template helper
* @returns {[FileCursor]}
* @returns {Promise<[FileCursor]>}
*/
each() {
return this.map((file) => {
async each() {
return this.mapAsync((file) => {
return new FileCursor(file, this._collection);
});
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name map
* @name mapAsync
* @param callback {Function} - Function to call. It will be called with three arguments: the `file`, a 0-based index, and cursor itself
* @param context {Object} - An object which will be the value of `this` inside `callback`
* @summary Map `callback` over all matching documents. Returns an Array.
* @returns {Array}
* @returns {Promise<Array>}
*/
map(callback, context = {}) {
this._collection._debug('[FilesCollection] [FilesCursor] [map()]');
return this.cursor.map(callback, context);
async mapAsync(callback, context = {}) {
this._collection._debug('[FilesCollection] [FilesCursor] [mapAsync()]');
return this.cursor.mapAsync(callback, context);
}

/*
* @locus Anywhere
* @memberOf FilesCursor
* @name current
* @summary Returns current item on Cursor, if available
* @returns {Object|undefined}
* @returns {Promise<Object|undefined>}
*/
current() {
this._collection._debug('[FilesCollection] [FilesCursor] [current()]');
async current() {
this._collection._debug('[FilesCollection] [FilesCursor] [currentAsync()]');
if (this._current < 0) {
this._current = 0;
}
return this.fetch()[this._current];
return (await this.fetchAsync())[this._current];
}

/*
Expand All @@ -296,9 +295,9 @@ export class FilesCursor {
* @param callbacks {Object} - Functions to call to deliver the result set as it changes
* @summary Watch a query. Receive callbacks as the result set changes.
* @url http://docs.meteor.com/api/collections.html#Mongo-Cursor-observe
* @returns {Object} - live query handle
* @returns {Promise<Object>} - live query handle
*/
observe(callbacks) {
async observe(callbacks) {
this._collection._debug('[FilesCollection] [FilesCursor] [observe()]');
return this.cursor.observe(callbacks);
}
Expand Down
2 changes: 2 additions & 0 deletions lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,14 @@ const fixJSONStringify = function(obj) {
* @summary Returns formatted URL for file
* @returns {String} Downloadable link
*/
// eslint-disable-next-line camelcase, no-undef
const formatFleURL = (fileRef, version = 'original', _uriBase = (__meteor_runtime_config__ || {}).ROOT_URL) => {
check(fileRef, Object);
check(version, String);
let uriBase = _uriBase;

if (!helpers.isString(uriBase)) {
// eslint-disable-next-line camelcase, no-undef
uriBase = (__meteor_runtime_config__ || {}).ROOT_URL || '/';
}

Expand Down
Loading
Loading