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

apache-js-workers

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apache-js-workers - npm Package Compare versions

Comparing version 0.0.13 to 0.0.14

35

index.js

@@ -39,16 +39,28 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.log = exports.res = exports.Res = exports.req = void 0;
var worker_threads_1 = require("worker_threads");
exports.req = worker_threads_1.workerData.req;
exports.res = {
statusCode: 200,
headers: {},
send: function (body) {
var Res = /** @class */ (function () {
function Res() {
this.statusCode = 200;
this.headers = {};
}
Res.prototype.write = function (body) {
worker_threads_1.parentPort.postMessage({
type: 'write',
body: body
});
};
Res.prototype.send = function (body) {
worker_threads_1.parentPort.postMessage({
type: 'response',
statusCode: exports.res.statusCode,
headers: exports.res.headers,
statusCode: this.statusCode,
headers: this.headers,
body: body
});
}
};
};
return Res;
}());
exports.Res = Res;
exports.res = new Res();
exports.log = function (level, message) { return __awaiter(void 0, void 0, void 0, function () {

@@ -59,10 +71,5 @@ return __generator(this, function (_a) {

}
worker_threads_1.parentPort.postMessage({
type: 'log',
headers: {
level: level, message: message
}
});
worker_threads_1.parentPort.postMessage({ type: 'log', level: level, message: message });
return [2 /*return*/];
});
}); };

59

index.ts
import { workerData, parentPort } from 'worker_threads'
import { LogLevel } from '@iannisz/logger'

@@ -14,3 +15,3 @@ export interface Req {

interface File {
export interface File {
name: string

@@ -29,3 +30,6 @@ tempPath: string

export interface Res {
export type PostMessage = ResponsePostMessage | WritePostMessage | LogPostMessage
export interface ResponsePostMessage {
type: 'response'
statusCode: number

@@ -35,7 +39,17 @@ headers: {

}
send: (obj: ObjectOf<any> | string) => void
body: any
}
export interface PostMessage {
type: 'response' | 'log'
export interface WritePostMessage {
type: 'write',
body: any
}
export interface LogPostMessage {
type: 'log',
level: LogLevel,
message: string
}
export class Res {
statusCode: number

@@ -45,20 +59,28 @@ headers: {

}
body: ObjectOf<any> | string
}
export const res: Res = {
statusCode: 200,
headers: {},
constructor() {
this.statusCode = 200
this.headers = {}
}
send: (body: ObjectOf<any> | string) => {
write(body: any) {
parentPort.postMessage({
type: 'write',
body
} as WritePostMessage)
}
send(body?: any) {
parentPort.postMessage({
type: 'response',
statusCode: res.statusCode,
headers: res.headers,
statusCode: this.statusCode,
headers: this.headers,
body
} as PostMessage)
} as ResponsePostMessage)
}
}
export const log = async (level: 'i' | 'w' | 'e', message: string | Error) => {
export const res = new Res()
export const log = async (level: LogLevel, message: string | Error) => {
if (message instanceof Error) {

@@ -68,8 +90,3 @@ message = message.stack

parentPort.postMessage({
type: 'log',
headers: {
level, message
}
})
parentPort.postMessage({ type: 'log', level, message } as LogPostMessage)
}
{
"name": "apache-js-workers",
"version": "0.0.13",
"version": "0.0.14",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

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