mirror of
https://github.com/standardnotes/server
synced 2026-04-24 06:01:43 -04:00
Compare commits
44 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7f4776b52b | |||
| d20f03127a | |||
| 4b6c7774e0 | |||
| d02bca8879 | |||
| 5e654ccf94 | |||
| 7d3e5c22fb | |||
| 23eb61ee5f | |||
| 2cded4b2d1 | |||
| ba7662fc1e | |||
| 832a48ac76 | |||
| 2db0c125fe | |||
| 20d9624bc6 | |||
| f20ee68f50 | |||
| cbf45ce3eb | |||
| 2e7fdd93dd | |||
| 8ce38f82b5 | |||
| ec5429eeec | |||
| 4b17c4045d | |||
| aaf42e4693 | |||
| 0e3cbfc40b | |||
| a95ca05c10 | |||
| 56b600dbdc | |||
| 80a013d0a3 | |||
| 7ef59bb74c | |||
| 9cf1a9e25c | |||
| 0fce6c0cd4 | |||
| 2d444e9aa0 | |||
| 7c393b1125 | |||
| 78ab4dc94d | |||
| 6a5904cfaa | |||
| a6061ec2a9 | |||
| 51c777304b | |||
| fbd535f2c5 | |||
| 7d456671c2 | |||
| dd4924c925 | |||
| f73129cd7e | |||
| 4983c8741e | |||
| c5798640ff | |||
| 5803a8018a | |||
| e2aae8ac8a | |||
| 2917aeeb32 | |||
| 9377c03c3f | |||
| 9b926fbad6 | |||
| 8db19c3e2b |
@@ -11,19 +11,18 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
call_server_application_workflow:
|
||||
name: Server Application
|
||||
uses: standardnotes/server/.github/workflows/common-server-application.yml@main
|
||||
call_server_utility_workflow:
|
||||
name: Server Utility
|
||||
uses: standardnotes/server/.github/workflows/common-server-utility.yml@main
|
||||
with:
|
||||
service_name: analytics
|
||||
workspace_name: "@standardnotes/analytics"
|
||||
e2e_tag_parameter_name: analytics_image_tag
|
||||
deploy_web: false
|
||||
package_path: packages/analytics
|
||||
secrets: inherit
|
||||
|
||||
newrelic:
|
||||
needs: call_server_application_workflow
|
||||
needs: call_server_utility_workflow
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
name: Reusable Server Utility Workflow
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
service_name:
|
||||
required: true
|
||||
type: string
|
||||
workspace_name:
|
||||
required: true
|
||||
type: string
|
||||
deploy_web:
|
||||
required: false
|
||||
default: true
|
||||
type: boolean
|
||||
deploy_worker:
|
||||
required: false
|
||||
default: true
|
||||
type: boolean
|
||||
package_path:
|
||||
required: true
|
||||
type: string
|
||||
secrets:
|
||||
DOCKER_USERNAME:
|
||||
required: true
|
||||
DOCKER_PASSWORD:
|
||||
required: true
|
||||
CI_PAT_TOKEN:
|
||||
required: true
|
||||
AWS_ACCESS_KEY_ID:
|
||||
required: true
|
||||
AWS_SECRET_ACCESS_KEY:
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
outputs:
|
||||
temp_dir: ${{ steps.bundle-dir.outputs.temp_dir }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Create Bundle Dir
|
||||
id: bundle-dir
|
||||
run: echo "temp_dir=$(mktemp -d -t ${{ inputs.service_name }}-${{ github.sha }}-XXXXXXX)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Cache build
|
||||
id: cache-build
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
packages/**/dist
|
||||
${{ steps.bundle-dir.outputs.temp_dir }}
|
||||
key: ${{ runner.os }}-${{ inputs.service_name }}-build-${{ github.sha }}
|
||||
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
node-version-file: '.nvmrc'
|
||||
|
||||
- name: Build
|
||||
run: yarn build ${{ inputs.package_path }}
|
||||
|
||||
- name: Bundle
|
||||
run: yarn workspace ${{ inputs.workspace_name }} bundle --no-compress --output-directory ${{ steps.bundle-dir.outputs.temp_dir }}
|
||||
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
needs: build
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Cache build
|
||||
id: cache-build
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
packages/**/dist
|
||||
${{ needs.build.outputs.temp_dir }}
|
||||
key: ${{ runner.os }}-${{ inputs.service_name }}-build-${{ github.sha }}
|
||||
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
node-version-file: '.nvmrc'
|
||||
|
||||
- name: Build
|
||||
if: steps.cache-build.outputs.cache-hit != 'true'
|
||||
run: yarn build ${{ inputs.package_path }}
|
||||
|
||||
- name: Lint
|
||||
run: yarn lint:${{ inputs.service_name }}
|
||||
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
needs: build
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Cache build
|
||||
id: cache-build
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
packages/**/dist
|
||||
${{ needs.build.outputs.temp_dir }}
|
||||
key: ${{ runner.os }}-${{ inputs.service_name }}-build-${{ github.sha }}
|
||||
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
node-version-file: '.nvmrc'
|
||||
|
||||
- name: Build
|
||||
if: steps.cache-build.outputs.cache-hit != 'true'
|
||||
run: yarn build ${{ inputs.package_path }}
|
||||
|
||||
- name: Test
|
||||
run: yarn test ${{ inputs.package_path }}
|
||||
|
||||
publish:
|
||||
needs: [ build, test, lint ]
|
||||
|
||||
name: Publish Docker Image
|
||||
uses: standardnotes/server/.github/workflows/common-docker-image.yml@main
|
||||
with:
|
||||
service_name: ${{ inputs.service_name }}
|
||||
bundle_dir: ${{ needs.build.outputs.temp_dir }}
|
||||
package_path: ${{ inputs.package_path }}
|
||||
workspace_name: ${{ inputs.workspace_name }}
|
||||
secrets: inherit
|
||||
|
||||
deploy-web:
|
||||
if: ${{ inputs.deploy_web }}
|
||||
|
||||
needs: publish
|
||||
|
||||
name: Deploy Web
|
||||
uses: standardnotes/server/.github/workflows/common-deploy.yml@main
|
||||
with:
|
||||
service_name: ${{ inputs.service_name }}
|
||||
docker_image: ${{ inputs.service_name }}:${{ github.sha }}
|
||||
secrets: inherit
|
||||
|
||||
deploy-worker:
|
||||
if: ${{ inputs.deploy_worker }}
|
||||
|
||||
needs: publish
|
||||
|
||||
name: Deploy Worker
|
||||
uses: standardnotes/server/.github/workflows/common-deploy.yml@main
|
||||
with:
|
||||
service_name: ${{ inputs.service_name }}-worker
|
||||
docker_image: ${{ inputs.service_name }}:${{ github.sha }}
|
||||
secrets: inherit
|
||||
@@ -11,19 +11,18 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
call_server_application_workflow:
|
||||
name: Server Application
|
||||
uses: standardnotes/server/.github/workflows/common-server-application.yml@main
|
||||
call_server_utility_workflow:
|
||||
name: Server Utility
|
||||
uses: standardnotes/server/.github/workflows/common-server-utility.yml@main
|
||||
with:
|
||||
service_name: event-store
|
||||
workspace_name: "@standardnotes/event-store"
|
||||
e2e_tag_parameter_name: event_store_image_tag
|
||||
deploy_web: false
|
||||
package_path: packages/event-store
|
||||
secrets: inherit
|
||||
|
||||
newrelic:
|
||||
needs: call_server_application_workflow
|
||||
needs: call_server_utility_workflow
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
||||
@@ -11,19 +11,18 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
call_server_application_workflow:
|
||||
name: Server Application
|
||||
uses: standardnotes/server/.github/workflows/common-server-application.yml@main
|
||||
call_server_utility_workflow:
|
||||
name: Server Utility
|
||||
uses: standardnotes/server/.github/workflows/common-server-utility.yml@main
|
||||
with:
|
||||
service_name: scheduler
|
||||
workspace_name: "@standardnotes/scheduler-server"
|
||||
e2e_tag_parameter_name: scheduler_image_tag
|
||||
deploy_web: false
|
||||
package_path: packages/scheduler
|
||||
secrets: inherit
|
||||
|
||||
newrelic:
|
||||
needs: call_server_application_workflow
|
||||
needs: call_server_utility_workflow
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
||||
@@ -11,18 +11,17 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
call_server_application_workflow:
|
||||
name: Server Application
|
||||
uses: standardnotes/server/.github/workflows/common-server-application.yml@main
|
||||
call_server_utility_workflow:
|
||||
name: Server Utility
|
||||
uses: standardnotes/server/.github/workflows/common-server-utility.yml@main
|
||||
with:
|
||||
service_name: websockets
|
||||
workspace_name: "@standardnotes/websockets-server"
|
||||
e2e_tag_parameter_name: websockets_image_tag
|
||||
package_path: packages/websockets
|
||||
secrets: inherit
|
||||
|
||||
newrelic:
|
||||
needs: call_server_application_workflow
|
||||
needs: call_server_utility_workflow
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
@@ -11,18 +11,17 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
call_server_application_workflow:
|
||||
name: Server Application
|
||||
uses: standardnotes/server/.github/workflows/common-server-application.yml@main
|
||||
call_server_utility_workflow:
|
||||
name: Server Utility
|
||||
uses: standardnotes/server/.github/workflows/common-server-utility.yml@main
|
||||
with:
|
||||
service_name: workspace
|
||||
workspace_name: "@standardnotes/workspace-server"
|
||||
e2e_tag_parameter_name: workspace_image_tag
|
||||
package_path: packages/workspace
|
||||
secrets: inherit
|
||||
|
||||
newrelic:
|
||||
needs: call_server_application_workflow
|
||||
needs: call_server_utility_workflow
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Generated
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
Copyright 2022 Contrast Security, Inc
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
Generated
Vendored
+43
@@ -0,0 +1,43 @@
|
||||
# @contrast/fn-inspect
|
||||
|
||||
[](https://github.com/Contrast-Security-Inc/node-fn-inspect/actions/workflows/test.yml)
|
||||
|
||||
This module exposes some useful information from the underlying v8 engine,
|
||||
including:
|
||||
|
||||
- file and line number given a function reference
|
||||
- code events (i.e. `'LAZY_COMPILE'`)
|
||||
|
||||
## Usage
|
||||
|
||||
Getting details about a function:
|
||||
|
||||
```js
|
||||
const { funcInfo } = require('@contrast/fn-inspect');
|
||||
|
||||
function testFn() {}
|
||||
|
||||
const results = funcInfo(testFn);
|
||||
// => { lineNumber: 2, column: 15, file: 'example.js', method: 'testFn', type: 'Function' }
|
||||
```
|
||||
|
||||
Registering a listener for code events:
|
||||
|
||||
```js
|
||||
const { setCodeEventListener } = require('@contrast/fn-inspect');
|
||||
|
||||
setCodeEventListener((event) => {
|
||||
console.log(event);
|
||||
});
|
||||
```
|
||||
|
||||
## Building locally
|
||||
|
||||
`npm run build` will build the project for your current OS and architecture.
|
||||
|
||||
`npm run download` will pull the most recent build artifacts from GitHub.
|
||||
|
||||
## Publishing
|
||||
|
||||
Simply run `npm version` and `git push && git push --tags`. CI will take care of
|
||||
releasing on taggedcommits.
|
||||
Generated
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"variables" : {
|
||||
"openssl_fips": "",
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "fninspect",
|
||||
"sources": [
|
||||
"src/addon.cc",
|
||||
"src/code-events.cc",
|
||||
"src/event-queue.cc",
|
||||
"src/func-info.cc"
|
||||
],
|
||||
"include_dirs": [
|
||||
"<!(node -e \"require('nan')\")"
|
||||
],
|
||||
"conditions": [
|
||||
[
|
||||
"OS == 'mac'",
|
||||
{
|
||||
"xcode_settings": {
|
||||
"OTHER_CFLAGS": [
|
||||
"-arch x86_64",
|
||||
"-arch arm64"
|
||||
],
|
||||
"OTHER_LDFLAGS": [
|
||||
"-arch x86_64",
|
||||
"-arch arm64"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Generated
Vendored
+45
@@ -0,0 +1,45 @@
|
||||
/* eslint-disable @typescript-eslint/ban-types */
|
||||
|
||||
declare interface FunctionInfo {
|
||||
file: string;
|
||||
column: number;
|
||||
lineNumber: number;
|
||||
method: string;
|
||||
type: 'AsyncFunction' | 'Function';
|
||||
}
|
||||
|
||||
declare interface CodeEvent {
|
||||
func: string;
|
||||
lineNumber: number;
|
||||
script: string;
|
||||
type:
|
||||
| 'Builtin'
|
||||
| 'Callback'
|
||||
| 'Eval'
|
||||
| 'Function'
|
||||
| 'InterpretedFunction'
|
||||
| 'Handler'
|
||||
| 'BytecodeHandler'
|
||||
| 'LazyCompile'
|
||||
| 'RegExp'
|
||||
| 'Script'
|
||||
| 'Stub'
|
||||
| 'Relocation'
|
||||
}
|
||||
|
||||
declare const fnInspect: {
|
||||
/** Retrieves name, type, column, lineNumber and file from a function reference */
|
||||
funcInfo(fn: Function): FunctionInfo | null;
|
||||
|
||||
/**
|
||||
* Sets the function for processing v8 code events.
|
||||
* Will start listening for code events if not already listening.
|
||||
* starts a timer which polls for an available code event once every `interval` ms.
|
||||
*/
|
||||
setCodeEventListener(cb: (event: CodeEvent) => void, interval?: number): void;
|
||||
|
||||
/** Stop listening for v8 code events */
|
||||
stopListening(): void;
|
||||
};
|
||||
|
||||
export = fnInspect;
|
||||
.yarn/unplugged/@contrast-fn-inspect-npm-3.3.0-c6a8faa5b7/node_modules/@contrast/fn-inspect/index.js
Generated
Vendored
+58
@@ -0,0 +1,58 @@
|
||||
'use strict';
|
||||
|
||||
const binding = require('node-gyp-build')(__dirname);
|
||||
|
||||
let codeEventsInited = false;
|
||||
let codeEventListener = null;
|
||||
let timer = null;
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Retrieves name, type, column, lineNumber and file from a function reference
|
||||
*
|
||||
* @param {Function} fn function reference to obtain info
|
||||
* @return {FunctionInfo | null}
|
||||
*/
|
||||
funcInfo(fn) {
|
||||
const info = binding.funcInfo(fn);
|
||||
if (info === null) return null;
|
||||
|
||||
info.type = fn.constructor.name;
|
||||
return info;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the function for processing v8 code events.
|
||||
* Will start listening for code events if not already listening.
|
||||
* starts a timer which polls for an available code event once every `interval` value.
|
||||
*
|
||||
* @param {Function} cb callback function to call
|
||||
* @param {number} [interval=1] how often to get code events in ms
|
||||
*/
|
||||
setCodeEventListener(cb, interval = 1) {
|
||||
if (codeEventsInited) {
|
||||
codeEventListener = cb;
|
||||
return;
|
||||
}
|
||||
|
||||
binding.initHandler();
|
||||
codeEventsInited = true;
|
||||
codeEventListener = cb;
|
||||
timer = setInterval(() => {
|
||||
const codeEvent = binding.getNextCodeEvent();
|
||||
if (codeEvent) codeEventListener(codeEvent);
|
||||
}, interval);
|
||||
},
|
||||
|
||||
/**
|
||||
* Stop listening for v8 code events
|
||||
*/
|
||||
stopListening() {
|
||||
if (!codeEventsInited) return;
|
||||
|
||||
clearInterval(timer);
|
||||
binding.deinitHandler();
|
||||
codeEventListener = null;
|
||||
codeEventsInited = false;
|
||||
},
|
||||
};
|
||||
Generated
Vendored
+63
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"name": "@contrast/fn-inspect",
|
||||
"version": "3.3.0",
|
||||
"description": "Retrieve function name and line number from a function reference",
|
||||
"keywords": [
|
||||
"instrumentation"
|
||||
],
|
||||
"author": "Contrast Security",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Contrast-Security-Inc/node-fn-inspect.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Contrast-Security-Inc/node-fn-inspect/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Contrast-Security-Inc/node-fn-inspect#readme",
|
||||
"files": [
|
||||
"prebuilds/",
|
||||
"src/",
|
||||
"binding.gyp",
|
||||
"index.d.ts",
|
||||
"index.js"
|
||||
],
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"scripts": {
|
||||
"install": "node-gyp-build",
|
||||
"prepare": "husky install",
|
||||
"build": "prebuildify -t 12.13.0 -t 14.15.0 -t 16.9.1 -t 18.7.0 --strip",
|
||||
"build:linux": "prebuildify-cross -i centos7-devtoolset7 -i alpine -i linux-arm64 -t 12.13.0 -t 14.15.0 -t 16.9.1 -t 18.7.0 --strip",
|
||||
"build:darwin": "npm run build -- --arch x64+arm64",
|
||||
"build:win32": "npm run build",
|
||||
"clean": "rimraf build/ coverage/ prebuilds/",
|
||||
"download": "node scripts/download-artifacts.js",
|
||||
"test": "c8 --reporter lcov --reporter text mocha .",
|
||||
"test:valgrind": "valgrind --xml=yes --xml-file=./valgrind.xml --trace-children=yes --leak-check=full --show-leak-kinds=all mocha . && node scripts/parse-valgrind.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.13.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"nan": "^2.16.0",
|
||||
"node-gyp-build": "^4.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@contrast/eslint-config": "^3.1.1",
|
||||
"@ls-lint/ls-lint": "^1.11.2",
|
||||
"@octokit/rest": "^18.12.0",
|
||||
"c8": "^7.11.3",
|
||||
"chai": "^4.3.6",
|
||||
"husky": "^8.0.1",
|
||||
"inquirer": "^8.2.4",
|
||||
"lint-staged": "^13.0.1",
|
||||
"mocha": "^10.0.0",
|
||||
"node-gyp": "^9.0.0",
|
||||
"prebuildify": "^5.0.0",
|
||||
"prebuildify-cross": "^5.0.0",
|
||||
"rimraf": "^3.0.2",
|
||||
"unzipper": "^0.10.11",
|
||||
"xml-js": "^1.6.11"
|
||||
}
|
||||
}
|
||||
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
BIN
Binary file not shown.
Generated
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
#include <nan.h>
|
||||
|
||||
#include "code-events.h"
|
||||
#include "func-info.h"
|
||||
|
||||
NAN_MODULE_INIT(Init) {
|
||||
NAN_EXPORT(target, initHandler);
|
||||
NAN_EXPORT(target, deinitHandler);
|
||||
NAN_EXPORT(target, getNextCodeEvent);
|
||||
|
||||
NAN_EXPORT(target, funcInfo);
|
||||
}
|
||||
|
||||
NODE_MODULE(addon, Init)
|
||||
Generated
Vendored
+75
@@ -0,0 +1,75 @@
|
||||
#include "code-events.h"
|
||||
#include "event-queue.h"
|
||||
|
||||
using namespace v8;
|
||||
|
||||
class FnInspectCodeEventHandler : public CodeEventHandler {
|
||||
public:
|
||||
FnInspectCodeEventHandler(Isolate *isolate) : CodeEventHandler(isolate) {
|
||||
this->isolate = isolate;
|
||||
}
|
||||
|
||||
void Handle(CodeEvent *event) {
|
||||
/*
|
||||
* If Handle() is invoked from a worker thread (i.e. during
|
||||
* garbage collection) we don't have access to the isolate
|
||||
* so just bail
|
||||
*/
|
||||
if (Isolate::GetCurrent() != isolate) {
|
||||
return;
|
||||
}
|
||||
events.enqueue(event);
|
||||
}
|
||||
|
||||
EventNode *dequeue() {
|
||||
return this->events.dequeue();
|
||||
}
|
||||
|
||||
unsigned int eventCount() {
|
||||
return this->events.length;
|
||||
}
|
||||
|
||||
private:
|
||||
Isolate *isolate;
|
||||
EventQueue events;
|
||||
};
|
||||
|
||||
FnInspectCodeEventHandler *handler;
|
||||
|
||||
NAN_METHOD(initHandler) {
|
||||
handler = new FnInspectCodeEventHandler(info.GetIsolate());
|
||||
handler->Enable();
|
||||
}
|
||||
|
||||
NAN_METHOD(deinitHandler) {
|
||||
handler->Disable();
|
||||
|
||||
delete handler;
|
||||
handler = NULL;
|
||||
}
|
||||
|
||||
NAN_METHOD(getNextCodeEvent) {
|
||||
EventNode *node = handler->dequeue();
|
||||
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
Local<Object> obj = Nan::New<Object>();
|
||||
|
||||
Nan::Set(obj,
|
||||
Nan::New("script").ToLocalChecked(),
|
||||
Nan::New(node->script).ToLocalChecked());
|
||||
Nan::Set(obj,
|
||||
Nan::New("func").ToLocalChecked(),
|
||||
Nan::New(node->func).ToLocalChecked());
|
||||
Nan::Set(obj,
|
||||
Nan::New("type").ToLocalChecked(),
|
||||
Nan::New(node->type).ToLocalChecked());
|
||||
Nan::Set(obj,
|
||||
Nan::New("lineNumber").ToLocalChecked(),
|
||||
Nan::New(node->lineNumber));
|
||||
|
||||
info.GetReturnValue().Set(obj);
|
||||
|
||||
delete node;
|
||||
}
|
||||
Generated
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <nan.h>
|
||||
#include <v8-profiler.h>
|
||||
#include <v8.h>
|
||||
|
||||
#include "event-queue.h"
|
||||
|
||||
NAN_METHOD(initHandler);
|
||||
NAN_METHOD(deinitHandler);
|
||||
NAN_METHOD(getNextCodeEvent);
|
||||
Generated
Vendored
+61
@@ -0,0 +1,61 @@
|
||||
#include <v8-profiler.h>
|
||||
#include <v8.h>
|
||||
|
||||
#include "event-queue.h"
|
||||
|
||||
using namespace v8;
|
||||
|
||||
EventQueue::EventQueue() {
|
||||
this->head = NULL;
|
||||
this->tail = NULL;
|
||||
this->length = 0;
|
||||
}
|
||||
|
||||
EventQueue::~EventQueue() {
|
||||
EventNode *tmp;
|
||||
while (this->head) {
|
||||
tmp = this->head;
|
||||
;
|
||||
this->head = this->head->next;
|
||||
delete tmp;
|
||||
}
|
||||
}
|
||||
|
||||
void EventQueue::enqueue(CodeEvent *event) {
|
||||
if (Nan::Utf8String(event->GetScriptName()).length() == 0)
|
||||
return;
|
||||
|
||||
EventNode *node = new EventNode();
|
||||
|
||||
node->type = strdup(CodeEvent::GetCodeEventTypeName(event->GetCodeType()));
|
||||
node->script = strdup(*Nan::Utf8String(event->GetScriptName()));
|
||||
node->func = strdup(*Nan::Utf8String(event->GetFunctionName()));
|
||||
node->lineNumber = event->GetScriptLine();
|
||||
|
||||
if (this->tail) {
|
||||
this->tail->next = node;
|
||||
this->tail = node;
|
||||
} else {
|
||||
this->head = node;
|
||||
this->tail = node;
|
||||
}
|
||||
|
||||
this->length += 1;
|
||||
}
|
||||
|
||||
EventNode *EventQueue::dequeue() {
|
||||
EventNode *node = this->head;
|
||||
|
||||
if (!node)
|
||||
return NULL;
|
||||
|
||||
this->head = this->head->next;
|
||||
|
||||
if (this->head == NULL) {
|
||||
this->tail = NULL;
|
||||
}
|
||||
|
||||
this->length -= 1;
|
||||
|
||||
return node;
|
||||
}
|
||||
Generated
Vendored
+46
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <nan.h>
|
||||
#include <v8-profiler.h>
|
||||
#include <v8.h>
|
||||
|
||||
using namespace v8;
|
||||
|
||||
class EventNode {
|
||||
public:
|
||||
char *type;
|
||||
char *script;
|
||||
char *func;
|
||||
int lineNumber;
|
||||
EventNode *next;
|
||||
~EventNode() {
|
||||
free(this->type);
|
||||
free(this->script);
|
||||
free(this->func);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Implements a simple queue of code events that can be
|
||||
* consumed.
|
||||
*
|
||||
* Thread-Safety: There's no locking on these methods so
|
||||
* they aren't thread safe. However this should be OK
|
||||
* as the expectation is these methods are only ever called
|
||||
* from the main JS thread and they are blocking, there will
|
||||
* only ever be a single thread calling it as a time. We
|
||||
* may want to revisit this if we ever want to support
|
||||
* handling events from worker_threads.
|
||||
*/
|
||||
class EventQueue {
|
||||
public:
|
||||
EventQueue();
|
||||
~EventQueue();
|
||||
void enqueue(CodeEvent *event);
|
||||
EventNode *dequeue();
|
||||
unsigned int length;
|
||||
|
||||
private:
|
||||
EventNode *head;
|
||||
EventNode *tail;
|
||||
};
|
||||
Generated
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
#include "func-info.h"
|
||||
|
||||
using namespace v8;
|
||||
|
||||
NAN_METHOD(funcInfo) {
|
||||
if (info.Length() < 1 || info[0].IsEmpty() || !info[0]->IsFunction()) {
|
||||
info.GetReturnValue().Set(Nan::Null());
|
||||
return;
|
||||
}
|
||||
|
||||
Local<Function> fn = info[0].As<Function>();
|
||||
|
||||
Local<Object> obj = Nan::New<Object>();
|
||||
Local<Value> resourceName = fn->GetScriptOrigin().ResourceName();
|
||||
|
||||
if (!resourceName.IsEmpty()) {
|
||||
Nan::Set(obj, Nan::New("file").ToLocalChecked(), resourceName);
|
||||
Nan::Set(obj,
|
||||
Nan::New("lineNumber").ToLocalChecked(),
|
||||
Nan::New(fn->GetScriptLineNumber()));
|
||||
Nan::Set(obj, Nan::New("method").ToLocalChecked(), fn->GetName());
|
||||
Nan::Set(obj,
|
||||
Nan::New("column").ToLocalChecked(),
|
||||
Nan::New(fn->GetScriptColumnNumber()));
|
||||
}
|
||||
|
||||
info.GetReturnValue().Set(obj);
|
||||
}
|
||||
Generated
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <nan.h>
|
||||
#include <v8.h>
|
||||
|
||||
NAN_METHOD(funcInfo);
|
||||
Generated
Vendored
-1027
File diff suppressed because it is too large
Load Diff
Generated
Vendored
-6
@@ -1,6 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
var path = require("path"),
|
||||
cli = require(path.join(__dirname, "..", "cli", "pbjs.js"));
|
||||
var ret = cli.main(process.argv.slice(2));
|
||||
if (typeof ret === 'number')
|
||||
process.exit(ret);
|
||||
Generated
Vendored
-6
@@ -1,6 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
var path = require("path"),
|
||||
cli = require(path.join(__dirname, "..", "cli", "pbts.js"));
|
||||
var ret = cli.main(process.argv.slice(2));
|
||||
if (typeof ret === 'number')
|
||||
process.exit(ret);
|
||||
Generated
Vendored
-33
@@ -1,33 +0,0 @@
|
||||
Copyright (c) 2016, Daniel Wirtz All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of its author, nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
---
|
||||
|
||||
Code generated by the command line utilities is owned by the owner
|
||||
of the input file used when generating it. This code is not
|
||||
standalone and requires a support library to be linked with it. This
|
||||
support library is itself covered by the above license.
|
||||
Generated
Vendored
-174
@@ -1,174 +0,0 @@
|
||||
protobufjs-cli
|
||||
==============
|
||||
[](https://www.npmjs.com/package/protobufjs-cli)
|
||||
|
||||
Command line interface (CLI) for [protobuf.js](https://github.com/dcodeIO/protobuf.js). Translates between file formats and generates static code as well as TypeScript definitions.
|
||||
|
||||
* [CLI Documentation](https://github.com/dcodeIO/protobuf.js#command-line)
|
||||
|
||||
**Note** that moving the CLI to its own package is a work in progress. At the moment, it's still part of the main package.
|
||||
* [pbjs for JavaScript](#pbjs-for-javascript)
|
||||
* [pbts for TypeScript](#pbts-for-typescript)
|
||||
* [Reflection vs. static code](#reflection-vs-static-code)
|
||||
* [Command line API](#command-line-api)<br />
|
||||
|
||||
### pbjs for JavaScript
|
||||
|
||||
```
|
||||
Translates between file formats and generates static code.
|
||||
|
||||
-t, --target Specifies the target format. Also accepts a path to require a custom target.
|
||||
|
||||
json JSON representation
|
||||
json-module JSON representation as a module
|
||||
proto2 Protocol Buffers, Version 2
|
||||
proto3 Protocol Buffers, Version 3
|
||||
static Static code without reflection (non-functional on its own)
|
||||
static-module Static code without reflection as a module
|
||||
|
||||
-p, --path Adds a directory to the include path.
|
||||
|
||||
-o, --out Saves to a file instead of writing to stdout.
|
||||
|
||||
--sparse Exports only those types referenced from a main file (experimental).
|
||||
|
||||
Module targets only:
|
||||
|
||||
-w, --wrap Specifies the wrapper to use. Also accepts a path to require a custom wrapper.
|
||||
|
||||
default Default wrapper supporting both CommonJS and AMD
|
||||
commonjs CommonJS wrapper
|
||||
amd AMD wrapper
|
||||
es6 ES6 wrapper (implies --es6)
|
||||
closure A closure adding to protobuf.roots where protobuf is a global
|
||||
|
||||
-r, --root Specifies an alternative protobuf.roots name.
|
||||
|
||||
-l, --lint Linter configuration. Defaults to protobuf.js-compatible rules:
|
||||
|
||||
eslint-disable block-scoped-var, no-redeclare, no-control-regex, no-prototype-builtins
|
||||
|
||||
--es6 Enables ES6 syntax (const/let instead of var)
|
||||
|
||||
Proto sources only:
|
||||
|
||||
--keep-case Keeps field casing instead of converting to camel case.
|
||||
|
||||
Static targets only:
|
||||
|
||||
--no-create Does not generate create functions used for reflection compatibility.
|
||||
--no-encode Does not generate encode functions.
|
||||
--no-decode Does not generate decode functions.
|
||||
--no-verify Does not generate verify functions.
|
||||
--no-convert Does not generate convert functions like from/toObject
|
||||
--no-delimited Does not generate delimited encode/decode functions.
|
||||
--no-beautify Does not beautify generated code.
|
||||
--no-comments Does not output any JSDoc comments.
|
||||
--no-service Does not output service classes.
|
||||
|
||||
--force-long Enforces the use of 'Long' for s-/u-/int64 and s-/fixed64 fields.
|
||||
--force-number Enforces the use of 'number' for s-/u-/int64 and s-/fixed64 fields.
|
||||
--force-message Enforces the use of message instances instead of plain objects.
|
||||
|
||||
usage: pbjs [options] file1.proto file2.json ... (or pipe) other | pbjs [options] -
|
||||
```
|
||||
|
||||
For production environments it is recommended to bundle all your .proto files to a single .json file, which minimizes the number of network requests and avoids any parser overhead (hint: works with just the **light** library):
|
||||
|
||||
```
|
||||
$> pbjs -t json file1.proto file2.proto > bundle.json
|
||||
```
|
||||
|
||||
Now, either include this file in your final bundle:
|
||||
|
||||
```js
|
||||
var root = protobuf.Root.fromJSON(require("./bundle.json"));
|
||||
```
|
||||
|
||||
or load it the usual way:
|
||||
|
||||
```js
|
||||
protobuf.load("bundle.json", function(err, root) {
|
||||
...
|
||||
});
|
||||
```
|
||||
|
||||
Generated static code, on the other hand, works with just the **minimal** library. For example
|
||||
|
||||
```
|
||||
$> pbjs -t static-module -w commonjs -o compiled.js file1.proto file2.proto
|
||||
```
|
||||
|
||||
will generate static code for definitions within `file1.proto` and `file2.proto` to a CommonJS module `compiled.js`.
|
||||
|
||||
**ProTip!** Documenting your .proto files with `/** ... */`-blocks or (trailing) `/// ...` lines translates to generated static code.
|
||||
|
||||
|
||||
### pbts for TypeScript
|
||||
|
||||
```
|
||||
Generates TypeScript definitions from annotated JavaScript files.
|
||||
|
||||
-o, --out Saves to a file instead of writing to stdout.
|
||||
|
||||
-g, --global Name of the global object in browser environments, if any.
|
||||
|
||||
--no-comments Does not output any JSDoc comments.
|
||||
|
||||
Internal flags:
|
||||
|
||||
-n, --name Wraps everything in a module of the specified name.
|
||||
|
||||
-m, --main Whether building the main library without any imports.
|
||||
|
||||
usage: pbts [options] file1.js file2.js ... (or) other | pbts [options] -
|
||||
```
|
||||
|
||||
Picking up on the example above, the following not only generates static code to a CommonJS module `compiled.js` but also its respective TypeScript definitions to `compiled.d.ts`:
|
||||
|
||||
```
|
||||
$> pbjs -t static-module -w commonjs -o compiled.js file1.proto file2.proto
|
||||
$> pbts -o compiled.d.ts compiled.js
|
||||
```
|
||||
|
||||
Additionally, TypeScript definitions of static modules are compatible with their reflection-based counterparts (i.e. as exported by JSON modules), as long as the following conditions are met:
|
||||
|
||||
1. Instead of using `new SomeMessage(...)`, always use `SomeMessage.create(...)` because reflection objects do not provide a constructor.
|
||||
2. Types, services and enums must start with an uppercase letter to become available as properties of the reflected types as well (i.e. to be able to use `MyMessage.MyEnum` instead of `root.lookup("MyMessage.MyEnum")`).
|
||||
|
||||
For example, the following generates a JSON module `bundle.js` and a `bundle.d.ts`, but no static code:
|
||||
|
||||
```
|
||||
$> pbjs -t json-module -w commonjs -o bundle.js file1.proto file2.proto
|
||||
$> pbjs -t static-module file1.proto file2.proto | pbts -o bundle.d.ts -
|
||||
```
|
||||
|
||||
### Reflection vs. static code
|
||||
|
||||
While using .proto files directly requires the full library respectively pure reflection/JSON the light library, pretty much all code but the relatively short descriptors is shared.
|
||||
|
||||
Static code, on the other hand, requires just the minimal library, but generates additional source code without any reflection features. This also implies that there is a break-even point where statically generated code becomes larger than descriptor-based code once the amount of code generated exceeds the size of the full respectively light library.
|
||||
|
||||
There is no significant difference performance-wise as the code generated statically is pretty much the same as generated at runtime and both are largely interchangeable as seen in the previous section.
|
||||
|
||||
| Source | Library | Advantages | Tradeoffs
|
||||
|--------|---------|------------|-----------
|
||||
| .proto | full | Easily editable<br />Interoperability with other libraries<br />No compile step | Some parsing and possibly network overhead
|
||||
| JSON | light | Easily editable<br />No parsing overhead<br />Single bundle (no network overhead) | protobuf.js specific<br />Has a compile step
|
||||
| static | minimal | Works where `eval` access is restricted<br />Fully documented<br />Small footprint for small protos | Can be hard to edit<br />No reflection<br />Has a compile step
|
||||
|
||||
### Command line API
|
||||
|
||||
Both utilities can be used programmatically by providing command line arguments and a callback to their respective `main` functions:
|
||||
|
||||
```js
|
||||
var pbjs = require("protobufjs-cli/pbjs"); // or require("protobufjs-cli").pbjs / .pbts
|
||||
|
||||
pbjs.main([ "--target", "json-module", "path/to/myproto.proto" ], function(err, output) {
|
||||
if (err)
|
||||
throw err;
|
||||
// do something with output
|
||||
});
|
||||
```
|
||||
|
||||
**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause)
|
||||
Generated
Vendored
-6
@@ -1,6 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
var path = require("path"),
|
||||
cli = require(path.join(__dirname, "..", "pbjs.js"));
|
||||
var ret = cli.main(process.argv.slice(2));
|
||||
if (typeof ret === 'number')
|
||||
process.exit(ret);
|
||||
Generated
Vendored
-6
@@ -1,6 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
var path = require("path"),
|
||||
cli = require(path.join(__dirname, "..", "pbts.js"));
|
||||
var ret = cli.main(process.argv.slice(2));
|
||||
if (typeof ret === 'number')
|
||||
process.exit(ret);
|
||||
Generated
Vendored
-3
@@ -1,3 +0,0 @@
|
||||
import * as pbjs from "./pbjs.js";
|
||||
import * as pbts from "./pbts.js";
|
||||
export { pbjs, pbts };
|
||||
Generated
Vendored
-3
@@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
exports.pbjs = require("./pbjs");
|
||||
exports.pbts = require("./pbts");
|
||||
Generated
Vendored
-18
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"tags": {
|
||||
"allowUnknownTags": false
|
||||
},
|
||||
"plugins": [
|
||||
"./tsd-jsdoc/plugin"
|
||||
],
|
||||
"opts": {
|
||||
"encoding" : "utf8",
|
||||
"recurse" : true,
|
||||
"lenient" : true,
|
||||
"template" : "./tsd-jsdoc",
|
||||
|
||||
"private" : false,
|
||||
"comments" : true,
|
||||
"destination" : false
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user