@prisma/sqlcommenter-query-insights 7.9.0-dev.3 → 7.9.0-dev.4
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.
- package/dist/index.js +2 -91
- package/dist/index.mjs +2 -91
- package/package.json +2 -2
- package/dist/parameterize/parameterize.d.ts +0 -19
package/dist/index.js
CHANGED
|
@@ -24,94 +24,6 @@ __export(index_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
26
|
|
|
27
|
-
// src/parameterize/parameterize.ts
|
|
28
|
-
var PARAM_PLACEHOLDER = { $type: "Param" };
|
|
29
|
-
var RELATION_OPERATION_KEYS = /* @__PURE__ */ new Set([
|
|
30
|
-
"connect",
|
|
31
|
-
"connectOrCreate",
|
|
32
|
-
"disconnect",
|
|
33
|
-
"set",
|
|
34
|
-
"create",
|
|
35
|
-
"createMany",
|
|
36
|
-
"update",
|
|
37
|
-
"updateMany",
|
|
38
|
-
"upsert",
|
|
39
|
-
"delete",
|
|
40
|
-
"deleteMany"
|
|
41
|
-
]);
|
|
42
|
-
var STRUCTURAL_KEYS_IN_DATA = /* @__PURE__ */ new Set([
|
|
43
|
-
"where",
|
|
44
|
-
"select",
|
|
45
|
-
"include",
|
|
46
|
-
"omit",
|
|
47
|
-
"_count",
|
|
48
|
-
"_sum",
|
|
49
|
-
"_avg",
|
|
50
|
-
"_min",
|
|
51
|
-
"_max"
|
|
52
|
-
]);
|
|
53
|
-
var STRUCTURAL_VALUE_KEYS = /* @__PURE__ */ new Set(["take", "skip", "sort", "nulls", "mode", "relationLoadStrategy", "distinct"]);
|
|
54
|
-
function isTaggedValue(value) {
|
|
55
|
-
return typeof value === "object" && value !== null && "$type" in value && typeof value.$type === "string";
|
|
56
|
-
}
|
|
57
|
-
function isSelectionMarker(key) {
|
|
58
|
-
return key === "$scalars" || key === "$composites";
|
|
59
|
-
}
|
|
60
|
-
function isSortDirection(value) {
|
|
61
|
-
return value === "asc" || value === "desc";
|
|
62
|
-
}
|
|
63
|
-
function getChildContext(key, parentContext) {
|
|
64
|
-
if (key === "arguments") return "default";
|
|
65
|
-
if (key === "selection") return "selection";
|
|
66
|
-
if (key === "orderBy") return "orderBy";
|
|
67
|
-
if (key === "data") return "data";
|
|
68
|
-
if (parentContext === "data") {
|
|
69
|
-
if (RELATION_OPERATION_KEYS.has(key) || STRUCTURAL_KEYS_IN_DATA.has(key)) {
|
|
70
|
-
return "default";
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return parentContext;
|
|
74
|
-
}
|
|
75
|
-
function parameterize(value, context, key) {
|
|
76
|
-
if (value === null || value === void 0) {
|
|
77
|
-
return value;
|
|
78
|
-
}
|
|
79
|
-
if (isTaggedValue(value)) {
|
|
80
|
-
return value.$type === "FieldRef" || value.$type === "Param" ? value : PARAM_PLACEHOLDER;
|
|
81
|
-
}
|
|
82
|
-
if (Array.isArray(value)) {
|
|
83
|
-
return value.map((item) => parameterize(item, context, key));
|
|
84
|
-
}
|
|
85
|
-
if (typeof value === "object") {
|
|
86
|
-
return parameterizeObject(value, context);
|
|
87
|
-
}
|
|
88
|
-
if (key && STRUCTURAL_VALUE_KEYS.has(key)) {
|
|
89
|
-
return value;
|
|
90
|
-
}
|
|
91
|
-
if (context === "selection" && typeof value === "boolean") {
|
|
92
|
-
return value;
|
|
93
|
-
}
|
|
94
|
-
if (context === "orderBy" && typeof value === "string" && isSortDirection(value)) {
|
|
95
|
-
return value;
|
|
96
|
-
}
|
|
97
|
-
return PARAM_PLACEHOLDER;
|
|
98
|
-
}
|
|
99
|
-
function parameterizeObject(obj, context) {
|
|
100
|
-
const result = {};
|
|
101
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
102
|
-
if (isSelectionMarker(key)) {
|
|
103
|
-
result[key] = value;
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
const childContext = getChildContext(key, context);
|
|
107
|
-
result[key] = parameterize(value, childContext, key);
|
|
108
|
-
}
|
|
109
|
-
return result;
|
|
110
|
-
}
|
|
111
|
-
function parameterizeQuery(query) {
|
|
112
|
-
return parameterize(query, "default");
|
|
113
|
-
}
|
|
114
|
-
|
|
115
27
|
// src/shape/shape.ts
|
|
116
28
|
function isObject(value) {
|
|
117
29
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -165,14 +77,13 @@ function formatQueryInsight(queryInfo) {
|
|
|
165
77
|
if (!modelName) {
|
|
166
78
|
return action;
|
|
167
79
|
}
|
|
168
|
-
const
|
|
169
|
-
const shapedQuery = shapeQuery(parameterizedQuery);
|
|
80
|
+
const shapedQuery = shapeQuery(query);
|
|
170
81
|
const encoded = toBase64Url(JSON.stringify(shapedQuery));
|
|
171
82
|
return `${modelName}.${action}:${encoded}`;
|
|
172
83
|
}
|
|
173
84
|
case "compacted": {
|
|
174
85
|
const { modelName, action, queries } = queryInfo;
|
|
175
|
-
const shapedQueries = queries.map((q) => shapeQuery(
|
|
86
|
+
const shapedQueries = queries.map((q) => shapeQuery(q));
|
|
176
87
|
const encoded = toBase64Url(JSON.stringify(shapedQueries));
|
|
177
88
|
return `${modelName}.${action}:${encoded}`;
|
|
178
89
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,91 +1,3 @@
|
|
|
1
|
-
// src/parameterize/parameterize.ts
|
|
2
|
-
var PARAM_PLACEHOLDER = { $type: "Param" };
|
|
3
|
-
var RELATION_OPERATION_KEYS = /* @__PURE__ */ new Set([
|
|
4
|
-
"connect",
|
|
5
|
-
"connectOrCreate",
|
|
6
|
-
"disconnect",
|
|
7
|
-
"set",
|
|
8
|
-
"create",
|
|
9
|
-
"createMany",
|
|
10
|
-
"update",
|
|
11
|
-
"updateMany",
|
|
12
|
-
"upsert",
|
|
13
|
-
"delete",
|
|
14
|
-
"deleteMany"
|
|
15
|
-
]);
|
|
16
|
-
var STRUCTURAL_KEYS_IN_DATA = /* @__PURE__ */ new Set([
|
|
17
|
-
"where",
|
|
18
|
-
"select",
|
|
19
|
-
"include",
|
|
20
|
-
"omit",
|
|
21
|
-
"_count",
|
|
22
|
-
"_sum",
|
|
23
|
-
"_avg",
|
|
24
|
-
"_min",
|
|
25
|
-
"_max"
|
|
26
|
-
]);
|
|
27
|
-
var STRUCTURAL_VALUE_KEYS = /* @__PURE__ */ new Set(["take", "skip", "sort", "nulls", "mode", "relationLoadStrategy", "distinct"]);
|
|
28
|
-
function isTaggedValue(value) {
|
|
29
|
-
return typeof value === "object" && value !== null && "$type" in value && typeof value.$type === "string";
|
|
30
|
-
}
|
|
31
|
-
function isSelectionMarker(key) {
|
|
32
|
-
return key === "$scalars" || key === "$composites";
|
|
33
|
-
}
|
|
34
|
-
function isSortDirection(value) {
|
|
35
|
-
return value === "asc" || value === "desc";
|
|
36
|
-
}
|
|
37
|
-
function getChildContext(key, parentContext) {
|
|
38
|
-
if (key === "arguments") return "default";
|
|
39
|
-
if (key === "selection") return "selection";
|
|
40
|
-
if (key === "orderBy") return "orderBy";
|
|
41
|
-
if (key === "data") return "data";
|
|
42
|
-
if (parentContext === "data") {
|
|
43
|
-
if (RELATION_OPERATION_KEYS.has(key) || STRUCTURAL_KEYS_IN_DATA.has(key)) {
|
|
44
|
-
return "default";
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return parentContext;
|
|
48
|
-
}
|
|
49
|
-
function parameterize(value, context, key) {
|
|
50
|
-
if (value === null || value === void 0) {
|
|
51
|
-
return value;
|
|
52
|
-
}
|
|
53
|
-
if (isTaggedValue(value)) {
|
|
54
|
-
return value.$type === "FieldRef" || value.$type === "Param" ? value : PARAM_PLACEHOLDER;
|
|
55
|
-
}
|
|
56
|
-
if (Array.isArray(value)) {
|
|
57
|
-
return value.map((item) => parameterize(item, context, key));
|
|
58
|
-
}
|
|
59
|
-
if (typeof value === "object") {
|
|
60
|
-
return parameterizeObject(value, context);
|
|
61
|
-
}
|
|
62
|
-
if (key && STRUCTURAL_VALUE_KEYS.has(key)) {
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
if (context === "selection" && typeof value === "boolean") {
|
|
66
|
-
return value;
|
|
67
|
-
}
|
|
68
|
-
if (context === "orderBy" && typeof value === "string" && isSortDirection(value)) {
|
|
69
|
-
return value;
|
|
70
|
-
}
|
|
71
|
-
return PARAM_PLACEHOLDER;
|
|
72
|
-
}
|
|
73
|
-
function parameterizeObject(obj, context) {
|
|
74
|
-
const result = {};
|
|
75
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
76
|
-
if (isSelectionMarker(key)) {
|
|
77
|
-
result[key] = value;
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
const childContext = getChildContext(key, context);
|
|
81
|
-
result[key] = parameterize(value, childContext, key);
|
|
82
|
-
}
|
|
83
|
-
return result;
|
|
84
|
-
}
|
|
85
|
-
function parameterizeQuery(query) {
|
|
86
|
-
return parameterize(query, "default");
|
|
87
|
-
}
|
|
88
|
-
|
|
89
1
|
// src/shape/shape.ts
|
|
90
2
|
function isObject(value) {
|
|
91
3
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -139,14 +51,13 @@ function formatQueryInsight(queryInfo) {
|
|
|
139
51
|
if (!modelName) {
|
|
140
52
|
return action;
|
|
141
53
|
}
|
|
142
|
-
const
|
|
143
|
-
const shapedQuery = shapeQuery(parameterizedQuery);
|
|
54
|
+
const shapedQuery = shapeQuery(query);
|
|
144
55
|
const encoded = toBase64Url(JSON.stringify(shapedQuery));
|
|
145
56
|
return `${modelName}.${action}:${encoded}`;
|
|
146
57
|
}
|
|
147
58
|
case "compacted": {
|
|
148
59
|
const { modelName, action, queries } = queryInfo;
|
|
149
|
-
const shapedQueries = queries.map((q) => shapeQuery(
|
|
60
|
+
const shapedQueries = queries.map((q) => shapeQuery(q));
|
|
150
61
|
const encoded = toBase64Url(JSON.stringify(shapedQueries));
|
|
151
62
|
return `${modelName}.${action}:${encoded}`;
|
|
152
63
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/sqlcommenter-query-insights",
|
|
3
|
-
"version": "7.9.0-dev.
|
|
3
|
+
"version": "7.9.0-dev.4",
|
|
4
4
|
"description": "Query insights plugin for Prisma SQL commenter",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"sideEffects": false,
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"fast-check": "4.3.0",
|
|
34
|
-
"@prisma/sqlcommenter": "7.9.0-dev.
|
|
34
|
+
"@prisma/sqlcommenter": "7.9.0-dev.4"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"dev": "DEV=true tsx helpers/build.ts",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Query parameterization logic for Prisma query insights.
|
|
3
|
-
*
|
|
4
|
-
* This module handles the conversion of Prisma queries into parameterized shapes
|
|
5
|
-
* where user data values are replaced with placeholder markers.
|
|
6
|
-
*
|
|
7
|
-
* Design principle: when in doubt, parameterize. We're building query shapes
|
|
8
|
-
* for observability, not actual query parameterization for the query compiler.
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Placeholder object used to replace parameterized values in query shapes.
|
|
12
|
-
*/
|
|
13
|
-
export declare const PARAM_PLACEHOLDER: {
|
|
14
|
-
$type: string;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Parameterizes a query object, replacing all user data values with placeholders.
|
|
18
|
-
*/
|
|
19
|
-
export declare function parameterizeQuery(query: unknown): unknown;
|