How can I declare a new collection from a package? - meteor

I'm writing a Meteor package that needs to create a new collection.
NewCollection = new Mongo.Collection('newcollection'); doesn't work in package code because Mongo isn't available to the package (Mongo is not defined).
How can I create a new collection in a Meteor package?

In your package.js file just include the mongo package:
Package.onUse(function (api) {
api.use('mongo');
});

Related

Load harrison:papa-parse package in Meteor

I downloaded the harrison:papa-parse package : meteor add harrison:papa-parse.
But now i need to load it in my Meteor application so i can use it.
I imported the package in my Component :
import { Papa } from 'meteor/harrison:papa-parse';
and then i need to declare the module in typing.d.ts file
declare module 'meteor/harrison:papa-parse' {
// something here like export const Papa; ?
}
, but after that i'm lost ! and i have an error: cannot read property 'parse' of undefined
In My component :
Papa.parse("http://mywebsite/test.csv", {
download: true,
complete: function(results) {
console.log(results);
}
});
Maybe there's an easy way to import the package easly and i'm trying to complicate it ?
The meteor package exports the "Papa" variable on the server, which means you have to call it from a server process.
Delete this line from your code, because it won't do anything:
import { Papa } from 'meteor/harrison:papa-parse';
Meteor packages don't need to be imported, part of the package spec is an automatic import of whatever variables are needed.
According to the documentation this package should be available in the browser, but for some reason the meteor package author made the decision to only expose it in the server.
There is also an npm package available, which might be a better path for you to follow.
You don't need the harrison:papa-parse meteor package. You can install and use the papaparse NPM package directly. In the root of your meteor project run meteor npm install --save papaparse. Then, in your client script you can import with import Papa from 'papaparse';.

Package for aggregating external packages in meteor.js

I am creating meteor app and I decided to separate it into packages, so I can take control of file loading order.
However, many packages have common dependencies(other external packages) like react or meteorhacks:flow-router. I want to create main myapp:app package with all these dependencies, that other packages in my app will imply.
This is app package.js:
Package.describe({
name: 'myapp:app',
version: '0.0.1'
});
Package.onUse(function(api) {
api.versionsFrom('1.2.1');
// All external packages that will be used by other local packages
api.use([
'twbs:bootstrap',
], 'client');
api.use([
'ecmascript',
'react',
'meteorhacks:flow-router'
], ['client', 'server']);
});
An I have package myapp:taskslist that imply myapp:app:
Package.describe({
name: 'myapp:taskslist',
version: '0.0.1'
});
Package.onUse(function(api) {
api.versionsFrom('1.2.1');
api.imply(['myapp:app']);
api.addFiles([
'client/tasksList.jsx',
'client/task.jsx',
'main.jsx'
], ['client']);
});
However it doesn't work. I have an error No plugin known to handle file 'client/taskList.jsx' because myapp:tasksList, does not have react plugin installed. Shouldn't api.imply() share react to myapp:tasksList package? What's good solution for this problem?
To answer your question directly, no imply does not expose react to myapp:tasksList
You need to think of it like this:
IMPLY passes references OUT
USE takes references IN
All the imply in myapp:tasksList is doing is allowing whatever uses myapp:tasksList to have access to myapp:app.
In order for you to use myapp:app (and all the references it exposes) in myapp:tasksList you also need to add
api.use([
'myapp:app',
]);
to myapp:tasksList

Mobile verification in meteor web/mobile app?

I want to include mobile verification for the users in my app.Tried adding the accounts-phone package ::*$ meteor add okland:accounts-phone *
but error was shown while including that package.
[Edit:1]
*=> Errors while adding packages:
While selecting package versions:
error: Conflict: Constraint npm-bcrypt#=0.7.7 is not satisfied by npm-bcrypt
0.7.8_2.
Constraints on package "npm-bcrypt":
* npm-bcrypt#=0.7.8_2 <- accounts-password 1.1.1
* npm-bcrypt#=0.7.7 <- okland:accounts-phone 0.0.10*
This is a problem with the older versions of bycrpt and the old accounts-base package it depends on. I recently made a pull request to the okland:accounts-phone package which updates accounts-phone to depend on accounts-password and a newer bycrpt version.
Alternatively, if you don't want to wait, you can download his repo locally (okland:accounts-phone) into a packages dir at the root level of your project, and change the packages.js file as such:
Package.describe({
name : 'accounts-phone',
--skipped some lines--
Package.onUse(function (api) {
-api.use('npm-bcrypt#=0.7.8_2', 'server');
+api.use('npm-bcrypt#=0.8.7_1', 'server');
-api.use('accounts-base#1.0.2', ['client', 'server']);
+api.use('accounts-password#1.2.14', ['client', 'server']);
// Export Accounts (etc) to packages using this one.
-api.imply('accounts-base#1.0.2', ['client', 'server']);
+api.imply('accounts-password#1.2.14', ['client', 'server']);
(Make sure to get rid of the '+' and '-', they're just there to indicate what's deleted and what's new). Then, add the local using meteor add accounts-phone'. It will work just fine.

Meteor: Could not resolve the specified constraints for this project: Unknown package

What are the constraints that Meteor is trying to resolve when it loads the packages at startup? Is it all related to versioning or is it actually looking at the code that you load with ap.use() in packages.js?
I am getting this error when I try to start up my project. I have a super-simple package file that I created with the meter create --package command. I put all of my files that make up the package into the directory that it created and moved that directory to .meteor/packages. I'm just trying to create a local package for now. Here's the contents of package.js in that directory:
Package.describe({
name: 'ammap-meteor',
summary: 'mapping library packaged for meteor ',
version: '1.0.0',
});
Package.onUse(function(api) {
api.versionsFrom('METEOR#0.9.0');
api.addFiles('ammap.js');
api.addFiles('ammap_amcharts_extension.js');
});
Package.onTest(function(api) {
api.use('tinytest');
api.use('ammap-meteor');
api.addFiles('ammap-meteor-tests.js');
});
My ammap-meteor-tests.js file is blank for the moment but it exists. Would that make a difference? And I assume you just omit the git: property from Package.onUse() for a local package, is that right?
OK, I was able to get past that error with the publish command:
meteor publish --create
So I did not succeed in making a local package (still not clear on that) but at least I can get the package to load now.

Reactive Code without mongodb in Meteor and using NPM packages with Meteor

I am playing around with Meteor and I am trying, to connect the serverside of the application to another server S.
Therefore I want to open an TLS client socket and push the received data to the client, every time the server S transmits data.
Now I have two questions:
Can I require node packages in the usual way (e.g. var Candle = require('candle');)?
Is it possible, to create reactive code without writing the received data to a collection, which is stored in the mongodb database?
In other words, I just want to push the data to all clients, without saving it on the server.
1
To require a npm package, you need to install npm package via mrt add npm.
Then you add packages.json file with the list of necessary packages, for example:
{
"candle": "0.4.0",
"oauth": "0.9.11"
}
Afterwards, you can require the package with Meteor.require('candle');.
2
To create a reactive code you use Dependencies – see the documentation. Basically, you create a dep:
var dep = new Deps.Dependency();
mark the functions that should be recalculated when the dep is changed:
Templates.example.something = function() {
dep.depend();
...
}
And then change it when necessary:
dep.changed();
I can only answer your first question.
In order to integrate npm packages, you should add npm package via meteorite and create a packages.json file as documented here: https://github.com/arunoda/meteor-npm
Then you can load npm modules as follows:
var Candle = Meteor.require('candle');

Resources