Use the google Cloud Speech-to-Text .proto File with gRPC - nestjs

I am trying to run the (https://github.com/googleapis/nodejs-speech/blob/main/protos/google/cloud/speech/v1p1beta1/cloud_speech.proto) .proto File from Google in NestJS and I get the error:
Is someone here facing the same problem?
Ps. I have written just a simple gRPC code, like:
async function bootstrap() {
const app = await NestFactory.createMicroservice(AppModule, {
transport: Transport.GRPC,
options: {
options: 'localhost:3001',
package: 'google.cloud.speech.v1p1beta1',
protoPath: join(__dirname, './speech/speech.proto'),
}
});
await app.listen();
console.log(`Microservice is listening`);
}

I'm unclear on what you're trying to do but, to answer your question, the error's arising because speech.proto depends on the file: operations.proto (link).
See this comment for what appears to be an explanation for how to do this.
Things that compile protocol buffers files, include a mechanism by which you can reference (import path) depdendent files. You should clone (at least) operations.proto (it may include further dependencies) locally and configure your code to reference the cloned directory as part of the build process.
NOTE Please include errors directly in questions rather than reference images as it's not possible to copy content from images which may help in answering questions and referenced images may be deleted leaving the question orphaned.

Related

#google-cloud/pubsub TypeError: Cannot read property 'status' of undefined

Installed the google cloud pub sub following instructions from the following link,
https://cloud.google.com/pubsub/docs/reference/libraries
Imported that as the following,
const { PubSub } = require("#google-cloud/pubsub");
const projectId = "projectXYZ";
const pubSubClient = new PubSub({ projectId });
export async function publishMessage(topicName, data) {
return await pubSubClient.topic(topicName).publish(JSON.stringify(data));
}
this leads to the following error,
Now, what I have observed is that the code below the import has no significance in this issue, since this error still appears even if I only import on the first line.
Am I missing something or required to install something more that just the package?
Any help is deeply appreciated.
Thank you in advance.
Library maintainer here! I'm guessing from the stack trace that you're using webpack on your app? Right now we don't have webpack and rollup support - there are a few weird things like what you see above. Your code looks okay. We'd like to get webpack and similar tools working at some point for server-side usage, but it hasn't gone very high on the priority list just yet. I think the previous assumption was that people were trying to use it in a web browser, which we don't recommend for a number of reasons (most prominently, security concerns with GCP credentials). But I've been seeing a lot of issues with users trying to use webpack on the server side to make their Cloud Functions more compact, which seems pretty legit. I'll bring it up in our next team sync.
If you're not using webpack, then that sounds like something that might be filed over at the issue tracker.

How to setup StencilJS components on S3 and CloudFront

I have a few components and I want to deploy them into S3 and make them reachable with CloudFront.
My problem is that I don't know what file(s) I need to upload to S3 and which file needs CloudFront needs to point to as entry point.
Here's my stencil.config.tsx:
import { Config } from '#stencil/core';
export const config: Config = {
namespace: 'stencil-test',
taskQueue: 'async',
outputTargets: [
{
type: 'dist',
esmLoaderPath: '../loader',
dir: './build/dist'
},
{
type: 'www',
serviceWorker: null // disable service workers
}
]
};
I tried executing npm run build that generated a couple of folders: build/loader and build/dist there's a lot of stuff within each folder but I have no idea how which folder and files are supposed to do what.
It was hoping the build command would generate a minified file that contained all the stuff needed (is this how it works?) so I could eventually do something like the following where I want to use my components:
<script type="module" src='https://cdn.jsdelivr.net/npm/my-name#0.0.1/dist/myname.js'></script>
Can anyone offer some guidance or point me towards any resources?
The www output target is meant for generating apps and not really relevant for component libraries. To host your components, you should upload the whole generated dist folder. Only the files that the client needs are downloaded, which depends on the client and which components they access (lazy-loading). So you don't need to worry about the amount of files. See https://stenciljs.com/docs/distribution.
To start, Stencil was designed to lazy-load itself only when the component was actually used on a page. There are many benefits to this approach, such as simply adding a script tag to any page and the entire library is available for use, yet only the components actually used are downloaded.
If you want to generate a single bundle containing all your components, there's an output target called dist-custom-elements-bundle. For the differences to dist you can have a look at the same docs link above.
One of the main differences is that loading the script doesn't automatically register the components for you, you'll have to either do it manually per component (using customElements.define(), or define them all using the defineCustomElements() export. The official documentation for that output target is https://stenciljs.com/docs/custom-elements.

Gatsby Failed Build - error "window" is not available during server side rendering

I have been trying to build my gatsby (react) site recently using an external package.
The link to this package is "https://github.com/transitive-bullshit/react-particle-animation".
As I only have the option to change the props from the components detail, I cannot read/write the package file where it all gets together in the end as it is not included in the public folder of 'gatsby-build'.
What I have tried:
Editing the package file locally, which worked only on my machine but when I push it to netlify, which just receives the public folder and the corresponding package.json files and not the 'node-modules folder', I cannot make netlify read the file that I myself changed, as it requests it directly from the github page.
As a solution I found from a comment to this question, we can use the "Patch-Package" to save our fixes to the node module and then use it wherever we want.
This actually worked for me!
To explain how I fixed it: (As most of it is already written in the "Patch Package DOCS), so mentioning the main points:
I first made changes to my local package files that were giving the error.(For me they were in my node_modules folder)
Then I used the Patch Package Documentation to guide my self through the rest.
It worked after I pushed my changes to github such that now, Patch Package always gives me my edited version of the node_module.
When dealing with third-party modules that use window in Gatsby you need to add a null loader to its own webpack configuration to avoid the transpilation during the SSR (Server-Side Rendering). This is because gatsby develop occurs in the browser (where there is a window) while gatsby build occurs in the Node server where obviously there isn't a window or other global objects (because they are not even defined yet).
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
if (stage === "build-html") {
actions.setWebpackConfig({
module: {
rules: [
{
test: /react-particle-animation/,
use: loaders.null(),
},
],
},
})
}
}
Keep in mind that the test value is a regular expression that will match a folder under node_modules so, ensure that the /react-particle-animation/ is the right name.
Using a patch-package may work but keep in mind that you are adding an extra package, another bundled file that could potentially affect the performance of the site. The proposed snippet is a built-in solution that is fired when you build your application.

ArangoDB: getting started with Foxx Microservices: 404: errorMessage: unknown path

Using ArangoDB documentation version 3.3 or version 3.4 for the Getting Started section of Foxx Microservices, I can't get past this error:
Failed to load API definition.
NetworkError when attempting to fetch resource. http://192.168.1.1:8529/_db/_system/_admin/aardvark/foxxes/docs/swagger.json?mount=/getting-started
That error is shown on the API tab of the service. After installing my service according to the tutorial, I get the service's card as described. I click that card and then click the API tab and the above error is shown.
To eliminate typos, I have tried copying and pasting the exact file contents from the ArangoDB documentation and following every step exactly, and I still get the same error.
The Info tab of my newly created getting-started service contains this info:
Author:
Mount: /getting-started
Mode: Development
Version: Unknown
Version License: Unknown License
Path: /var/lib/arangodb3-apps/_db/_system/getting-started/APP
The example contains only two files and they are:
manifest.json
{
"engines": {
"arangodb": "^3.0.0"
},
"main": "index.js"
}
index.js
'use strict';
const createRouter = require('#arangodb/foxx/router');
const router = createRouter();
module.context.use(router);
router.get('/hello-world', function (req, res) {
res.send('Hello World!');
})
.response(['text/plain'], 'A generic greeting.')
.summary('Generic greeting')
.description('Prints a generic greeting.');
The canned demo services, such as the hello-fox example, work correctly. I collected more error information:
Navigating to http://192.168.1.1:8529/getting-started
404: errorMessage "unknown path '/getting-started'"
Navigating to http://192.168.1.1:8529/_db/_system/getting-started
404: errorMessage "unknown path '/getting-started'"
The console also shows:
WARNING File not found "/getting-started": file "" does not exist in "/var/lib/arangodb3-apps/_db/_system/getting-started/APP/files".
The tutorial doesn't indicate another file named getting-started or another location for the two specified files. What am I missing?
This issue was resolved based on the helpful comments by #camba1. There was no problem with Arango, just a problem with me understanding the tutorial. For others in my position, here are the things I did not understand properly and that, when addressed, resolved my problems.
The API tab, in contrast to what the tutorial says, will give the error "Failed to load API definition" even for a correctly working service. Ignore that error message. I am not yet using the API tab at all.
the tutorial refers to two paths, '/hello-world' and '/getting-started'. These are used on the endpoint (URI) and in creating the router like below:
router.get('/hello-world', function (req, res) { ...
The tutorial wasn't as clear as it could have been on this point, but as #camba1 pointed out, the service endpoint would end up incorporating both of those elements:
192.168.1.1:8529/_db/_system/getting-started/hello-world .
this very basic demo is easier and better in my opinion when the router is created without a path:
router.get(function (req, res) {
In this case it defaults to a path of '/'. I think this may avoid confusion for raw beginners like me. The service endpoint then becomes one element simpler. In my case, the endpoint (with Arango running on another computer on the LAN) becomes:
192.168.1.1:8529/_db/_system/getting-started
The tutorial would be improved if it either added a couple extra sentences to explain how the endpoint is constructed, or alternatively, did as I suggested above and simplified things by one step.

Serverless Framework with Azure functions

I am writing services with Serverless Framework & Azure Functions. Examples out there are very simple. But when I try to take a step further, I run into problem. Currently learning from AWS Lambda and then trying to implement it on Azure Functions.
The goal of doing so is:
1) Implement functions as es6 classes and then building the project with webpack.
2) Find a right project structure, which makes more sense.
3) Follow SoC pattern.
I have created a github project https://github.com/GeekOnGadgets/serverless-azure-settings and when I try to build this project serverless package it creates .serverless folder and inside it there is .zip file (the compiled version). Which I understand gets deployed to azure when you run serverless deploy. But when I check on Azure the function is just development code and not the compiled one (please refer to the code below).
Can someone please help with this. Any suggestions is appreciated.
import Settings from './src/Settings/Settings'
module.exports.settings = (event, context, callback) => {
let settings = new Settings();
const response = {
statusCode: 200,
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(settings.dev()),
};
callback(null, response);
}
Indeed javascript azure functions run on nodejs so commonjs modules are the natural format. Node also natively supports much of ES6, though the Functions version of node might not be the latest.
however, there is a current speed issue with loading all the dependencies in node_modules. This is due to file access so a workaround exists to bundle everything into a single script which package.json -> main points to.
I cant comment on how that fits in with serverless, but perhaps this will help clarify.
As far as I know, Node.js still does not support import/export ES6 syntax for modules. See also here.
Try a new deploy changing from
import Settings from './src/Settings/Settings'
to
const Settings = require('./src/Settings/Settings')

Resources