-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node-legacy): initial setup + version bumps (#323)
* chore(node): bump all * feat(node-legacy): initial setup * update make file
- Loading branch information
Showing
17 changed files
with
9,545 additions
and
1,057 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
# node | ||
node_modules | ||
node/stroeer | ||
node-legacy/stroeer | ||
bin/protoc | ||
*.tgz | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
engine-strict=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# @stroeer/tapir-v1 | ||
|
||
## Usage | ||
|
||
```bash | ||
npm i @stroeer/tapir-v1-legacy | ||
# or | ||
yarn add @stroeer/tapir-v1-legacy | ||
``` | ||
|
||
## Development | ||
|
||
Make sure you generated the gRPC models and services for node. | ||
|
||
### node | ||
|
||
```bash | ||
# https://github.com/nvm-sh/nvm#installing-and-updating | ||
brew install nvm | ||
|
||
# add this to your shell/bash profile: | ||
# source /usr/local/opt/nvm/nvm.sh | ||
|
||
nvm install 14 | ||
nvm use 14 | ||
# optional | ||
nvm alias system 14 | ||
``` | ||
|
||
### install | ||
|
||
```bash | ||
npm i | ||
``` | ||
|
||
### Test/Lint | ||
|
||
```bash | ||
npm run test | ||
npm run lint | ||
``` | ||
|
||
## How to update jest snapshots | ||
|
||
```bash | ||
npm run test -- --u | ||
``` | ||
|
||
## Helpful resources | ||
|
||
Examples for generating TypeScript types of generated services / models. | ||
|
||
https://github.com/badsyntax/grpc-js-typescript | ||
|
||
## Example Script | ||
|
||
A very basic example script to call the article page via the given node module and log the plain text to console. The `GRPC_SERVICE` variable needs to be set via environment variables or replaced in code to get this snippet to work. | ||
|
||
```js | ||
import ArticlePageService from '@stroeer/tapir-v1/stroeer/page/article/v1/article_page_service_pb.js'; | ||
import { ArticlePageServiceClient } from '@stroeer/tapir-v1/stroeer/page/article/v1/article_page_service_grpc_pb.js'; | ||
import { ChannelCredentials } from 'grpc'; | ||
|
||
// Client | ||
const credentials = ChannelCredentials.createSsl(); | ||
const client = new ArticlePageServiceClient(process.env.GRPC_SERVICE, credentials); | ||
|
||
// Request | ||
const request = new ArticlePageService.GetArticlePageRequest(); | ||
// Set Article Id | ||
request.setId(87971076); | ||
|
||
// Content | ||
const page = client.getArticlePage(request, (err, response) => { | ||
const page = response.getArticlePage(); | ||
const article = page.getArticle(); | ||
|
||
let articleText = ''; | ||
|
||
function handleChild(child) { | ||
const children = child.getChildrenList(); | ||
if (children.length > 0) { | ||
children.forEach(child => handleChild(child)); | ||
} else { | ||
articleText += child.getText(); | ||
} | ||
} | ||
|
||
const bodyNodes = article.getBody().getChildrenList(); | ||
|
||
bodyNodes.forEach(handleChild); | ||
|
||
console.log(articleText); | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { expect, test } from '@jest/globals'; | ||
import CoreArticleService from '../stroeer/core/v1/core_article_service_grpc_pb'; | ||
import ArticlePageService from '../stroeer/page/article/v1/article_page_service_grpc_pb'; | ||
import SectionPageService from '../stroeer/page/section/v1/section_page_service_grpc_pb'; | ||
import FragmentStageService from '../stroeer/fragment/v1/stage_service_grpc_pb'; | ||
|
||
test('gRPC core article service client is generated and matches the snapshot', () => { | ||
expect(CoreArticleService).toMatchInlineSnapshot(` | ||
Object { | ||
"ArticleServiceClient": [Function], | ||
"ArticleServiceService": Object { | ||
"getArticle": Object { | ||
"path": "/stroeer.core.v1.ArticleService/GetArticle", | ||
"requestDeserialize": [Function], | ||
"requestSerialize": [Function], | ||
"requestStream": false, | ||
"requestType": [Function], | ||
"responseDeserialize": [Function], | ||
"responseSerialize": [Function], | ||
"responseStream": false, | ||
"responseType": [Function], | ||
}, | ||
"listArticles": Object { | ||
"path": "/stroeer.core.v1.ArticleService/ListArticles", | ||
"requestDeserialize": [Function], | ||
"requestSerialize": [Function], | ||
"requestStream": false, | ||
"requestType": [Function], | ||
"responseDeserialize": [Function], | ||
"responseSerialize": [Function], | ||
"responseStream": false, | ||
"responseType": [Function], | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
test('gRPC article page service client is generated and matches the snapshot', () => { | ||
expect(ArticlePageService).toMatchInlineSnapshot(` | ||
Object { | ||
"ArticlePageServiceClient": [Function], | ||
"ArticlePageServiceService": Object { | ||
"getArticlePage": Object { | ||
"path": "/stroeer.page.article.v1.ArticlePageService/GetArticlePage", | ||
"requestDeserialize": [Function], | ||
"requestSerialize": [Function], | ||
"requestStream": false, | ||
"requestType": [Function], | ||
"responseDeserialize": [Function], | ||
"responseSerialize": [Function], | ||
"responseStream": false, | ||
"responseType": [Function], | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
test('gRPC section page service client is generated and matches the snapshot', () => { | ||
expect(SectionPageService).toMatchInlineSnapshot(` | ||
Object { | ||
"SectionPageServiceClient": [Function], | ||
"SectionPageServiceService": Object { | ||
"getSectionPage": Object { | ||
"path": "/stroeer.page.section.v1.SectionPageService/GetSectionPage", | ||
"requestDeserialize": [Function], | ||
"requestSerialize": [Function], | ||
"requestStream": false, | ||
"requestType": [Function], | ||
"responseDeserialize": [Function], | ||
"responseSerialize": [Function], | ||
"responseStream": false, | ||
"responseType": [Function], | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
test('gRPC fragment stage service client is generated and matches the snapshot', () => { | ||
expect(FragmentStageService).toMatchInlineSnapshot(` | ||
Object { | ||
"StageServiceClient": [Function], | ||
"StageServiceService": Object { | ||
"getStages": Object { | ||
"path": "/stroeer.fragment.v1.StageService/GetStages", | ||
"requestDeserialize": [Function], | ||
"requestSerialize": [Function], | ||
"requestStream": false, | ||
"requestType": [Function], | ||
"responseDeserialize": [Function], | ||
"responseSerialize": [Function], | ||
"responseStream": false, | ||
"responseType": [Function], | ||
}, | ||
}, | ||
} | ||
`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
preset: 'ts-jest' | ||
}; |
Oops, something went wrong.