mirror of
https://github.com/standardnotes/server
synced 2026-04-25 18:01:21 -04:00
Compare commits
34 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 |
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
|
||||
}
|
||||
}
|
||||
Generated
Vendored
-21
@@ -1,21 +0,0 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2016 Chad Engler
|
||||
|
||||
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.
|
||||
.yarn/unplugged/protobufjs-npm-6.11.3-566fb31188/node_modules/protobufjs/cli/lib/tsd-jsdoc/README.md
Generated
Vendored
-23
@@ -1,23 +0,0 @@
|
||||
protobuf.js fork of tsd-jsdoc
|
||||
=============================
|
||||
|
||||
This is a modified version of [tsd-jsdoc](https://github.com/englercj/tsd-jsdoc) v1.0.1 for use with protobuf.js, parked here so we can process issues and pull requests. The ultimate goal is to switch back to the a recent version of tsd-jsdoc once it meets our needs.
|
||||
|
||||
Options
|
||||
-------
|
||||
|
||||
* **module: `string`**<br />
|
||||
Wraps everything in a module of the specified name.
|
||||
|
||||
* **private: `boolean`**<br />
|
||||
Includes private members when set to `true`.
|
||||
|
||||
* **comments: `boolean`**<br />
|
||||
Skips comments when explicitly set to `false`.
|
||||
|
||||
* **destination: `string|boolean`**<br />
|
||||
Saves to the specified destination file or to console when set to `false`.
|
||||
|
||||
Setting options on the command line
|
||||
-----------------------------------
|
||||
Providing `-q, --query <queryString>` on the command line will set respectively override existing options. Example: `-q module=protobufjs`
|
||||
.yarn/unplugged/protobufjs-npm-6.11.3-566fb31188/node_modules/protobufjs/cli/lib/tsd-jsdoc/plugin.js
Generated
Vendored
-21
@@ -1,21 +0,0 @@
|
||||
"use strict";
|
||||
exports.defineTags = function(dictionary) {
|
||||
|
||||
dictionary.defineTag("template", {
|
||||
mustHaveValue: true,
|
||||
canHaveType: false,
|
||||
canHaveName: false,
|
||||
onTagged: function(doclet, tag) {
|
||||
(doclet.templates || (doclet.templates = [])).push(tag.text);
|
||||
}
|
||||
});
|
||||
|
||||
dictionary.defineTag("tstype", {
|
||||
mustHaveValue: true,
|
||||
canHaveType: false,
|
||||
canHaveName: false,
|
||||
onTagged: function(doclet, tag) {
|
||||
doclet.tsType = tag.text;
|
||||
}
|
||||
});
|
||||
};
|
||||
Generated
Vendored
-705
@@ -1,705 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var fs = require("fs");
|
||||
|
||||
// output stream
|
||||
var out = null;
|
||||
|
||||
// documentation data
|
||||
var data = null;
|
||||
|
||||
// already handled objects, by name
|
||||
var seen = {};
|
||||
|
||||
// indentation level
|
||||
var indent = 0;
|
||||
|
||||
// whether indent has been written for the current line yet
|
||||
var indentWritten = false;
|
||||
|
||||
// provided options
|
||||
var options = {};
|
||||
|
||||
// queued interfaces
|
||||
var queuedInterfaces = [];
|
||||
|
||||
// whether writing the first line
|
||||
var firstLine = true;
|
||||
|
||||
// JSDoc hook
|
||||
exports.publish = function publish(taffy, opts) {
|
||||
options = opts || {};
|
||||
|
||||
// query overrides options
|
||||
if (options.query)
|
||||
Object.keys(options.query).forEach(function(key) {
|
||||
if (key !== "query")
|
||||
switch (options[key] = options.query[key]) {
|
||||
case "true":
|
||||
options[key] = true;
|
||||
break;
|
||||
case "false":
|
||||
options[key] = false;
|
||||
break;
|
||||
case "null":
|
||||
options[key] = null;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// remove undocumented
|
||||
taffy({ undocumented: true }).remove();
|
||||
taffy({ ignore: true }).remove();
|
||||
taffy({ inherited: true }).remove();
|
||||
|
||||
// remove private
|
||||
if (!options.private)
|
||||
taffy({ access: "private" }).remove();
|
||||
|
||||
// setup output
|
||||
out = options.destination
|
||||
? fs.createWriteStream(options.destination)
|
||||
: process.stdout;
|
||||
|
||||
try {
|
||||
// setup environment
|
||||
data = taffy().get();
|
||||
indent = 0;
|
||||
indentWritten = false;
|
||||
firstLine = true;
|
||||
|
||||
// wrap everything in a module if configured
|
||||
if (options.module) {
|
||||
writeln("export = ", options.module, ";");
|
||||
writeln();
|
||||
writeln("declare namespace ", options.module, " {");
|
||||
writeln();
|
||||
++indent;
|
||||
}
|
||||
|
||||
// handle all
|
||||
getChildrenOf(undefined).forEach(function(child) {
|
||||
handleElement(child, null);
|
||||
});
|
||||
|
||||
// process queued
|
||||
while (queuedInterfaces.length) {
|
||||
var element = queuedInterfaces.shift();
|
||||
begin(element);
|
||||
writeInterface(element);
|
||||
writeln(";");
|
||||
}
|
||||
|
||||
// end wrap
|
||||
if (options.module) {
|
||||
--indent;
|
||||
writeln("}");
|
||||
}
|
||||
|
||||
// close file output
|
||||
if (out !== process.stdout)
|
||||
out.end();
|
||||
|
||||
} finally {
|
||||
// gc environment objects
|
||||
out = data = null;
|
||||
seen = options = {};
|
||||
queuedInterfaces = [];
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Utility
|
||||
//
|
||||
|
||||
// writes one or multiple strings
|
||||
function write() {
|
||||
var s = Array.prototype.slice.call(arguments).join("");
|
||||
if (!indentWritten) {
|
||||
for (var i = 0; i < indent; ++i)
|
||||
s = " " + s;
|
||||
indentWritten = true;
|
||||
}
|
||||
out.write(s);
|
||||
firstLine = false;
|
||||
}
|
||||
|
||||
// writes zero or multiple strings, followed by a new line
|
||||
function writeln() {
|
||||
var s = Array.prototype.slice.call(arguments).join("");
|
||||
if (s.length)
|
||||
write(s, "\n");
|
||||
else if (!firstLine)
|
||||
out.write("\n");
|
||||
indentWritten = false;
|
||||
}
|
||||
|
||||
var keepTags = [
|
||||
"param",
|
||||
"returns",
|
||||
"throws",
|
||||
"see"
|
||||
];
|
||||
|
||||
// parses a comment into text and tags
|
||||
function parseComment(comment) {
|
||||
var lines = comment.replace(/^ *\/\*\* *|^ *\*\/| *\*\/ *$|^ *\* */mg, "").trim().split(/\r?\n|\r/g); // property.description has just "\r" ?!
|
||||
var desc;
|
||||
var text = [];
|
||||
var tags = null;
|
||||
for (var i = 0; i < lines.length; ++i) {
|
||||
var match = /^@(\w+)\b/.exec(lines[i]);
|
||||
if (match) {
|
||||
if (!tags) {
|
||||
tags = [];
|
||||
desc = text;
|
||||
}
|
||||
text = [];
|
||||
tags.push({ name: match[1], text: text });
|
||||
lines[i] = lines[i].substring(match[1].length + 1).trim();
|
||||
}
|
||||
if (lines[i].length || text.length)
|
||||
text.push(lines[i]);
|
||||
}
|
||||
return {
|
||||
text: desc || text,
|
||||
tags: tags || []
|
||||
};
|
||||
}
|
||||
|
||||
// writes a comment
|
||||
function writeComment(comment, otherwiseNewline) {
|
||||
if (!comment || options.comments === false) {
|
||||
if (otherwiseNewline)
|
||||
writeln();
|
||||
return;
|
||||
}
|
||||
if (typeof comment !== "object")
|
||||
comment = parseComment(comment);
|
||||
comment.tags = comment.tags.filter(function(tag) {
|
||||
return keepTags.indexOf(tag.name) > -1 && (tag.name !== "returns" || tag.text[0] !== "{undefined}");
|
||||
});
|
||||
writeln();
|
||||
if (!comment.tags.length && comment.text.length < 2) {
|
||||
writeln("/** " + comment.text[0] + " */");
|
||||
return;
|
||||
}
|
||||
writeln("/**");
|
||||
comment.text.forEach(function(line) {
|
||||
if (line.length)
|
||||
writeln(" * ", line);
|
||||
else
|
||||
writeln(" *");
|
||||
});
|
||||
comment.tags.forEach(function(tag) {
|
||||
var started = false;
|
||||
if (tag.text.length) {
|
||||
tag.text.forEach(function(line, i) {
|
||||
if (i > 0)
|
||||
write(" * ");
|
||||
else if (tag.name !== "throws")
|
||||
line = line.replace(/^\{[^\s]*} ?/, "");
|
||||
if (!line.length)
|
||||
return;
|
||||
if (!started) {
|
||||
write(" * @", tag.name, " ");
|
||||
started = true;
|
||||
}
|
||||
writeln(line);
|
||||
});
|
||||
}
|
||||
});
|
||||
writeln(" */");
|
||||
}
|
||||
|
||||
// recursively replaces all occurencies of re's match
|
||||
function replaceRecursive(name, re, fn) {
|
||||
var found;
|
||||
|
||||
function replacer() {
|
||||
found = true;
|
||||
return fn.apply(null, arguments);
|
||||
}
|
||||
|
||||
do {
|
||||
found = false;
|
||||
name = name.replace(re, replacer);
|
||||
} while (found);
|
||||
return name;
|
||||
}
|
||||
|
||||
// tests if an element is considered to be a class or class-like
|
||||
function isClassLike(element) {
|
||||
return isClass(element) || isInterface(element);
|
||||
}
|
||||
|
||||
// tests if an element is considered to be a class
|
||||
function isClass(element) {
|
||||
return element && element.kind === "class";
|
||||
}
|
||||
|
||||
// tests if an element is considered to be an interface
|
||||
function isInterface(element) {
|
||||
return element && (element.kind === "interface" || element.kind === "mixin");
|
||||
}
|
||||
|
||||
// tests if an element is considered to be a namespace
|
||||
function isNamespace(element) {
|
||||
return element && (element.kind === "namespace" || element.kind === "module");
|
||||
}
|
||||
|
||||
// gets all children of the specified parent
|
||||
function getChildrenOf(parent) {
|
||||
var memberof = parent ? parent.longname : undefined;
|
||||
return data.filter(function(element) {
|
||||
return element.memberof === memberof;
|
||||
});
|
||||
}
|
||||
|
||||
// gets the literal type of an element
|
||||
function getTypeOf(element) {
|
||||
if (element.tsType)
|
||||
return element.tsType.replace(/\r?\n|\r/g, "\n");
|
||||
var name = "any";
|
||||
var type = element.type;
|
||||
if (type && type.names && type.names.length) {
|
||||
if (type.names.length === 1)
|
||||
name = element.type.names[0].trim();
|
||||
else
|
||||
name = "(" + element.type.names.join("|") + ")";
|
||||
} else
|
||||
return name;
|
||||
|
||||
// Replace catchalls with any
|
||||
name = name.replace(/\*|\bmixed\b/g, "any");
|
||||
|
||||
// Ensure upper case Object for map expressions below
|
||||
name = name.replace(/\bobject\b/g, "Object");
|
||||
|
||||
// Correct Something.<Something> to Something<Something>
|
||||
name = replaceRecursive(name, /\b(?!Object|Array)([\w$]+)\.<([^>]*)>/gi, function($0, $1, $2) {
|
||||
return $1 + "<" + $2 + ">";
|
||||
});
|
||||
|
||||
// Replace Array.<string> with string[]
|
||||
name = replaceRecursive(name, /\bArray\.?<([^>]*)>/gi, function($0, $1) {
|
||||
return $1 + "[]";
|
||||
});
|
||||
|
||||
// Replace Object.<string,number> with { [k: string]: number }
|
||||
name = replaceRecursive(name, /\bObject\.?<([^,]*), *([^>]*)>/gi, function($0, $1, $2) {
|
||||
return "{ [k: " + $1 + "]: " + $2 + " }";
|
||||
});
|
||||
|
||||
// Replace functions (there are no signatures) with Function
|
||||
name = name.replace(/\bfunction(?:\(\))?\b/g, "Function");
|
||||
|
||||
// Convert plain Object back to just object
|
||||
name = name.replace(/\b(Object\b(?!\.))/g, function($0, $1) {
|
||||
return $1.toLowerCase();
|
||||
});
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
// begins writing the definition of the specified element
|
||||
function begin(element, is_interface) {
|
||||
if (!seen[element.longname]) {
|
||||
if (isClass(element)) {
|
||||
var comment = parseComment(element.comment);
|
||||
var classdesc = comment.tags.find(function(tag) { return tag.name === "classdesc"; });
|
||||
if (classdesc) {
|
||||
comment.text = classdesc.text;
|
||||
comment.tags = [];
|
||||
}
|
||||
writeComment(comment, true);
|
||||
} else
|
||||
writeComment(element.comment, is_interface || isClassLike(element) || isNamespace(element) || element.isEnum || element.scope === "global");
|
||||
seen[element.longname] = element;
|
||||
} else
|
||||
writeln();
|
||||
// ????: something changed in JSDoc 3.6.0? so that @exports + @enum does
|
||||
// no longer yield a 'global' scope, but is some sort of unscoped module
|
||||
// element now. The additional condition added below works around this.
|
||||
if ((element.scope === "global" || element.isEnum && element.scope === undefined) && !options.module)
|
||||
write("export ");
|
||||
}
|
||||
|
||||
// writes the function signature describing element
|
||||
function writeFunctionSignature(element, isConstructor, isTypeDef) {
|
||||
write("(");
|
||||
|
||||
var params = {};
|
||||
|
||||
// this type
|
||||
if (element.this)
|
||||
params["this"] = {
|
||||
type: element.this.replace(/^{|}$/g, ""),
|
||||
optional: false
|
||||
};
|
||||
|
||||
// parameter types
|
||||
if (element.params)
|
||||
element.params.forEach(function(param) {
|
||||
var path = param.name.split(/\./g);
|
||||
if (path.length === 1)
|
||||
params[param.name] = {
|
||||
type: getTypeOf(param),
|
||||
variable: param.variable === true,
|
||||
optional: param.optional === true,
|
||||
defaultValue: param.defaultvalue // Not used yet (TODO)
|
||||
};
|
||||
else // Property syntax (TODO)
|
||||
params[path[0]].type = "{ [k: string]: any }";
|
||||
});
|
||||
|
||||
var paramNames = Object.keys(params);
|
||||
paramNames.forEach(function(name, i) {
|
||||
var param = params[name];
|
||||
var type = param.type;
|
||||
if (param.variable) {
|
||||
name = "..." + name;
|
||||
type = param.type.charAt(0) === "(" ? "any[]" : param.type + "[]";
|
||||
}
|
||||
write(name, !param.variable && param.optional ? "?: " : ": ", type);
|
||||
if (i < paramNames.length - 1)
|
||||
write(", ");
|
||||
});
|
||||
|
||||
write(")");
|
||||
|
||||
// return type
|
||||
if (!isConstructor) {
|
||||
write(isTypeDef ? " => " : ": ");
|
||||
var typeName;
|
||||
if (element.returns && element.returns.length && (typeName = getTypeOf(element.returns[0])) !== "undefined")
|
||||
write(typeName);
|
||||
else
|
||||
write("void");
|
||||
}
|
||||
}
|
||||
|
||||
// writes (a typedef as) an interface
|
||||
function writeInterface(element) {
|
||||
write("interface ", element.name);
|
||||
writeInterfaceBody(element);
|
||||
writeln();
|
||||
}
|
||||
|
||||
function writeInterfaceBody(element) {
|
||||
writeln("{");
|
||||
++indent;
|
||||
if (element.tsType)
|
||||
writeln(element.tsType.replace(/\r?\n|\r/g, "\n"));
|
||||
else if (element.properties && element.properties.length)
|
||||
element.properties.forEach(writeProperty);
|
||||
--indent;
|
||||
write("}");
|
||||
}
|
||||
|
||||
function writeProperty(property, declare) {
|
||||
writeComment(property.description);
|
||||
if (declare)
|
||||
write("let ");
|
||||
write(property.name);
|
||||
if (property.optional)
|
||||
write("?");
|
||||
writeln(": ", getTypeOf(property), ";");
|
||||
}
|
||||
|
||||
//
|
||||
// Handlers
|
||||
//
|
||||
|
||||
// handles a single element of any understood type
|
||||
function handleElement(element, parent) {
|
||||
if (element.scope === "inner")
|
||||
return false;
|
||||
|
||||
if (element.optional !== true && element.type && element.type.names && element.type.names.length) {
|
||||
for (var i = 0; i < element.type.names.length; i++) {
|
||||
if (element.type.names[i].toLowerCase() === "undefined") {
|
||||
// This element is actually optional. Set optional to true and
|
||||
// remove the 'undefined' type
|
||||
element.optional = true;
|
||||
element.type.names.splice(i, 1);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (seen[element.longname])
|
||||
return true;
|
||||
if (isClassLike(element))
|
||||
handleClass(element, parent);
|
||||
else switch (element.kind) {
|
||||
case "module":
|
||||
if (element.isEnum) {
|
||||
handleEnum(element, parent);
|
||||
break;
|
||||
}
|
||||
// eslint-disable-line no-fallthrough
|
||||
case "namespace":
|
||||
handleNamespace(element, parent);
|
||||
break;
|
||||
case "constant":
|
||||
case "member":
|
||||
handleMember(element, parent);
|
||||
break;
|
||||
case "function":
|
||||
handleFunction(element, parent);
|
||||
break;
|
||||
case "typedef":
|
||||
handleTypeDef(element, parent);
|
||||
break;
|
||||
case "package":
|
||||
break;
|
||||
}
|
||||
seen[element.longname] = element;
|
||||
return true;
|
||||
}
|
||||
|
||||
// handles (just) a namespace
|
||||
function handleNamespace(element/*, parent*/) {
|
||||
var children = getChildrenOf(element);
|
||||
if (!children.length)
|
||||
return;
|
||||
var first = true;
|
||||
if (element.properties)
|
||||
element.properties.forEach(function(property) {
|
||||
if (!/^[$\w]+$/.test(property.name)) // incompatible in namespace
|
||||
return;
|
||||
if (first) {
|
||||
begin(element);
|
||||
writeln("namespace ", element.name, " {");
|
||||
++indent;
|
||||
first = false;
|
||||
}
|
||||
writeProperty(property, true);
|
||||
});
|
||||
children.forEach(function(child) {
|
||||
if (child.scope === "inner" || seen[child.longname])
|
||||
return;
|
||||
if (first) {
|
||||
begin(element);
|
||||
writeln("namespace ", element.name, " {");
|
||||
++indent;
|
||||
first = false;
|
||||
}
|
||||
handleElement(child, element);
|
||||
});
|
||||
if (!first) {
|
||||
--indent;
|
||||
writeln("}");
|
||||
}
|
||||
}
|
||||
|
||||
// a filter function to remove any module references
|
||||
function notAModuleReference(ref) {
|
||||
return ref.indexOf("module:") === -1;
|
||||
}
|
||||
|
||||
// handles a class or class-like
|
||||
function handleClass(element, parent) {
|
||||
var is_interface = isInterface(element);
|
||||
begin(element, is_interface);
|
||||
if (is_interface)
|
||||
write("interface ");
|
||||
else {
|
||||
if (element.virtual)
|
||||
write("abstract ");
|
||||
write("class ");
|
||||
}
|
||||
write(element.name);
|
||||
if (element.templates && element.templates.length)
|
||||
write("<", element.templates.join(", "), ">");
|
||||
write(" ");
|
||||
|
||||
// extended classes
|
||||
if (element.augments) {
|
||||
var augments = element.augments.filter(notAModuleReference);
|
||||
if (augments.length)
|
||||
write("extends ", augments[0], " ");
|
||||
}
|
||||
|
||||
// implemented interfaces
|
||||
var impls = [];
|
||||
if (element.implements)
|
||||
Array.prototype.push.apply(impls, element.implements);
|
||||
if (element.mixes)
|
||||
Array.prototype.push.apply(impls, element.mixes);
|
||||
impls = impls.filter(notAModuleReference);
|
||||
if (impls.length)
|
||||
write("implements ", impls.join(", "), " ");
|
||||
|
||||
writeln("{");
|
||||
++indent;
|
||||
|
||||
if (element.tsType)
|
||||
writeln(element.tsType.replace(/\r?\n|\r/g, "\n"));
|
||||
|
||||
// constructor
|
||||
if (!is_interface && !element.virtual)
|
||||
handleFunction(element, parent, true);
|
||||
|
||||
// properties
|
||||
if (is_interface && element.properties)
|
||||
element.properties.forEach(function(property) {
|
||||
writeProperty(property);
|
||||
});
|
||||
|
||||
// class-compatible members
|
||||
var incompatible = [];
|
||||
getChildrenOf(element).forEach(function(child) {
|
||||
if (isClassLike(child) || child.kind === "module" || child.kind === "typedef" || child.isEnum) {
|
||||
incompatible.push(child);
|
||||
return;
|
||||
}
|
||||
handleElement(child, element);
|
||||
});
|
||||
|
||||
--indent;
|
||||
writeln("}");
|
||||
|
||||
// class-incompatible members
|
||||
if (incompatible.length) {
|
||||
writeln();
|
||||
if (element.scope === "global" && !options.module)
|
||||
write("export ");
|
||||
writeln("namespace ", element.name, " {");
|
||||
++indent;
|
||||
incompatible.forEach(function(child) {
|
||||
handleElement(child, element);
|
||||
});
|
||||
--indent;
|
||||
writeln("}");
|
||||
}
|
||||
}
|
||||
|
||||
// handles an enum
|
||||
function handleEnum(element) {
|
||||
begin(element);
|
||||
|
||||
var stringEnum = false;
|
||||
element.properties.forEach(function(property) {
|
||||
if (isNaN(property.defaultvalue)) {
|
||||
stringEnum = true;
|
||||
}
|
||||
});
|
||||
if (stringEnum) {
|
||||
writeln("type ", element.name, " =");
|
||||
++indent;
|
||||
element.properties.forEach(function(property, i) {
|
||||
write(i === 0 ? "" : "| ", JSON.stringify(property.defaultvalue));
|
||||
});
|
||||
--indent;
|
||||
writeln(";");
|
||||
} else {
|
||||
writeln("enum ", element.name, " {");
|
||||
++indent;
|
||||
element.properties.forEach(function(property, i) {
|
||||
write(property.name);
|
||||
if (property.defaultvalue !== undefined)
|
||||
write(" = ", JSON.stringify(property.defaultvalue));
|
||||
if (i < element.properties.length - 1)
|
||||
writeln(",");
|
||||
else
|
||||
writeln();
|
||||
});
|
||||
--indent;
|
||||
writeln("}");
|
||||
}
|
||||
}
|
||||
|
||||
// handles a namespace or class member
|
||||
function handleMember(element, parent) {
|
||||
if (element.isEnum) {
|
||||
handleEnum(element);
|
||||
return;
|
||||
}
|
||||
begin(element);
|
||||
|
||||
var inClass = isClassLike(parent);
|
||||
if (inClass) {
|
||||
write(element.access || "public", " ");
|
||||
if (element.scope === "static")
|
||||
write("static ");
|
||||
if (element.readonly)
|
||||
write("readonly ");
|
||||
} else
|
||||
write(element.kind === "constant" ? "const " : "let ");
|
||||
|
||||
write(element.name);
|
||||
if (element.optional)
|
||||
write("?");
|
||||
write(": ");
|
||||
|
||||
if (element.type && element.type.names && /^Object\b/i.test(element.type.names[0]) && element.properties) {
|
||||
writeln("{");
|
||||
++indent;
|
||||
element.properties.forEach(function(property, i) {
|
||||
writeln(JSON.stringify(property.name), ": ", getTypeOf(property), i < element.properties.length - 1 ? "," : "");
|
||||
});
|
||||
--indent;
|
||||
writeln("};");
|
||||
} else
|
||||
writeln(getTypeOf(element), ";");
|
||||
}
|
||||
|
||||
// handles a function or method
|
||||
function handleFunction(element, parent, isConstructor) {
|
||||
var insideClass = true;
|
||||
if (isConstructor) {
|
||||
writeComment(element.comment);
|
||||
write("constructor");
|
||||
} else {
|
||||
begin(element);
|
||||
insideClass = isClassLike(parent);
|
||||
if (insideClass) {
|
||||
write(element.access || "public", " ");
|
||||
if (element.scope === "static")
|
||||
write("static ");
|
||||
} else
|
||||
write("function ");
|
||||
write(element.name);
|
||||
if (element.templates && element.templates.length)
|
||||
write("<", element.templates.join(", "), ">");
|
||||
}
|
||||
writeFunctionSignature(element, isConstructor, false);
|
||||
writeln(";");
|
||||
if (!insideClass)
|
||||
handleNamespace(element);
|
||||
}
|
||||
|
||||
// handles a type definition (not a real type)
|
||||
function handleTypeDef(element, parent) {
|
||||
if (isInterface(element)) {
|
||||
if (isClassLike(parent))
|
||||
queuedInterfaces.push(element);
|
||||
else {
|
||||
begin(element);
|
||||
writeInterface(element);
|
||||
}
|
||||
} else {
|
||||
writeComment(element.comment, true);
|
||||
write("type ", element.name);
|
||||
if (element.templates && element.templates.length)
|
||||
write("<", element.templates.join(", "), ">");
|
||||
write(" = ");
|
||||
if (element.tsType)
|
||||
write(element.tsType.replace(/\r?\n|\r/g, "\n"));
|
||||
else {
|
||||
var type = getTypeOf(element);
|
||||
if (element.type && element.type.names.length === 1 && element.type.names[0] === "function")
|
||||
writeFunctionSignature(element, false, true);
|
||||
else if (type === "object") {
|
||||
if (element.properties && element.properties.length)
|
||||
writeInterfaceBody(element);
|
||||
else
|
||||
write("{}");
|
||||
} else
|
||||
write(type);
|
||||
}
|
||||
writeln(";");
|
||||
}
|
||||
}
|
||||
Generated
Vendored
-8
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"version": "6.9.0",
|
||||
"dependencies": {
|
||||
"escodegen": "^2.0.0",
|
||||
"espree": "^7.1.0",
|
||||
"tmp": "^0.2.1"
|
||||
}
|
||||
}
|
||||
.yarn/unplugged/protobufjs-npm-6.11.3-566fb31188/node_modules/protobufjs/cli/package.standalone.json
Generated
Vendored
-32
@@ -1,32 +0,0 @@
|
||||
{
|
||||
"name": "protobufjs-cli",
|
||||
"description": "Translates between file formats and generates static code as well as TypeScript definitions.",
|
||||
"version": "6.9.0",
|
||||
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/dcodeIO/protobuf.js.git"
|
||||
},
|
||||
"license": "BSD-3-Clause",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"bin": {
|
||||
"pbjs": "bin/pbjs",
|
||||
"pbts": "bin/pbts"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"protobufjs": "~6.9.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "^3.0.0",
|
||||
"escodegen": "^1.13.0",
|
||||
"espree": "^6.1.2",
|
||||
"estraverse": "^4.3.0",
|
||||
"glob": "^7.1.6",
|
||||
"jsdoc": "^3.6.3",
|
||||
"minimist": "^1.2.0",
|
||||
"semver": "^7.1.2",
|
||||
"tmp": "^0.1.0",
|
||||
"uglify-js": "^3.7.7"
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user