pino-http-send
Advanced tools
Comparing version 0.4.0 to 0.4.2
@@ -1,2 +0,8 @@ | ||
#!/usr/bin/env node | ||
export declare function safeParse(src: string): any; | ||
import Pumpify from 'pumpify'; | ||
import { Args } from './args'; | ||
/** | ||
* Creates a writable stream that handles logs, batches them, and then sends | ||
* them to the configured endpoint. | ||
* @param options | ||
*/ | ||
export declare function createWriteStream(args: Args): Pumpify; |
@@ -1,2 +0,1 @@ | ||
#!/usr/bin/env node | ||
"use strict"; | ||
@@ -7,4 +6,4 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.safeParse = void 0; | ||
const pump_1 = __importDefault(require("pump")); | ||
exports.createWriteStream = void 0; | ||
const pumpify_1 = __importDefault(require("pumpify")); | ||
const split2_1 = __importDefault(require("split2")); | ||
@@ -14,22 +13,38 @@ const through2_1 = __importDefault(require("through2")); | ||
const handle_1 = require("./handle"); | ||
args_1.loadArgs(); | ||
/** | ||
* Safely parses incoming JSON and logs the source if an error is thrown. | ||
* @param src | ||
*/ | ||
function safeParse(src) { | ||
try { | ||
const parsed = JSON.parse(src); | ||
if (args_1.args.log) { | ||
console.log(src); | ||
} | ||
return parsed; | ||
} | ||
catch (e) { | ||
if (args_1.args.log) { | ||
console.log(src); | ||
} | ||
console.log(src); | ||
} | ||
} | ||
exports.safeParse = safeParse; | ||
const transport = through2_1.default.obj((log, _enc, callback) => { | ||
handle_1.handleLog(log, callback); | ||
}); | ||
pump_1.default(process.stdin, split2_1.default(safeParse), transport); | ||
/** | ||
* Passes the incoming stream through the proper callback. | ||
* @param args | ||
*/ | ||
function streamHandler() { | ||
return through2_1.default.obj((log, _enc, callback) => { | ||
handle_1.handleLog(log, callback); | ||
}); | ||
} | ||
/** | ||
* Creates a writable stream that handles logs, batches them, and then sends | ||
* them to the configured endpoint. | ||
* @param options | ||
*/ | ||
function createWriteStream(args) { | ||
// make sure url is defined right away | ||
if (!args.url || !args.url.trim()) { | ||
throw new Error('args.url is required'); | ||
} | ||
args_1.setArgs(args); | ||
return new pumpify_1.default(split2_1.default(safeParse), streamHandler()); | ||
} | ||
exports.createWriteStream = createWriteStream; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "pino-http-send", | ||
"version": "0.4.0", | ||
"version": "0.4.2", | ||
"description": "", | ||
@@ -27,3 +27,3 @@ "keywords": [ | ||
"bin": { | ||
"pino-http-send": "./dist/index.js" | ||
"pino-http-send": "./dist/bin.js" | ||
}, | ||
@@ -30,0 +30,0 @@ "files": [ |
@@ -94,6 +94,2 @@ # pino-http-send | ||
**It's important that you don't import/require from index when using as an API | ||
stream. Doing so willl require CLI args to be defined as this is a CLI-first | ||
package.** | ||
### `createWriteStream` | ||
@@ -120,3 +116,3 @@ | ||
```ts | ||
import { createWriteStream } from 'pino-http-send/dist/stream'; | ||
import { createWriteStream } from 'pino-http-send'; | ||
@@ -123,0 +119,0 @@ const stream = createWriteStream({ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
24025
359
130