@prisma/debug 6.4.0-dev.5 → 6.4.0-dev.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ export declare function clearLogs(): void;
2
+
3
+ declare const Debug: typeof debugCreate & {
4
+ enable(namespace: any): void;
5
+ disable(): any;
6
+ enabled(namespace: string): boolean;
7
+ log: (...args: string[]) => void;
8
+ formatters: {};
9
+ };
10
+ export { Debug }
11
+ export default Debug;
12
+
13
+ /**
14
+ * Create a new debug instance with the given namespace.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import Debug from '@prisma/debug'
19
+ * const debug = Debug('prisma:client')
20
+ * debug('Hello World')
21
+ * ```
22
+ */
23
+ declare function debugCreate(namespace: string): ((...args: any[]) => void) & {
24
+ color: string;
25
+ enabled: boolean;
26
+ namespace: string;
27
+ log: (...args: string[]) => void;
28
+ extend: () => void;
29
+ };
30
+
31
+ /**
32
+ * We can get the logs for all the last {@link MAX_ARGS_HISTORY} ${@link debugCall} that
33
+ * have happened in the different packages. Useful to generate error report links.
34
+ * @see https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
35
+ * @param numChars
36
+ * @returns
37
+ */
38
+ export declare function getLogs(numChars?: number): string;
39
+
40
+ export { }
package/dist/index.d.ts CHANGED
@@ -1,35 +1,40 @@
1
- /**
2
- * Create a new debug instance with the given namespace.
3
- *
4
- * @example
5
- * ```ts
6
- * import Debug from '@prisma/debug'
7
- * const debug = Debug('prisma:client')
8
- * debug('Hello World')
9
- * ```
10
- */
11
- declare function debugCreate(namespace: string): ((...args: any[]) => void) & {
12
- color: string;
13
- enabled: boolean;
14
- namespace: string;
15
- log: (...args: string[]) => void;
16
- extend: () => void;
17
- };
18
- declare const Debug: typeof debugCreate & {
19
- enable(namespace: any): void;
20
- disable(): any;
21
- enabled(namespace: string): boolean;
22
- log: (...args: string[]) => void;
23
- formatters: {};
24
- };
25
- /**
26
- * We can get the logs for all the last {@link MAX_ARGS_HISTORY} ${@link debugCall} that
27
- * have happened in the different packages. Useful to generate error report links.
28
- * @see https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
29
- * @param numChars
30
- * @returns
31
- */
32
- export declare function getLogs(numChars?: number): string;
33
- export declare function clearLogs(): void;
34
- export { Debug };
35
- export default Debug;
1
+ export declare function clearLogs(): void;
2
+
3
+ declare const Debug: typeof debugCreate & {
4
+ enable(namespace: any): void;
5
+ disable(): any;
6
+ enabled(namespace: string): boolean;
7
+ log: (...args: string[]) => void;
8
+ formatters: {};
9
+ };
10
+ export { Debug }
11
+ export default Debug;
12
+
13
+ /**
14
+ * Create a new debug instance with the given namespace.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import Debug from '@prisma/debug'
19
+ * const debug = Debug('prisma:client')
20
+ * debug('Hello World')
21
+ * ```
22
+ */
23
+ declare function debugCreate(namespace: string): ((...args: any[]) => void) & {
24
+ color: string;
25
+ enabled: boolean;
26
+ namespace: string;
27
+ log: (...args: string[]) => void;
28
+ extend: () => void;
29
+ };
30
+
31
+ /**
32
+ * We can get the logs for all the last {@link MAX_ARGS_HISTORY} ${@link debugCall} that
33
+ * have happened in the different packages. Useful to generate error report links.
34
+ * @see https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
35
+ * @param numChars
36
+ * @returns
37
+ */
38
+ export declare function getLogs(numChars?: number): string;
39
+
40
+ export { }
package/dist/index.mjs ADDED
@@ -0,0 +1,213 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // ../../node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/colors.mjs
8
+ var colors_exports = {};
9
+ __export(colors_exports, {
10
+ $: () => $,
11
+ bgBlack: () => bgBlack,
12
+ bgBlue: () => bgBlue,
13
+ bgCyan: () => bgCyan,
14
+ bgGreen: () => bgGreen,
15
+ bgMagenta: () => bgMagenta,
16
+ bgRed: () => bgRed,
17
+ bgWhite: () => bgWhite,
18
+ bgYellow: () => bgYellow,
19
+ black: () => black,
20
+ blue: () => blue,
21
+ bold: () => bold,
22
+ cyan: () => cyan,
23
+ dim: () => dim,
24
+ gray: () => gray,
25
+ green: () => green,
26
+ grey: () => grey,
27
+ hidden: () => hidden,
28
+ inverse: () => inverse,
29
+ italic: () => italic,
30
+ magenta: () => magenta,
31
+ red: () => red,
32
+ reset: () => reset,
33
+ strikethrough: () => strikethrough,
34
+ underline: () => underline,
35
+ white: () => white,
36
+ yellow: () => yellow
37
+ });
38
+ var FORCE_COLOR;
39
+ var NODE_DISABLE_COLORS;
40
+ var NO_COLOR;
41
+ var TERM;
42
+ var isTTY = true;
43
+ if (typeof process !== "undefined") {
44
+ ({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {});
45
+ isTTY = process.stdout && process.stdout.isTTY;
46
+ }
47
+ var $ = {
48
+ enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== "dumb" && (FORCE_COLOR != null && FORCE_COLOR !== "0" || isTTY)
49
+ };
50
+ function init(x, y) {
51
+ let rgx = new RegExp(`\\x1b\\[${y}m`, "g");
52
+ let open = `\x1B[${x}m`, close = `\x1B[${y}m`;
53
+ return function(txt) {
54
+ if (!$.enabled || txt == null) return txt;
55
+ return open + (!!~("" + txt).indexOf(close) ? txt.replace(rgx, close + open) : txt) + close;
56
+ };
57
+ }
58
+ var reset = init(0, 0);
59
+ var bold = init(1, 22);
60
+ var dim = init(2, 22);
61
+ var italic = init(3, 23);
62
+ var underline = init(4, 24);
63
+ var inverse = init(7, 27);
64
+ var hidden = init(8, 28);
65
+ var strikethrough = init(9, 29);
66
+ var black = init(30, 39);
67
+ var red = init(31, 39);
68
+ var green = init(32, 39);
69
+ var yellow = init(33, 39);
70
+ var blue = init(34, 39);
71
+ var magenta = init(35, 39);
72
+ var cyan = init(36, 39);
73
+ var white = init(37, 39);
74
+ var gray = init(90, 39);
75
+ var grey = init(90, 39);
76
+ var bgBlack = init(40, 49);
77
+ var bgRed = init(41, 49);
78
+ var bgGreen = init(42, 49);
79
+ var bgYellow = init(43, 49);
80
+ var bgBlue = init(44, 49);
81
+ var bgMagenta = init(45, 49);
82
+ var bgCyan = init(46, 49);
83
+ var bgWhite = init(47, 49);
84
+
85
+ // src/index.ts
86
+ var MAX_ARGS_HISTORY = 100;
87
+ var COLORS = ["green", "yellow", "blue", "magenta", "cyan", "red"];
88
+ var argsHistory = [];
89
+ var lastTimestamp = Date.now();
90
+ var lastColor = 0;
91
+ var processEnv = typeof process !== "undefined" ? process.env : {};
92
+ globalThis.DEBUG ??= processEnv.DEBUG ?? "";
93
+ globalThis.DEBUG_COLORS ??= processEnv.DEBUG_COLORS ? processEnv.DEBUG_COLORS === "true" : true;
94
+ var topProps = {
95
+ enable(namespace) {
96
+ if (typeof namespace === "string") {
97
+ globalThis.DEBUG = namespace;
98
+ }
99
+ },
100
+ disable() {
101
+ const prev = globalThis.DEBUG;
102
+ globalThis.DEBUG = "";
103
+ return prev;
104
+ },
105
+ // this is the core logic to check if logging should happen or not
106
+ enabled(namespace) {
107
+ const listenedNamespaces = globalThis.DEBUG.split(",").map((s) => {
108
+ return s.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
109
+ });
110
+ const isListened = listenedNamespaces.some((listenedNamespace) => {
111
+ if (listenedNamespace === "" || listenedNamespace[0] === "-") return false;
112
+ return namespace.match(RegExp(listenedNamespace.split("*").join(".*") + "$"));
113
+ });
114
+ const isExcluded = listenedNamespaces.some((listenedNamespace) => {
115
+ if (listenedNamespace === "" || listenedNamespace[0] !== "-") return false;
116
+ return namespace.match(RegExp(listenedNamespace.slice(1).split("*").join(".*") + "$"));
117
+ });
118
+ return isListened && !isExcluded;
119
+ },
120
+ log: (...args) => {
121
+ const [namespace, format, ...rest] = args;
122
+ const logWithFormatting = console.warn ?? console.log;
123
+ logWithFormatting(`${namespace} ${format}`, ...rest);
124
+ },
125
+ formatters: {}
126
+ // not implemented
127
+ };
128
+ function debugCreate(namespace) {
129
+ const instanceProps = {
130
+ color: COLORS[lastColor++ % COLORS.length],
131
+ enabled: topProps.enabled(namespace),
132
+ namespace,
133
+ log: topProps.log,
134
+ extend: () => {
135
+ }
136
+ // not implemented
137
+ };
138
+ const debugCall = (...args) => {
139
+ const { enabled, namespace: namespace2, color, log } = instanceProps;
140
+ if (args.length !== 0) {
141
+ argsHistory.push([namespace2, ...args]);
142
+ }
143
+ if (argsHistory.length > MAX_ARGS_HISTORY) {
144
+ argsHistory.shift();
145
+ }
146
+ if (topProps.enabled(namespace2) || enabled) {
147
+ const stringArgs = args.map((arg) => {
148
+ if (typeof arg === "string") {
149
+ return arg;
150
+ }
151
+ return safeStringify(arg);
152
+ });
153
+ const ms = `+${Date.now() - lastTimestamp}ms`;
154
+ lastTimestamp = Date.now();
155
+ if (globalThis.DEBUG_COLORS) {
156
+ log(colors_exports[color](bold(namespace2)), ...stringArgs, colors_exports[color](ms));
157
+ } else {
158
+ log(namespace2, ...stringArgs, ms);
159
+ }
160
+ }
161
+ };
162
+ return new Proxy(debugCall, {
163
+ get: (_, prop) => instanceProps[prop],
164
+ set: (_, prop, value) => instanceProps[prop] = value
165
+ });
166
+ }
167
+ var Debug = new Proxy(debugCreate, {
168
+ get: (_, prop) => topProps[prop],
169
+ set: (_, prop, value) => topProps[prop] = value
170
+ });
171
+ function safeStringify(value, indent = 2) {
172
+ const cache = /* @__PURE__ */ new Set();
173
+ return JSON.stringify(
174
+ value,
175
+ (key, value2) => {
176
+ if (typeof value2 === "object" && value2 !== null) {
177
+ if (cache.has(value2)) {
178
+ return `[Circular *]`;
179
+ }
180
+ cache.add(value2);
181
+ } else if (typeof value2 === "bigint") {
182
+ return value2.toString();
183
+ }
184
+ return value2;
185
+ },
186
+ indent
187
+ );
188
+ }
189
+ function getLogs(numChars = 7500) {
190
+ const logs = argsHistory.map(([namespace, ...args]) => {
191
+ return `${namespace} ${args.map((arg) => {
192
+ if (typeof arg === "string") {
193
+ return arg;
194
+ } else {
195
+ return JSON.stringify(arg);
196
+ }
197
+ }).join(" ")}`;
198
+ }).join("\n");
199
+ if (logs.length < numChars) {
200
+ return logs;
201
+ }
202
+ return logs.slice(-numChars);
203
+ }
204
+ function clearLogs() {
205
+ argsHistory.length = 0;
206
+ }
207
+ var index_default = Debug;
208
+ export {
209
+ Debug,
210
+ clearLogs,
211
+ index_default as default,
212
+ getLogs
213
+ };
package/package.json CHANGED
@@ -1,9 +1,22 @@
1
1
  {
2
2
  "name": "@prisma/debug",
3
- "version": "6.4.0-dev.5",
3
+ "version": "6.4.0-dev.50",
4
4
  "description": "This package is intended for Prisma's internal use",
5
5
  "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
6
7
  "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "require": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "import": {
15
+ "types": "./dist/index.d.mts",
16
+ "default": "./dist/index.mjs"
17
+ }
18
+ }
19
+ },
7
20
  "license": "Apache-2.0",
8
21
  "author": "Tim Suchanek <suchanek@prisma.io>",
9
22
  "homepage": "https://www.prisma.io",
package/dist/util.js DELETED
@@ -1,74 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function __require() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
-
33
- // ../../node_modules/.pnpm/ansi-regex@5.0.1/node_modules/ansi-regex/index.js
34
- var require_ansi_regex = __commonJS({
35
- "../../node_modules/.pnpm/ansi-regex@5.0.1/node_modules/ansi-regex/index.js"(exports2, module2) {
36
- "use strict";
37
- module2.exports = ({ onlyFirst = false } = {}) => {
38
- const pattern = [
39
- "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
40
- "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"
41
- ].join("|");
42
- return new RegExp(pattern, onlyFirst ? void 0 : "g");
43
- };
44
- }
45
- });
46
-
47
- // ../../node_modules/.pnpm/strip-ansi@6.0.1/node_modules/strip-ansi/index.js
48
- var require_strip_ansi = __commonJS({
49
- "../../node_modules/.pnpm/strip-ansi@6.0.1/node_modules/strip-ansi/index.js"(exports2, module2) {
50
- "use strict";
51
- var ansiRegex = require_ansi_regex();
52
- module2.exports = (string) => typeof string === "string" ? string.replace(ansiRegex(), "") : string;
53
- }
54
- });
55
-
56
- // src/util.ts
57
- var util_exports = {};
58
- __export(util_exports, {
59
- removeISODate: () => removeISODate,
60
- sanitizeTestLogs: () => sanitizeTestLogs
61
- });
62
- module.exports = __toCommonJS(util_exports);
63
- var import_strip_ansi = __toESM(require_strip_ansi());
64
- function removeISODate(str) {
65
- return str.replace(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/gim, "");
66
- }
67
- function sanitizeTestLogs(str) {
68
- return (0, import_strip_ansi.default)(str).split("\n").map((l) => removeISODate(l.replace(/\+\d+ms$/, "")).trim()).join("\n");
69
- }
70
- // Annotate the CommonJS export names for ESM import in node:
71
- 0 && (module.exports = {
72
- removeISODate,
73
- sanitizeTestLogs
74
- });