prisma-query-log
Advanced tools
Comparing version 3.0.2 to 3.1.0
59
index.js
var __defProp = Object.defineProperty; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); | ||
var __export = (target, all) => { | ||
__markAsModule(target); | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __reExport = (target, module2, copyDefault, desc) => { | ||
if (module2 && typeof module2 === "object" || typeof module2 === "function") { | ||
for (let key of __getOwnPropNames(module2)) | ||
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default")) | ||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable }); | ||
} | ||
return target; | ||
}; | ||
var __toCommonJS = /* @__PURE__ */ ((cache) => { | ||
return (module2, temp) => { | ||
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp); | ||
}; | ||
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0); | ||
// src/index.ts | ||
__export(exports, { | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
createPrismaQueryEventHandler: () => createPrismaQueryEventHandler | ||
@@ -46,3 +47,3 @@ }); | ||
var _a; | ||
const options = __spreadValues(__spreadValues({}, defaultOptions), args); | ||
const options = { ...defaultOptions, ...args }; | ||
const logger = options.logger === true ? console.log : options.logger; | ||
@@ -62,5 +63,5 @@ if (typeof logger !== "function") { | ||
} | ||
query = query.replace(/\?/g, (_, index, string) => { | ||
query = query.replace(/(\?|\$\d+)/g, (match, p1, offset, string) => { | ||
let parameter = JSON.stringify(params.shift()); | ||
const previousChar = string.charAt(index - 1); | ||
const previousChar = string.charAt(offset - 1); | ||
if (colorQuery && colorParameter) { | ||
@@ -84,17 +85,18 @@ parameter = colorParameter + parameter + "[0m" + colorQuery; | ||
function unescapeQuery(query) { | ||
const regex = /`\w+`(\.`\w+`)?(\.`\w+`)?/g; | ||
const regex = /(?<quote>["`])\w+["`](\.["`]\w+["`])?(\.["`]\w+["`])?/g; | ||
const matchAllResult = query.matchAll(regex); | ||
const matches = Array.from(matchAllResult); | ||
for (let index = matches.length - 1; index >= 0; index--) { | ||
const { 0: fullMatch, index: matchIndex } = matches[index]; | ||
const { | ||
0: fullMatch, | ||
index: matchIndex, | ||
groups: { quote } = {} | ||
} = matches[index]; | ||
if (!matchIndex || !fullMatch) { | ||
continue; | ||
} | ||
const parts = fullMatch.split("`.`"); | ||
let replacement = ""; | ||
if (parts.length >= 2) { | ||
parts.shift(); | ||
replacement = parts.join(".").slice(0, -1); | ||
} else { | ||
replacement = parts[0].slice(1, -1); | ||
let replacement = fullMatch.replace(/["`]\w+["`]\.(["`]\w+["`](\.["`]\w+["`])?)/g, "$1"); | ||
if (quote === "`") { | ||
const parts = replacement.split("`.`"); | ||
replacement = parts.join(".").slice(1, -1); | ||
} | ||
@@ -105,2 +107,3 @@ query = query.slice(0, matchIndex) + replacement + query.slice(matchIndex + fullMatch.length); | ||
} | ||
module.exports = __toCommonJS(src_exports); | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -107,0 +110,0 @@ 0 && (module.exports = { |
{ | ||
"name": "prisma-query-log", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"license": "MIT", | ||
@@ -10,22 +10,14 @@ "description": "Log prisma query event", | ||
"scripts": { | ||
"test": "npm run lint:src && npm run lint:ts && npm run test:cov", | ||
"test:r": "node -r ts-node/register/transpile-only node_modules/mocha/bin/_mocha src/**/*.spec.ts", | ||
"test:cov": "c8 --reporter text --exclude \"**/*.spec.ts\" --exclude \"**/testing/**\" npm run test:r -- --no-timeouts", | ||
"test:w": "npm run test:r -- --watch --watch-files src/**/*.ts", | ||
"lint": "npm run lint:src && npm run lint:ts", | ||
"lint:src": "node node_modules/eslint/bin/eslint \"src/**/*.{ts,tsx}\"", | ||
"lint:src:fix": "npm run lint:src -- --fix", | ||
"lint:ts": "tsc --noEmit", | ||
"lint:ts:w": "npm run lint:ts -- --watch", | ||
"lint:src:w": "watchexec -w src \"npm run lint:src\"", | ||
"lint:fix": "npm run lint:src:fix && npm run lint:doc:fix", | ||
"lint:doc": "sh Taskfile remark_run", | ||
"lint:doc:fix": "sh Taskfile remark_run --output", | ||
"test": "npm run tscheck && npm run eslint && npm run test:r", | ||
"test:r": "vitest run src/index.spec.ts", | ||
"test:w": "npm run test:r -- --watch", | ||
"eslint": "node node_modules/eslint/bin/eslint \"src/**/*.{ts,tsx}\"", | ||
"eslint:w": "watchexec -w src \"npm run eslint\"", | ||
"eslint:fix": "npm run eslint -- --fix", | ||
"tscheck": "tsc --noEmit", | ||
"tscheck:w": "npm run tscheck -- --watch", | ||
"format:src": "prettier src --write", | ||
"lint:commit": "sh Taskfile commit_lint", | ||
"commit": "cz", | ||
"semantic-release": "semantic-release", | ||
"build": "sh Taskfile build_tsup", | ||
"mocha": "node node_modules/mocha/bin/_mocha", | ||
"test:d": "ndb -r ts-node/register/transpile-only node_modules/mocha/bin/_mocha --no-timeouts --watch-files src/**/*.ts --watch src/**/*.spec.ts" | ||
"build": "sh Taskfile build_tsup" | ||
}, | ||
@@ -43,52 +35,33 @@ "dependencies": { | ||
"homepage": "https://github.com/unlight/prisma-query-log#readme", | ||
"ultra": { | ||
"concurrent": [ | ||
"lint", | ||
"test" | ||
] | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "node_modules/cz-customizable" | ||
} | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^12.1.1", | ||
"@commitlint/config-conventional": "^12.1.1", | ||
"@semantic-release/changelog": "^5.0.1", | ||
"@semantic-release/git": "^9.0.0", | ||
"@types/mocha": "^8.2.2", | ||
"@types/node": "^14.14.41", | ||
"@typescript-eslint/eslint-plugin": "^4.22.0", | ||
"@typescript-eslint/parser": "^4.22.0", | ||
"c8": "^7.7.1", | ||
"commitizen": "^4.2.3", | ||
"cz-customizable": "^6.3.0", | ||
"eslint": "^7.25.0", | ||
"@commitlint/cli": "^15.0.0", | ||
"@commitlint/config-conventional": "^15.0.0", | ||
"@prisma/client": "^3.7.0", | ||
"@semantic-release/changelog": "^6.0.1", | ||
"@semantic-release/git": "^10.0.1", | ||
"@types/node": "^17.0.2", | ||
"@typescript-eslint/eslint-plugin": "^5.8.0", | ||
"@typescript-eslint/parser": "^5.8.0", | ||
"commitizen": "^4.2.4", | ||
"conventional-changelog-conventionalcommits": "^4.6.1", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"eslint": "^8.5.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-import-resolver-node": "^0.3.4", | ||
"eslint-plugin-etc": "^1.4.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-only-warn": "^1.0.2", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"eslint-plugin-promise": "^5.1.0", | ||
"eslint-plugin-regexp": "^0.9.0", | ||
"eslint-plugin-simple-import-sort": "^7.0.0", | ||
"eslint-plugin-sonarjs": "^0.7.0", | ||
"eslint-plugin-sort-class-members": "^1.11.0", | ||
"eslint-plugin-total-functions": "^4.7.2", | ||
"eslint-plugin-unicorn": "^31.0.0", | ||
"eslint-plugin-wix-editor": "^3.3.0", | ||
"expect": "^26.6.2", | ||
"git-branch-is": "^4.0.0", | ||
"mocha": "^8.3.2", | ||
"eslint-plugin-etc": "^2.0.1", | ||
"eslint-plugin-only-warn": "^1.0.3", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eslint-plugin-unicorn": "^39.0.0", | ||
"expect": "^27.4.2", | ||
"precise-commits": "^1.0.2", | ||
"prettier": "^2.2.1", | ||
"semantic-release": "^17.4.2", | ||
"strip-ansi": "6", | ||
"ts-node": "^9.1.1", | ||
"tslib": "^2.2.0", | ||
"typescript": "^4.2.4", | ||
"prettier": "^2.5.1", | ||
"prisma": "^3.7.0", | ||
"semantic-release": "^18.0.1", | ||
"strip-ansi": "6.X", | ||
"ts-node": "^10.4.0", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.5.4", | ||
"vite": "^2.7.4", | ||
"vitest": "0.0.105", | ||
"watchexec-bin": "^1.0.0" | ||
} | ||
} |
# prisma-query-log | ||
Log prisma query event | ||
Log prisma query event. | ||
Currently works only for SQLite, MySQL. | ||
@@ -106,1 +107,8 @@ Features: | ||
![](docs/after.png) | ||
## Development | ||
```sh | ||
docker run -it -p 5432:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=user postgres | ||
docker run -it -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=query_log_example_db mysql | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29
160
114
10919