@ulixee/commons
Advanced tools
Comparing version 2.0.0-alpha.28 to 2.0.0-alpha.29
@@ -6,2 +6,15 @@ # Change Log | ||
# [2.0.0-alpha.29](https://github.com/ulixee/shared/compare/v2.0.0-alpha.28...v2.0.0-alpha.29) (2024-07-16) | ||
### Bug Fixes | ||
* **commons:** fix serializing uint8array ([d5b8c62](https://github.com/ulixee/shared/commit/d5b8c623c8ae7478b77cbc21ba699a937752d9b9)) | ||
* **commons:** handle no json file ([28c6243](https://github.com/ulixee/shared/commit/28c6243d844928c65d050612e486382480f8ced2)) | ||
* use this prototype ([#22](https://github.com/ulixee/shared/issues/22)) ([ff9a5ce](https://github.com/ulixee/shared/commit/ff9a5ced79e4fae570cbd74d137b8edb44f74130)) | ||
# [2.0.0-alpha.28](https://github.com/ulixee/shared/compare/v2.0.0-alpha.27...v2.0.0-alpha.28) (2024-03-11) | ||
@@ -8,0 +21,0 @@ |
@@ -7,3 +7,3 @@ import { TypedEventEmitter } from '../lib/eventUtils'; | ||
readonly directoryPath: string; | ||
static global: UlixeeHostsConfig; | ||
static get global(): UlixeeHostsConfig; | ||
hostByVersion: IUlixeeHostsConfig['hostByVersion']; | ||
@@ -10,0 +10,0 @@ private get configPath(); |
@@ -17,2 +17,5 @@ "use strict"; | ||
class UlixeeHostsConfig extends eventUtils_1.TypedEventEmitter { | ||
static get global() { | ||
return new UlixeeHostsConfig(Path.join((0, dirUtils_1.getDataDirectory)(), 'ulixee')); | ||
} | ||
get configPath() { | ||
@@ -118,4 +121,3 @@ return Path.join(this.directoryPath, 'hosts'); | ||
_UlixeeHostsConfig_watchHandle = new WeakMap(); | ||
UlixeeHostsConfig.global = new UlixeeHostsConfig(Path.join((0, dirUtils_1.getDataDirectory)(), 'ulixee')); | ||
exports.default = UlixeeHostsConfig; | ||
//# sourceMappingURL=hosts.js.map |
@@ -0,1 +1,2 @@ | ||
import IRegisteredEventListener from './IRegisteredEventListener'; | ||
export default interface ITypedEventEmitter<T> { | ||
@@ -11,2 +12,3 @@ on<K extends keyof T & (string | symbol)>(eventType: K, listenerFn: (this: this, event?: T[K]) => any, includeUnhandledEvents?: boolean): this; | ||
removeAllListeners(event?: string | symbol): this; | ||
addEventEmitter<K extends keyof T & (string | symbol)>(emitter: ITypedEventEmitter<T>, eventTypes: K[]): IRegisteredEventListener[]; | ||
} |
@@ -1,2 +0,2 @@ | ||
export declare function debounce(func: () => any, wait: number): () => void; | ||
export declare function debounce<T extends (...args: any[]) => void | Promise<void>>(func: T, wait: number, maxWait?: number): T; | ||
export declare function length(source: AsyncIterable<unknown>): Promise<number>; | ||
@@ -3,0 +3,0 @@ export declare function all<T>(source: AsyncIterable<T>): Promise<T[]>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.last = exports.first = exports.all = exports.length = exports.debounce = void 0; | ||
function debounce(func, wait) { | ||
function debounce(func, wait, maxWait) { | ||
let timeout; | ||
return function runLater() { | ||
let lastRun; | ||
return function runLater(...args) { | ||
function later() { | ||
timeout = undefined; | ||
func(); | ||
void func(...args); | ||
} | ||
clearTimeout(timeout); | ||
timeout = setTimeout(later, wait).unref(); | ||
if (maxWait && Date.now() - lastRun > maxWait) { | ||
void func(...args); | ||
} | ||
else { | ||
timeout = setTimeout(later, wait).unref(); | ||
} | ||
lastRun = Date.now(); | ||
}; | ||
@@ -14,0 +21,0 @@ } |
@@ -1,2 +0,1 @@ | ||
export declare function getCacheDirectory(): string; | ||
export declare function getDataDirectory(): string; | ||
@@ -3,0 +2,0 @@ export declare function cleanHomeDir(str: string): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.findProjectPathAsync = exports.findProjectPathSync = exports.cleanHomeDir = exports.getDataDirectory = exports.getCacheDirectory = void 0; | ||
exports.findProjectPathAsync = exports.findProjectPathSync = exports.cleanHomeDir = exports.getDataDirectory = void 0; | ||
const Fs = require("fs"); | ||
const os = require("os"); | ||
const Path = require("path"); | ||
const Fs = require("fs"); | ||
const envUtils_1 = require("./envUtils"); | ||
const fileUtils_1 = require("./fileUtils"); | ||
function getCacheDirectory() { | ||
if (process.platform === 'linux') { | ||
return process.env.XDG_CACHE_HOME || Path.join(os.homedir(), '.cache'); | ||
function getDataDirectory() { | ||
if (process.env.ULX_DATA_DIR) { | ||
return (0, envUtils_1.parseEnvPath)(process.env.ULX_DATA_DIR); | ||
} | ||
if (process.platform === 'darwin') { | ||
return Path.join(os.homedir(), 'Library', 'Caches'); | ||
} | ||
if (process.platform === 'win32') { | ||
return process.env.LOCALAPPDATA || Path.join(os.homedir(), 'AppData', 'Local'); | ||
} | ||
throw new Error(`Unsupported platform: ${process.platform}`); | ||
} | ||
exports.getCacheDirectory = getCacheDirectory; | ||
function getDataDirectory() { | ||
if (process.platform === 'linux') { | ||
@@ -23,0 +14,0 @@ return process.env.XDG_DATA_HOME || Path.join(os.homedir(), '.local', 'share'); |
@@ -5,4 +5,4 @@ "use strict"; | ||
const Fs = require("fs"); | ||
const Os = require("os"); | ||
const Path = require("path"); | ||
const Os = require("os"); | ||
const dirUtils_1 = require("./dirUtils"); | ||
@@ -76,4 +76,2 @@ /** | ||
envvar = Path.join(Os.homedir(), envvar.slice(1)); | ||
if (envvar?.startsWith('<CACHE>')) | ||
envvar = envvar.replace('<CACHE>', (0, dirUtils_1.getCacheDirectory)()); | ||
if (envvar?.startsWith('<DATA>')) | ||
@@ -80,0 +78,0 @@ envvar = envvar.replace('<DATA>', (0, dirUtils_1.getDataDirectory)()); |
@@ -29,3 +29,3 @@ "use strict"; | ||
async function readFileAsJson(path) { | ||
const buffer = await fs_1.promises.readFile(path, 'utf8'); | ||
const buffer = await fs_1.promises.readFile(path, 'utf8').catch(() => null); | ||
if (!buffer) | ||
@@ -32,0 +32,0 @@ return null; |
/// <reference types="node" /> | ||
import ILog, { ILogData } from '../interfaces/ILog'; | ||
declare global { | ||
function UlixeeLogCreator(module: NodeModule): { | ||
log: ILog; | ||
}; | ||
var UlxLogPrototype: Log; | ||
var UlxLogFilters: any; | ||
var UlxLoggerSessionIdNames: Map<string, string>; | ||
var UlxSubscriptions: Map<number, (log: ILogEntry) => any>; | ||
} | ||
declare const hasBeenLoggedSymbol: unique symbol; | ||
@@ -35,10 +44,2 @@ declare class Log implements ILog { | ||
}; | ||
declare global { | ||
function UlixeeLogCreator(module: NodeModule): { | ||
log: ILog; | ||
}; | ||
var UlixeeLogClass: typeof Log; | ||
var UlxLoggerSessionIdNames: Map<string, string>; | ||
var UlxSubscriptions: Map<number, (log: ILogEntry) => any>; | ||
} | ||
export default function logger(module: NodeModule): ILogBuilder; | ||
@@ -45,0 +46,0 @@ declare const loggerSessionIdNames: Map<string, string>; |
@@ -22,4 +22,2 @@ "use strict"; | ||
this.logtimeById = {}; | ||
global.UlxLogPrototype ??= Log.prototype; | ||
Object.setPrototypeOf(this, global.UlxLogPrototype); | ||
this.module = module ? extractPathFromModule(module) : ''; | ||
@@ -110,5 +108,8 @@ if (boundContext) | ||
exports.Log = Log; | ||
function translateValueToPrintable(value, depth = 0) { | ||
function translateValueToPrintable(key, value, depth = 0) { | ||
if (value === undefined || value === null) | ||
return; | ||
if (key === 'password' || key === 'suri') { | ||
return '********'; | ||
} | ||
if (value instanceof Error) { | ||
@@ -138,7 +139,7 @@ return value.toString(); | ||
if (Array.isArray(value)) { | ||
return value.map(x => translateValueToPrintable(x, depth + 1)); | ||
return value.map((x, i) => translateValueToPrintable(i, x, depth + 1)); | ||
} | ||
const result = {}; | ||
for (const [key, subValue] of Object.entries(value)) { | ||
result[key] = translateValueToPrintable(subValue, depth + 1); | ||
for (const [subKey, subValue] of Object.entries(value)) { | ||
result[subKey] = translateValueToPrintable(subKey, subValue, depth + 1); | ||
} | ||
@@ -175,3 +176,3 @@ return result; | ||
} | ||
const printable = translateValueToPrintable(value); | ||
const printable = translateValueToPrintable(key, value); | ||
if (printable === null || printable === undefined) | ||
@@ -188,2 +189,6 @@ continue; | ||
const log = new Log(module); | ||
// This code ensures a single version of Log is used across all @ulixee/commons that are loaded into memory. | ||
// We don't update it if an injected logger is used. | ||
global.UlxLogPrototype ??= Log.prototype; | ||
Object.setPrototypeOf(log, global.UlxLogPrototype); | ||
return { | ||
@@ -194,3 +199,2 @@ log, | ||
} | ||
global.UlixeeLogClass ??= Log; | ||
function logger(module) { | ||
@@ -231,3 +235,2 @@ return global.UlixeeLogCreator(module); | ||
.replace(/^(.*)[/\\]ulixee[/\\](.+)$/, '$2') | ||
.replace(/^(.*)[/\\]payments[/\\](.+)$/, '$2') | ||
.replace(/^(.*)[/\\]@ulixee[/\\](.+)$/, '$2') | ||
@@ -295,3 +298,3 @@ .replace(/^(.*)[/\\]commons[/\\](.+)$/, '$2') | ||
else if (ns === 'ulx') { | ||
active.push(/hero[/-].*/, /agent\/.*/, /plugins\/.*/, /net\/.*/, /cloud\/.*/, /datastore[/-].*/, /mainchain[/-].*/, /sidechain[/-].*/, /ramps[/-].*/); | ||
active.push(/hero[/-].*/, /agent\/.*/, /plugins\/.*/, /net\/.*/, /cloud\/.*/, /datastore[/-].*/, /broker\/.*/, /mainchain[/-].*/, /sidechain[/-].*/, /ramps[/-].*/); | ||
skip.push(/desktop[/-]?.*/, /DevtoolsSessionLogger/); | ||
@@ -298,0 +301,0 @@ } |
export declare function filterUndefined<T>(object: T, omitKeys?: string[]): Partial<T>; | ||
export declare function omit<T, Keys extends keyof T & string>(object: T, keys: Keys[]): Pick<T, Exclude<keyof T, Keys>>; | ||
export declare function pick<T, Keys extends keyof T & string>(object: T, keys: Keys[]): Pick<T, Exclude<keyof T, Keys>>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.omit = exports.filterUndefined = void 0; | ||
exports.pick = exports.omit = exports.filterUndefined = void 0; | ||
function filterUndefined(object, omitKeys) { | ||
@@ -28,2 +28,13 @@ if (!object) | ||
exports.omit = omit; | ||
function pick(object, keys) { | ||
object = Object(object); | ||
const result = {}; | ||
for (const [key, value] of Object.entries(object)) { | ||
if (keys.includes(key)) { | ||
result[key] = value; | ||
} | ||
} | ||
return result; | ||
} | ||
exports.pick = pick; | ||
//# sourceMappingURL=objectUtils.js.map |
@@ -147,4 +147,5 @@ "use strict"; | ||
if (ArrayBuffer.isView(value)) { | ||
// @ts-ignore | ||
const binary = new TextDecoder('utf8').decode(value.buffer); | ||
const binary = Array.from(new Uint8Array(value.buffer, value.byteOffset, value.byteLength)) | ||
.map(byte => String.fromCharCode(byte)) | ||
.join(''); | ||
return { | ||
@@ -161,4 +162,3 @@ __type: Types.ArrayBuffer64, | ||
if (value instanceof ArrayBuffer) { | ||
// @ts-ignore | ||
const binary = new TextDecoder('utf8').decode(value); | ||
const binary = Array.from(new Uint8Array(value)).map(byte => String.fromCharCode(byte)).join(''); | ||
return { | ||
@@ -196,4 +196,6 @@ __type: Types.ArrayBuffer64, | ||
const decoded = globalThis.atob(value); | ||
// @ts-ignore | ||
const uint8Array = new TextEncoder().encode(decoded); | ||
const uint8Array = new Uint8Array(new ArrayBuffer(decoded.length)); | ||
for (let i = 0; i < decoded.length; i++) { | ||
uint8Array[i] = decoded.charCodeAt(i); | ||
} | ||
if (!entry.args) | ||
@@ -200,0 +202,0 @@ return uint8Array; |
@@ -30,8 +30,6 @@ "use strict"; | ||
return new Promise((resolve, reject) => { | ||
const client = new net.Socket(); | ||
let isInUse = true; | ||
client.once('error', err => { | ||
if (err.code === 'ECONNREFUSED') { | ||
isInUse = false; | ||
resolve(isInUse); | ||
const server = net.createServer(); | ||
server.once('error', err => { | ||
if (err.code === 'EADDRINUSE') { | ||
resolve(true); // Port is in use | ||
} | ||
@@ -41,8 +39,14 @@ else { | ||
} | ||
client.removeAllListeners().end().destroy().unref(); | ||
cleanup(); | ||
}); | ||
client.connect(Number(port), () => { | ||
resolve(isInUse); | ||
client.removeAllListeners().end().destroy().unref(); | ||
server.once('listening', () => { | ||
resolve(false); | ||
cleanup(); | ||
}); | ||
const cleanup = () => { | ||
server.removeAllListeners(); | ||
server.unref(); | ||
server.close(); | ||
}; | ||
server.listen(Number(port)); | ||
}); | ||
@@ -49,0 +53,0 @@ } |
{ | ||
"name": "@ulixee/commons", | ||
"version": "2.0.0-alpha.28", | ||
"version": "2.0.0-alpha.29", | ||
"description": "Common utilities for Ulixee", | ||
@@ -19,3 +19,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "367ef2fa5f7031c2374a1b33d5944d95ee731aef" | ||
"gitHead": "4fcb78bc7fe83c6c074b92bed59b8c6cbaa4fe2f" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
292445
4061