Socket
Socket
Sign inDemoInstall

@prisma/debug

Package Overview
Dependencies
Maintainers
7
Versions
8224
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prisma/debug - npm Package Compare versions

Comparing version 2.0.0-alpha.1205 to 2.0.0-alpha.1210

dist/__tests__/basic.test.d.ts

6

dist/index.d.ts
import DebugLib from 'debug';
declare function Debug(namespace: string): DebugLib.Debugger;
declare namespace Debug {
var enable: (namespace: any) => void;
var enabled: (namespace: any) => boolean;
var enable: (namespace: string) => void;
var enabled: (namespace: string) => boolean;
}
export default Debug;
export declare type Debugger = DebugLib.Debugger;
export declare function getLogs(numLines?: number): string;
export declare function getLogs(numChars?: number): string;

@@ -12,6 +12,39 @@ "use strict";

const enabledNamespaces = new Map();
// parse the enabled namespaces that come from process.env.DEBUG
const envDebug = process.env.DEBUG ? process.env.DEBUG + ',' : '';
const skips = debug_1.default.skips.slice();
const names = debug_1.default.names.slice();
// same algorithm as original `debug` library:
function isEnabledByEnvVar(name) {
if (name[name.length - 1] === '*') {
return true;
}
for (const skip of skips) {
if (skip.test(name)) {
return false;
}
}
for (const nameRegex of names) {
if (nameRegex.test(name)) {
return true;
}
}
return false;
}
function Debug(namespace) {
const debug = debug_1.default(namespace);
namespaces.push(namespace);
debug_1.default.enable(namespaces.join(','));
debug_1.default.enable(envDebug + namespaces.join(','));
if (isEnabledByEnvVar(namespace)) {
enabledNamespaces.set(namespace, true);
}
const newDebug = (formatter, ...args) => {
return debug(formatter, ...args);
};
newDebug.log = console.error.bind(console);
newDebug.color = debug.color;
newDebug.namespace = debug.namespace;
newDebug.enabled = debug.enabled;
newDebug.destroy = debug.destroy;
newDebug.extend = debug.extend;
debug.log = (...args) => {

@@ -24,6 +57,6 @@ cache.push(args);

if (enabledNamespaces.has(namespace)) {
console.error(...args);
newDebug.log(...args);
}
};
return debug;
return newDebug;
}

@@ -35,14 +68,13 @@ exports.default = Debug;

Debug.enabled = (namespace) => enabledNamespaces.has(namespace);
function getLogs(numLines = 100) {
// https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
// we need some space for other characters, so we go for 30k here
function getLogs(numChars = 30000) {
// flatmap on text level
const lines = cache
.map((c) => c.join(' '))
.join('\n')
.split('\n'); // no this is not a no-op
if (lines.length <= numLines) {
return lines.join('\n');
let output = cache.map((c) => c.join(' ')).join('\n');
if (output.length < numChars) {
return output;
}
return lines.slice(-numLines).join('\n');
return output.slice(-numChars);
}
exports.getLogs = getLogs;
//# sourceMappingURL=index.js.map
{
"name": "@prisma/debug",
"version": "2.0.0-alpha.1205",
"version": "2.0.0-alpha.1210",
"main": "dist/index.js",

@@ -21,2 +21,3 @@ "types": "dist/index.d.ts",

"lint-staged": "^10.1.4",
"strip-ansi": "^6.0.0",
"ts-jest": "^25.3.1",

@@ -23,0 +24,0 @@ "typescript": "^3.8.3"

@@ -1,4 +0,4 @@

# @prisma/get-platform
# @prisma/debug
Platform detection used for Prisma 2 binaries.
A cached [`debug`](https://github.com/visionmedia/debug/).

@@ -8,5 +8,16 @@ ## Usage

```ts
import { getPlatform } from '@prisma/get-platform'
import Debug, { getLogs } from '@prisma/debug'
const platform = await getPlatform()
const debug = Debug('my-namespace')
try {
debug('hello')
debug(process.env)
throw new Error('oops')
} catch (e) {
console.error(e)
console.error(`We just crashed. But no worries, here are the debug logs:`)
// get 10 last lines of debug logs
console.error(getLogs(10))
}
```

Sorry, the diff of this file is not supported yet

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