why using var {google} instead of var google in google.auth.OAuth - google-api-nodejs-client

This code is from oauth nodesjs.
I want to ask why we are using '{}' around the var google? I also tried using it without '{}' and got error OAuth2 is undefined. i can't understand what is happening here.
var {google} = require('googleapis');
var OAuth2 = google.auth.OAuth2;

To add a little to this answer - this is what's called a destructuring assignment. You can read about them here:
http://2ality.com/2015/01/es6-destructuring.html
The code you're looking at here:
const {google} = require('googleapis');
Is the same as code that looks like this:
const google = require('googleapis').google;
This is just a convenient shorthand that was added in es6. We made the change in the googleapis package when we moved towards ES modules, which don't play nicely with the export=foo style syntax. Hope this helps!

According to the Changelog from google-api-nodejs-client, there are some changes from V26.0.0 onwards that you have to implement in your code, precisely the issue you are experiencing is mentioned. I also took a while to figure this one out...
BREAKING CHANGE: This library is now optimized for es6 modules. In previous versions you would import the library like this:
const google = require('googleapis');
In this and future versions, you must use a named import:
const {google} = require('googleapis');
You may also reference the type to instantiate a new instance:
const {GoogleApis} = require('googleapis');
const google = new GoogleApis();

Related

How to check whether the user is a new user or not in #assistant/conversation package

In the actions-on-google package I have used the following logic to check whether the user is a new user or not.
conv.user.last.seen
But in the new #assistant/conversation package i have used the same logic but it fails stating that the seen is not found. I tried the following logic which shows the current date and time which makes the logic to pass all time.
conv.user.lastSeenTime
Does anyone tried to show whether the user is a new or not in the new #assistant/conversation package?
I ‘m dealing with a similar issue of how to differentiate between new vs returning users with google console’s action builder. The Main invocation is the part of the conversation I'm using this in. (Brand new to the forum so forgive me if I didn’t grasp your question.) I used the same logic as you did, and it did deploy correctly for me using the cloud function's inline editor for the webhook. So I ‘m not entirely sure what’s going on but here are some resources. The following tutorial and code was helpful/ worked for me (https://youtu.be/nVbwk4UKHWw?t=700 )
const { conversation } = require('#assistant/conversation');
const functions = require('firebase-functions');
const app = conversation({debug:true});
app.handle('greeting', conv => {
let message = 'Welcome to App';
if (conv.user.lastSeenTime) {
message = 'Welcome back to App!';
}
conv.add(message);
});
exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app);

How to get access to Developer: Inspect TM Scopes data? [duplicate]

I have used the tokenizer in monaco but I do not see that it is accessible in vscode. This would be helpful for completion/signature help providers, how can I tokenize a grammar?
It doesn't seem like there's an official way of doing this right now. There is an open feature request for adding the ability to retrieve tmLanguage scopes at a position here: #580
There is one potential workaround, which requires adding a dependency to the scope-info extension. This extension exposes an API of its own that other extension can use. Here's a code example posted by the author in the linked issue:
import * as api from 'scope-info'
async function example(doc : vscode.TextDocument, pos: vscode.Position) {
const siExt = vscode.extensions.getExtension<api.ScopeInfoAPI>('siegebell.scope-info');
const si = await siExt.activate();
const t1 : api.Token = si.getScopeAt(doc, pos);
}
Update: unfortunately, it looks like scope-info is no longer compatible with current VSCode versions.

How to tokenize grammars, like in monaco.editor.tokenize for use in extension

I have used the tokenizer in monaco but I do not see that it is accessible in vscode. This would be helpful for completion/signature help providers, how can I tokenize a grammar?
It doesn't seem like there's an official way of doing this right now. There is an open feature request for adding the ability to retrieve tmLanguage scopes at a position here: #580
There is one potential workaround, which requires adding a dependency to the scope-info extension. This extension exposes an API of its own that other extension can use. Here's a code example posted by the author in the linked issue:
import * as api from 'scope-info'
async function example(doc : vscode.TextDocument, pos: vscode.Position) {
const siExt = vscode.extensions.getExtension<api.ScopeInfoAPI>('siegebell.scope-info');
const si = await siExt.activate();
const t1 : api.Token = si.getScopeAt(doc, pos);
}
Update: unfortunately, it looks like scope-info is no longer compatible with current VSCode versions.

WebStorm 11 unrecognized MongoDb (with mongoose) functions

WebStorm gives me a warning of "Unrecognized function or method" on functions like:
Schema.find() [find() not recognized]
Schema.aggregate() [aggregate() not recognized]
Schema.findOneAndUpdate() [findOneAndUpdate() not recognized]
I've tried to Enabling the NodeJs core libraries and to install
mongodb-DefinitelyType
mongoose-DefinitelyType
mongoose-auto-increment-DefinitelyType
mongoose-deep-populate-DefinitelyType
mongoose-DefinitelyType
mongoose-mock-DefinitelyType
under Preferences > JavaScript > Libraries
But this has not solved my problem. Does someone knows a solution?
This issue is tracked as https://youtrack.jetbrains.com/issue/WEB-17099; please see https://youtrack.jetbrains.com/issue/WEB-17099#comment=27-1441265 for possible workaround
This is possible solution working for me without any issues.
Moving the relative path out of the require() statement as follows.
const PATH = '../models/';
const User = require(PATH + 'user');
Alternatively
Do not import Schema separately.
Just import mongoose like this
const mongoose = require('mongoose');
and use mongoose.Schema to access Schema
I don't know the reason but somehow this works:
export
module.exports.User = User; // your model
import
const User = require("../dbSchema/user.js").User;
Note that the schema is inserted correctly. Don't forget to check your Schema.
Sample
module.exports = mongoose.model('SampleCollection', SampleSchema);

YUI3 DOM is undefined?

I am newcomer to Javascript and have been tasked with migrating our product's UI from YUI2 to YUI3.
It doesn't look like there's a migration guide anywhere, so I'm browsing internet posts and the yui docs for now.
In my global scope, I've temporarily added something like var Y = YUI().use('*',function(Y){});
I've encountered a YAHOO.util.Dom.get(...) elsewhere which doesn't work with YUI3, and it looks like Y.DOM.byId(...) is the recommended migration. But, I'm getting the error that "Y.DOM" is undefined!
Whoever's using Y.DOM.(...), how did this get resolved?
I don't know where you found the idea of Y.DOM.byId
Try
var node = Y.one('#elementID');
or if you want to use classes:
var nodes = Y.all('.className');
For more information on how to get nodes in YUI3, see their documentation
EDIT:
<script>
YUI().use('node', function (Y) {
var node = Y.one('#elementID');
});
</script>