meteor publish composite does not - meteor

I have problems when I try use meteor-publish-composite. I see this page https://github.com/englue/meteor-publish-composite and I execute the following code in my meteor project:
meteor add reywood:publish-composite
I create publish-composite function like this:
import { Meteor } from 'meteor/meteor';
import { Categories } from '../../../../both/collections/administration/category.collection';
import { Structures } from '../../../../both/collections/administration/structure.collection';
//Meteor.publish('categories', () => Categories.find());
Meteor.publishComposite('categoriesWithStructures', {
find: () => {
return Categories.collection.find();
},
children: [{
find:(category) => {
console.log(category);
return Structures.collection.find({_id: category.structure});
}
}]
});
But when I initialize the project, in the console I see the message:
Property 'publishComposite' does not exist on type 'typeof Meteor'
In the .meteor/packages file the meteor module is added
angular2-compilers
accounts-password
msavin:mongol
reywood:publish-composite
My meteor project use Angular2.
I will appreciate any help. Regards.

I have the same problem.
My solution looks like
Meteor["publishComposite"] (...)
instead of
Meteor.publishComposite (...)
I'm also using typescript for meteor, and I think that its not bet combo (yet).

Related

Meteor packages dynamic imports fail with templating as weak dependency

The Package
I have a shared library as Meteor package with the following structure:
ui
- componentA.html
- componentA.js
- loader.js
- ...
tools
- toolXY.js
- ...
and while tools are shared among many of my apps (and the ui), the ui part is only used by one app. Consider the template to be totally simple:
componentA.html
<template name="componentA">
<span>yea component A</span>
</template>
componentA.js
import { Template } from 'meteor/templating'
import { toolXY } from '../tools/toolXY'
import './componentA.html'
// ... template code
loader.js (little helper, think the package has 100 ui components)
export const loader = {
componentA: {
template: 'componentA',
load: async function () {
return import('./componentA')
}
}
}
Because the ui is used in one app only, I made the templating and dynamic-import a weak dependency:
Package.onUse(function (api) {
api.versionsFrom('1.6')
api.use('ecmascript')
api.use('dynamic-import', ['client'], { weak: true })
api.use('templating', ['client'], { weak: true })
})
The Problem
I add my package and the weak dependencies to a project via
$ meteor add dynamic-import templating me:mypackage
and import the ui on the client like the following:
client/main.js
import { loader } from 'meteor/me:mypackage/ui/loader'
Meteor.startup(() => {
loader.componentA.load()
.then(() => console.log('loaded'))
.catch(e => console.error(e))
})
It will result in the following error:
Error: "Cannot find module './componentA.html'"
makeMissingError http://localhost:5050/packages/modules-runtime.js?hash=23fe92393aa44a7b01bb53a510a9cab5fb43037c:232
resolve http://localhost:5050/packages/modules-runtime.js?hash=23fe92393aa44a7b01bb53a510a9cab5fb43037c:238
moduleLink http://localhost:5050/packages/modules.js?hash=88e9e724ccc8459066fbe9e3889ef37c7bb7067f:353
module /node_modules/meteor/me:mypackage/ui/componentA.js:16
makeModuleFunction http://localhost:5050/packages/dynamic-import.js?hash=cf582bcc349503492678c9fd3f7bba4a610f70e5:138
fileEvaluate http://localhost:5050/packages/modules-runtime.js?hash=23fe92393aa44a7b01bb53a510a9cab5fb43037c:346
require http://localhost:5050/packages/modules-runtime.js?hash=23fe92393aa44a7b01bb53a510a9cab5fb43037c:248
moduleLink http://localhost:5050/packages/modules.js?hash=88e9e724ccc8459066fbe9e3889ef37c7bb7067f:360
getNamespace http://localhost:5050/packages/dynamic-import.js?hash=cf582bcc349503492678c9fd3f7bba4a610f70e5:187
dynamicImport http://localhost:5050/packages/dynamic-import.js?hash=cf582bcc349503492678c9fd3f7bba4a610f70e5:40
Checking for Package.templating inside loader.js, as well as componentA.js resolves to Object { Template: Template(viewName, renderFunction) } (because it has been installed as package to the project).
The fix that isn't really a fix
If I turn off the weak dependency on templating it will work fine:
api.use('templating')
This, however, will cause all my applications to load templating, allthough they do not require it.
The question
Why is it behaving like this? Shouldn't this work with weak dependency when the dependency has been added to the project?

TypeError: Cannot read property <template name> of undefined when creating package

I am trying to create a package for Meteor, unsuccessfully unfortunately. I'm on Meteor 1.8.1. My goal is to make a template for a button that I can use in my application like this {{> testButton}} (I am just trying it out atm).
package.js
Package.describe({
name: 'button-test',
version: '0.0.1',
summary: '',
git: '',
documentation: 'README.md'
});
Package.onUse(function (api) {
api.use(['ecmascript']);
api.use(['session', 'templating'], ['client', 'server']);
api.mainModule('button-test.js');
});
Package.onTest(function (api) {
api.use('ecmascript');
api.use('tinytest');
api.use('button-test');
api.mainModule('button-test-tests.js');
});
button-test.js
// Variables exported by this module can be imported by other packages and
// applications. See button-test-tests.js for an example of importing.
import './testButton.js';
testButton.js
import { Template } from 'meteor/templating';
Template.testButton.events({
'click #buttonT': () =>
console.log('Clicked the button')
});
testButton.html
<template name="testButton"><button id="buttonT">TEST</button></template>
I have some problems with this;
Running the code like this returns the error TypeError: Cannot read property 'testButton' of undefined. So there is a problem with Template, but I don't know what it is, since I have added it with api.use
When I try to add import ./testButton.html to testButton.js I get the error Error: Cannot find module './testButton.html'
I looked at the source code for accounts-ui-unstyled, but this is written on an older meteor version.
Does anybody have an idea as to what I am doing wrong?
The problem was with the api.mainModule, I solved it by having my Package.onUse like this:
Package.onUse(function (api) {
api.use(['templating', 'blaze'], 'client');
api.use('ecmascript');
api.addFiles(['button-test.js'], 'client');
});
After using the addFiles instead of mainModule, I could import the html and the Template problem disappeared. I have no idea why this works and mainModule does not, but hey, it does.

Can't access Meteor.user() property

I've installed a Meteor phone authentication package mys:accounts-phone, which should add a phone.number subfield into users collection. I try to access this field as follows:
Meteor.user().phone.number
but typescript shows error
Property 'phone' does not exist on type 'User'.
On the other hand, I have custom props in users.profile, and can easily access them in this way.
Insecure is not yet removed. Autopublish is ON.
this happens sometime when our angular component is initialized but our meteor data is not reached from server.
try to use user injection in place of Meteor.user()
import {Component} from "#angular/core";
import { InjectUser } from 'angular2-meteor-accounts-ui';//<--**** import this****
#Component({
selector: "login-buttons",
template
})
#InjectUser('user') //<--*** add this***
export class LoginButtonsComponent {
user: Meteor.User; //<--*** add this ***
constructor(private router: Router) {}
}
now in user variable you will have all values of Meteor.User
if you want to print in html part use this
<div *ngIf="user">
{{user.phone.number}}
</div>
don't forget to install
meteor add accounts-password
meteor npm install --save angular2-meteor-accounts-ui
and in app.module.ts file
import { AccountsModule } from 'angular2-meteor-accounts-ui';
#NgModule({
imports: [
... other modules here
AccountsModule
],
hope this will work. if this not work let me know i will tell you one other solution
Got probable answer from Meteor docs.
It explains why username property appears. By default, Meteor publish only a number of fields considered to be public. To exposure any additional fields they must be published explicitly.
Not yet have time to test, but think it should work.
The other reason, with the same sympthoms, when publication code do not executed at server side. Try to put
Meteor.startup(() => {
// code to run on server at startup
Meteor.publish('userData', function() {
if(!this.userId) return null;
return Meteor.users.find(this.userId
//, {fields: {lastname: 1,}}
);
});
});
in a file within /server folder of your application.

Meteor Package - Iron:router - How to prevent my package routes to execute the hooks of the apps that use it?

I am creating a meteor package using iron:router, it works great.
The routes logic of this package is very specific.
But as soon as I add this package in a Meteor app that is also using iron:router, the hooks defined by the Meteor app (onBeforeAction, onAfterAction, ...) are called for the routes created by the package.
I'd like to prevent my package routes to execute the hooks of the app.
Is there a simple piece of code I could use to isolate the routes of my package from the "external" hooks? Maybe I could create a specific RouteController?
The last option for me is to implement a router from scratch...
Thank you!
The code that solved my issue is the following:
let MyRouter = new Iron.Router;
MyRouter.onBeforeAction(Iron.Router.bodyParser.json());
MyRouter.onBeforeAction(Iron.Router.bodyParser.urlencoded({extended: false}));
The solution is to declare a new isolated router. The 2 lines under the router declaration enable to retrieve the data of POST requests.
Yes, you need to create isolated controller:
var MyPackageController = RouteController.extend({
onBeforeAction: function () { ... },
onAfterAction: function () { ... }
/* other options */
});
Router.map(function () {
this.route('packageRoute', {
controller: MyPackageController
/* other options */
});
});

"moment is undefined" when launching angular app in node-webkit

I want to launch my angular application which works in general, but when I get to use moment I got the error that "moment" is undefined.
I am using "angular-moment" from here
var app = angular.module("MyApp",
[
"ngRoute",
"ui.bootstrap",
"angularMoment",
'angular-jwt',
'angular-storage'
]);
My package.json looks like this
{
"name": "myapp",
"main": "index.html",
"toolbar":"true",
"dependencies": {
"moment": "*"
}
}
I am trying to use it with
app.config(function (moment) {
moment().format();
});
which says that moment ist undefined.
How do I have to modify my package.json to get node-webkit find moment? Or Angular-Moment?
Thanks in advance.
Make sure you have both moment and angular-moment loading in your HTML file.
Follow the instructions on the angular-moment github page. I don't think moment().format(); is valid because moment should not be a function..
Also try including "node-remote": "<local>" in your package.json file.
I encountered the same problem, I use this code snippet to solve it. You should replace vendor.js with your own files suce as angular, moment.
<script>
//hide global object
try {
window.globalTmp = global;
global = undefined;
} catch (e) {}
</script>
<script src="vendor.js"></script>
<script>
//recover global object
try {
global = window.globalTmp;
window.globalTmp = undefined;
} catch (e) {}
</script>
moment is undefined because it's added to global other than window. global is an object of node-webkit.If you type global in console, you will find global.moment in output.
I found this snippet in moment's source code which can support my explain.
var moment,
VERSION = '2.8.4',
// the global-scope this is NOT the global object in Node.js
globalScope = typeof global !== 'undefined' ? global : this,

Resources