Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@travetto/base

Package Overview
Dependencies
Maintainers
1
Versions
357
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@travetto/base - npm Package Compare versions

Comparing version 3.4.0-rc.2 to 3.4.0-rc.3

2

package.json
{
"name": "@travetto/base",
"version": "3.4.0-rc.2",
"version": "3.4.0-rc.3",
"description": "Environment config and common utilities for travetto applications.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -227,3 +227,2 @@ <!-- This file was generated by @travetto/doc and should not be modified directly -->

* `waitForCompletion(src: Readable, finish:()=>Promise<any>)` will ensure the stream remains open until the promise finish produces is satisfied.
* `streamByDelimiter(file: string, options: { delimiter, start, encoding, includeDelimiter}): AsyncIterable<{item:string, read:number}>` will watch a file for any line changes, and produce those changes as asynchronous iterable stream. Functionally, this is equivalent to using the Unix tail operation on a file

@@ -230,0 +229,0 @@ ## Object Utilities

@@ -9,2 +9,3 @@ import rl from 'readline/promises';

import { LogLevel } from './types';
import { AppError } from './error';

@@ -18,2 +19,3 @@ type ServerInfo = {

compilerPid: number;
env: Record<string, string>;
};

@@ -30,3 +32,4 @@

{ type: 'progress', payload: ProgressEvent } |
{ type: 'state', payload: StateEvent };
{ type: 'state', payload: StateEvent } |
{ type: 'custom', payload: any };

@@ -65,4 +68,4 @@ type CompilerEventType = CompilerEvent['type'];

/** Get compiler info */
async getInfo(): Promise<ServerInfo | undefined> {
const res = await fetch(`${this.#url}/info`, { signal: this.#kill.signal }).catch(err => ({ ok: false, json: () => undefined }));
async getInfo(env?: boolean): Promise<ServerInfo | undefined> {
const res = await fetch(`${this.#url}/info?${env ? 'env' : ''}`, { signal: this.#kill.signal }).catch(err => ({ ok: false, json: () => undefined }));
if (res.ok) {

@@ -101,2 +104,18 @@ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions

/** Send an event to the system */
async sendEvent<
V extends CompilerEventType,
T extends (CompilerEvent & { type: V })['payload']
>(type: V, payload: T, signal?: AbortSignal): Promise<void> {
const res = await fetch(`${this.#url}/send-event`, {
method: 'POST',
body: JSON.stringify({ type, payload }),
headers: { 'Content-Type': 'application/json' },
signal
});
if (!res.ok) {
throw new AppError('Unable to send event');
}
}
/**

@@ -103,0 +122,0 @@ * Listen to file changes

@@ -1,2 +0,2 @@

import { createReadStream, createWriteStream } from 'fs';
import { createWriteStream } from 'fs';
import { PassThrough, Readable, Writable } from 'stream';

@@ -143,35 +143,2 @@ import { ReadableStream as WebReadableStream } from 'stream/web';

}
/**
* Stream by delimiter from a file, returning the bytes read, for chunked resuming
* @param file The file to stream from
* @param options Stream options, including delimiter control
*/
static async * streamByDelimiter(
file: string | Readable,
options: { start?: number, encoding?: BufferEncoding, includeDelimiter?: boolean, delimiter?: string } = {}
): AsyncIterable<{ item: string, read: number }> {
let read = options.start ?? 0;
const stream = typeof file === 'string' ? createReadStream(file, { start: read }) : file;
const encoding = options.encoding ?? 'utf8';
const includeDelimiter = !!options.includeDelimiter;
const delimiter = options.delimiter ?? '\n';
let buffer: Buffer = Buffer.from([]);
for await (const chunk of stream) {
const chunkBuff: Buffer = typeof chunk === 'string' ? Buffer.from(chunk, encoding) : chunk;
buffer = Buffer.concat([buffer, chunkBuff]);
let pos = buffer.indexOf(delimiter);
while (pos >= 0) { // If we have a newline
const fullLength = pos + delimiter.length;
const outLength = pos + (includeDelimiter ? delimiter.length : 0);
read += fullLength;
yield { item: buffer.toString(encoding, 0, outLength), read };
buffer = Buffer.copyBytesFrom(buffer, fullLength);
pos = buffer.indexOf(delimiter);
}
}
// Yield on exit, in case of being called in a loop
await new Promise(r => setTimeout(r, 1));
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc