@prisma-next/eslint-plugin 0.3.0-dev.6 → 0.3.0-dev.64
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/LICENSE +201 -0
- package/dist/index.d.mts +26 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +199 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +26 -21
- package/dist/index.d.ts +0 -15
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -219
- package/dist/index.js.map +0 -1
- package/dist/rules/lint-build-call.d.ts +0 -12
- package/dist/rules/lint-build-call.d.ts.map +0 -1
- package/dist/utils.d.ts +0 -45
- package/dist/utils.d.ts.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2026] [Prisma Data, Inc]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
|
|
3
|
+
//#region src/rules/lint-build-call.d.ts
|
|
4
|
+
type MessageIds = 'unboundedQuery' | 'maxLimitExceeded';
|
|
5
|
+
interface RuleOptions {
|
|
6
|
+
/** Enforce limit() calls on SELECT queries to prevent unbounded queries */
|
|
7
|
+
requireLimit?: boolean;
|
|
8
|
+
/** Maximum allowed limit value */
|
|
9
|
+
maxLimit?: number;
|
|
10
|
+
}
|
|
11
|
+
type Options = [RuleOptions];
|
|
12
|
+
declare const lintBuildCall: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/index.d.ts
|
|
15
|
+
interface ESLintPlugin {
|
|
16
|
+
meta: {
|
|
17
|
+
name: string;
|
|
18
|
+
version: string;
|
|
19
|
+
};
|
|
20
|
+
rules: Record<string, any>;
|
|
21
|
+
configs: Record<string, any>;
|
|
22
|
+
}
|
|
23
|
+
declare const plugin: ESLintPlugin;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { type ESLintPlugin, plugin as default, plugin, lintBuildCall };
|
|
26
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/rules/lint-build-call.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;KAkBK,UAAA;UAEK,WAAA;EAFL;EAEK,YAAA,CAAA,EAAW,OAAA;EAOhB;EAGQ,QAAA,CAAA,EAAA,MAsGX;;KAzGG,OAAA,GAGqB,CAHV,WAGU,CAAA;AAAA,cAAb,aAAa,EAAA,WAAA,CAAA,UAAA,CAAA,UAAA,EAAA,OAAA,EAAA,OAAA,EAAA,WAAA,CAAA,YAAA,CAAA;;;UCVhB,YAAA;;IDFL,IAAA,EAAA,MAAU;IAEL,OAAA,EAAA,MAAW;EAOhB,CAAA;EAGQ,KAAA,ECJJ,MDII,CAAA,MAsGX,EAAA,GAAA,CAAA;EAtGwB,OAAA,ECFf,MDEe,CAAA,MAAA,EAAA,GAAA,CAAA;;cCEpB,MDFoB,ECEZ,YDFY"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
|
|
3
|
+
//#region package.json
|
|
4
|
+
var name = "@prisma-next/eslint-plugin";
|
|
5
|
+
var version = "0.3.0-dev.64";
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/utils.ts
|
|
9
|
+
const PRISMA_NEXT_SQL_PACKAGES = ["@prisma-next/sql-lane", "packages/2-sql/4-lanes/sql-lane"];
|
|
10
|
+
const PLAN_TYPE_PATTERNS = [/^SqlQueryPlan$/];
|
|
11
|
+
/**
|
|
12
|
+
* Get TypeScript services from ESLint context
|
|
13
|
+
*/
|
|
14
|
+
function getTypeScriptServices(context) {
|
|
15
|
+
try {
|
|
16
|
+
const parserServices = ESLintUtils.getParserServices(context, false);
|
|
17
|
+
if (!parserServices?.program) return null;
|
|
18
|
+
return {
|
|
19
|
+
program: parserServices.program,
|
|
20
|
+
checker: parserServices.program.getTypeChecker(),
|
|
21
|
+
esTreeNodeToTSNodeMap: parserServices.esTreeNodeToTSNodeMap,
|
|
22
|
+
tsNodeToESTreeNodeMap: parserServices.tsNodeToESTreeNodeMap
|
|
23
|
+
};
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if a call expression is a method call with a specific name
|
|
30
|
+
*/
|
|
31
|
+
function isMethodCall(node, methodName) {
|
|
32
|
+
return node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier" && node.callee.property.name === methodName;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Check if a call expression is a query builder build() call
|
|
36
|
+
* Uses type information to verify it's actually our query builder's build method
|
|
37
|
+
*/
|
|
38
|
+
function isPrismaNextQueryBuildCall(node, services) {
|
|
39
|
+
if (!isMethodCall(node, "build") || node.arguments.length > 1 || !services) return false;
|
|
40
|
+
if (node.callee.type !== "MemberExpression") return false;
|
|
41
|
+
const objectType = getTypeOfNode(node.callee.object, services);
|
|
42
|
+
if (!objectType) return false;
|
|
43
|
+
if (!isTypeFromPackages(objectType, PRISMA_NEXT_SQL_PACKAGES)) return false;
|
|
44
|
+
const returnType = getTypeOfNode(node, services);
|
|
45
|
+
return returnType ? isPrismaNextQueryPlanType(returnType) : false;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get the TypeScript type of an ESTree node
|
|
49
|
+
*/
|
|
50
|
+
function getTypeOfNode(node, services) {
|
|
51
|
+
try {
|
|
52
|
+
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
53
|
+
return tsNode ? services.checker.getTypeAtLocation(tsNode) : null;
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Check if type is a Prisma Next query plan type by name and origin
|
|
60
|
+
*/
|
|
61
|
+
function isPrismaNextQueryPlanType(type) {
|
|
62
|
+
return PLAN_TYPE_PATTERNS.some((pattern) => pattern.test(type.symbol.name));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Extract call chain from a call expression
|
|
66
|
+
* Returns array of method names called in sequence
|
|
67
|
+
*/
|
|
68
|
+
function extractCallChain(node) {
|
|
69
|
+
const chain = [];
|
|
70
|
+
function traverse(current) {
|
|
71
|
+
switch (current.type) {
|
|
72
|
+
case "CallExpression":
|
|
73
|
+
if (current.callee.type === "MemberExpression") {
|
|
74
|
+
traverse(current.callee.object);
|
|
75
|
+
if (current.callee.property.type === "Identifier") chain.push({
|
|
76
|
+
method: current.callee.property.name,
|
|
77
|
+
args: current.arguments
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
break;
|
|
81
|
+
case "MemberExpression":
|
|
82
|
+
traverse(current.object);
|
|
83
|
+
break;
|
|
84
|
+
case "Identifier": break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
traverse(node);
|
|
88
|
+
return chain;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Helper to check if a type originates from specific packages
|
|
92
|
+
*/
|
|
93
|
+
function isTypeFromPackages(type, packages) {
|
|
94
|
+
const fileName = type.getSymbol()?.valueDeclaration?.getSourceFile().fileName;
|
|
95
|
+
return fileName ? packages.some((pkg) => fileName.includes(`${pkg}/`)) : false;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/rules/lint-build-call.ts
|
|
100
|
+
const DEFAULT_OPTIONS = {
|
|
101
|
+
requireLimit: true,
|
|
102
|
+
maxLimit: 1e3,
|
|
103
|
+
requiredFields: []
|
|
104
|
+
};
|
|
105
|
+
const SELECT_QUERY_METHODS = ["select", "from"];
|
|
106
|
+
const lintBuildCall = ESLintUtils.RuleCreator.withoutDocs({
|
|
107
|
+
meta: {
|
|
108
|
+
type: "problem",
|
|
109
|
+
docs: { description: "Validate query builder build() calls using TypeScript type information" },
|
|
110
|
+
schema: [{
|
|
111
|
+
type: "object",
|
|
112
|
+
properties: {
|
|
113
|
+
requireLimit: {
|
|
114
|
+
type: "boolean",
|
|
115
|
+
description: "Enforce limit() calls on SELECT queries"
|
|
116
|
+
},
|
|
117
|
+
maxLimit: {
|
|
118
|
+
type: "number",
|
|
119
|
+
description: "Maximum allowed limit value",
|
|
120
|
+
minimum: 1
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
additionalProperties: false
|
|
124
|
+
}],
|
|
125
|
+
messages: {
|
|
126
|
+
unboundedQuery: "Query build() call may result in unbounded query. Consider adding .limit() to prevent fetching too many rows.",
|
|
127
|
+
maxLimitExceeded: "Query build() call has a limit() value that exceeds the maximum allowed of {{maxLimit}}."
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
defaultOptions: [DEFAULT_OPTIONS],
|
|
131
|
+
create(context, [options]) {
|
|
132
|
+
const services = getTypeScriptServices(context);
|
|
133
|
+
if (!services) throw new Error("TypeScript services are required for lint-build-call rule. Please ensure you are using @typescript-eslint/parser.");
|
|
134
|
+
return { CallExpression(node) {
|
|
135
|
+
if (!isPrismaNextQueryBuildCall(node, services)) return;
|
|
136
|
+
lintQuery(node, extractCallChain(node));
|
|
137
|
+
} };
|
|
138
|
+
function lintQuery(node, callChain) {
|
|
139
|
+
if (isSelectQuery(callChain)) {
|
|
140
|
+
checkUnboundedQuery(node, callChain);
|
|
141
|
+
checkLimitExceedsMax(node, callChain);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function isSelectQuery(callChain) {
|
|
145
|
+
return SELECT_QUERY_METHODS.some((method) => callChain.some((call) => call.method === method));
|
|
146
|
+
}
|
|
147
|
+
function checkUnboundedQuery(node, callChain) {
|
|
148
|
+
if (options.requireLimit && !callChain.some((call) => call.method === "limit")) reportUnboundedQuery(node);
|
|
149
|
+
}
|
|
150
|
+
function checkLimitExceedsMax(node, callChain) {
|
|
151
|
+
if (!options.maxLimit) return;
|
|
152
|
+
const limitArg = callChain.find((call) => call.method === "limit")?.args.pop();
|
|
153
|
+
const literalValue = limitArg ? extractNumericLiteral(limitArg) : void 0;
|
|
154
|
+
if (literalValue !== void 0 && literalValue > options.maxLimit) reportLimitExceeded(node);
|
|
155
|
+
}
|
|
156
|
+
function extractNumericLiteral(arg) {
|
|
157
|
+
if (arg?.type === "Literal" && "value" in arg && typeof arg.value === "number") return arg.value;
|
|
158
|
+
}
|
|
159
|
+
function reportUnboundedQuery(node) {
|
|
160
|
+
context.report({
|
|
161
|
+
node,
|
|
162
|
+
messageId: "unboundedQuery"
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
function reportLimitExceeded(node) {
|
|
166
|
+
context.report({
|
|
167
|
+
node,
|
|
168
|
+
messageId: "maxLimitExceeded",
|
|
169
|
+
data: { maxLimit: options.maxLimit?.toString() ?? "undefined" }
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/index.ts
|
|
177
|
+
const PLUGIN_META = {
|
|
178
|
+
name,
|
|
179
|
+
version
|
|
180
|
+
};
|
|
181
|
+
const RULES = { "lint-build-call": lintBuildCall };
|
|
182
|
+
const RULE_CONFIG = { "@prisma-next/lint-build-call": "error" };
|
|
183
|
+
const plugin = {
|
|
184
|
+
meta: PLUGIN_META,
|
|
185
|
+
rules: RULES,
|
|
186
|
+
configs: { recommended: {
|
|
187
|
+
plugins: ["@prisma-next"],
|
|
188
|
+
rules: RULE_CONFIG
|
|
189
|
+
} }
|
|
190
|
+
};
|
|
191
|
+
plugin.configs["flat/recommended"] = {
|
|
192
|
+
plugins: { "@prisma-next": plugin },
|
|
193
|
+
rules: RULE_CONFIG
|
|
194
|
+
};
|
|
195
|
+
var src_default = plugin;
|
|
196
|
+
|
|
197
|
+
//#endregion
|
|
198
|
+
export { src_default as default, lintBuildCall, plugin };
|
|
199
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["chain: BuilderCall[]","plugin: ESLintPlugin"],"sources":["../package.json","../src/utils.ts","../src/rules/lint-build-call.ts","../src/index.ts"],"sourcesContent":["","import type { TSESTree } from '@typescript-eslint/types';\nimport type { ParserServices } from '@typescript-eslint/utils';\nimport { ESLintUtils } from '@typescript-eslint/utils';\nimport type * as ts from 'typescript';\n\nconst PRISMA_NEXT_SQL_PACKAGES = [\n '@prisma-next/sql-lane',\n 'packages/2-sql/4-lanes/sql-lane',\n] as const;\n\nconst PLAN_TYPE_PATTERNS = [/^SqlQueryPlan$/] as const;\n\nexport type BuilderCall = { method: string; args: TSESTree.CallExpressionArgument[] };\n\n// Types\nexport interface TypeScriptServices {\n program: ts.Program;\n checker: ts.TypeChecker;\n esTreeNodeToTSNodeMap: ParserServices['esTreeNodeToTSNodeMap'];\n tsNodeToESTreeNodeMap: ParserServices['tsNodeToESTreeNodeMap'];\n}\n\n/**\n * Get TypeScript services from ESLint context\n */\nexport function getTypeScriptServices(\n context: Parameters<typeof ESLintUtils.getParserServices>[0],\n): TypeScriptServices | null {\n try {\n const parserServices = ESLintUtils.getParserServices(context, false);\n\n if (!parserServices?.program) {\n return null;\n }\n\n return {\n program: parserServices.program,\n checker: parserServices.program.getTypeChecker(),\n esTreeNodeToTSNodeMap: parserServices.esTreeNodeToTSNodeMap,\n tsNodeToESTreeNodeMap: parserServices.tsNodeToESTreeNodeMap,\n };\n } catch {\n return null;\n }\n}\n\n/**\n * Check if a call expression is a method call with a specific name\n */\nexport function isMethodCall(node: TSESTree.CallExpression, methodName: string): boolean {\n return (\n node.callee.type === 'MemberExpression' &&\n node.callee.property.type === 'Identifier' &&\n node.callee.property.name === methodName\n );\n}\n\n/**\n * Check if a call expression is a query builder build() call\n * Uses type information to verify it's actually our query builder's build method\n */\nexport function isPrismaNextQueryBuildCall(\n node: TSESTree.CallExpression,\n services?: TypeScriptServices | null,\n): boolean {\n if (!isMethodCall(node, 'build') || node.arguments.length > 1 || !services) {\n return false;\n }\n\n if (node.callee.type !== 'MemberExpression') {\n return false;\n }\n\n const objectType = getTypeOfNode(node.callee.object, services);\n if (!objectType) {\n return false;\n }\n\n if (!isTypeFromPackages(objectType, PRISMA_NEXT_SQL_PACKAGES)) {\n return false;\n }\n\n const returnType = getTypeOfNode(node, services);\n return returnType ? isPrismaNextQueryPlanType(returnType) : false;\n}\n\n/**\n * Get the TypeScript type of an ESTree node\n */\nexport function getTypeOfNode(node: TSESTree.Node, services: TypeScriptServices): ts.Type | null {\n try {\n const tsNode = services.esTreeNodeToTSNodeMap.get(node);\n return tsNode ? services.checker.getTypeAtLocation(tsNode) : null;\n } catch {\n return null;\n }\n}\n\n/**\n * Check if a type has a specific property\n */\nexport function typeHasProperty(\n type: ts.Type,\n propertyName: string,\n checker: ts.TypeChecker,\n): boolean {\n try {\n const properties = checker.getPropertiesOfType(type);\n return properties.some((prop) => prop.getName() === propertyName);\n } catch {\n return false;\n }\n}\n\n/**\n * Check if type is a Prisma Next query plan type by name and origin\n */\nexport function isPrismaNextQueryPlanType(type: ts.Type): boolean {\n return PLAN_TYPE_PATTERNS.some((pattern) => pattern.test(type.symbol.name));\n}\n\n/**\n * Extract call chain from a call expression\n * Returns array of method names called in sequence\n */\nexport function extractCallChain(node: TSESTree.CallExpression): BuilderCall[] {\n const chain: BuilderCall[] = [];\n\n function traverse(current: TSESTree.Node): void {\n switch (current.type) {\n case 'CallExpression':\n if (current.callee.type === 'MemberExpression') {\n traverse(current.callee.object);\n if (current.callee.property.type === 'Identifier') {\n chain.push({ method: current.callee.property.name, args: current.arguments });\n }\n }\n break;\n\n case 'MemberExpression':\n traverse(current.object);\n break;\n\n case 'Identifier':\n break;\n }\n }\n\n traverse(node);\n return chain;\n}\n\n/**\n * Helper to check if a type originates from specific packages\n */\nfunction isTypeFromPackages(type: ts.Type, packages: readonly string[]): boolean {\n const fileName = type.getSymbol()?.valueDeclaration?.getSourceFile().fileName;\n return fileName ? packages.some((pkg) => fileName.includes(`${pkg}/`)) : false;\n}\n","import type { TSESTree } from '@typescript-eslint/types';\nimport { ESLintUtils } from '@typescript-eslint/utils';\nimport {\n type BuilderCall,\n extractCallChain,\n getTypeScriptServices,\n isPrismaNextQueryBuildCall,\n} from '../utils';\n\nconst DEFAULT_OPTIONS = {\n requireLimit: true,\n maxLimit: 1000,\n requiredFields: [],\n};\n\nconst SELECT_QUERY_METHODS = ['select', 'from'] as const;\n\n// Types\ntype MessageIds = 'unboundedQuery' | 'maxLimitExceeded';\n\ninterface RuleOptions {\n /** Enforce limit() calls on SELECT queries to prevent unbounded queries */\n requireLimit?: boolean;\n /** Maximum allowed limit value */\n maxLimit?: number;\n}\n\ntype Options = [RuleOptions];\n\n// Rule implementation\nexport const lintBuildCall = ESLintUtils.RuleCreator.withoutDocs<Options, MessageIds>({\n meta: {\n type: 'problem',\n docs: {\n description: 'Validate query builder build() calls using TypeScript type information',\n },\n schema: [\n {\n type: 'object',\n properties: {\n requireLimit: {\n type: 'boolean',\n description: 'Enforce limit() calls on SELECT queries',\n },\n maxLimit: {\n type: 'number',\n description: 'Maximum allowed limit value',\n minimum: 1,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n unboundedQuery:\n 'Query build() call may result in unbounded query. Consider adding .limit() to prevent fetching too many rows.',\n maxLimitExceeded:\n 'Query build() call has a limit() value that exceeds the maximum allowed of {{maxLimit}}.',\n },\n },\n defaultOptions: [DEFAULT_OPTIONS],\n create(context, [options]) {\n const services = getTypeScriptServices(context);\n\n if (!services) {\n throw new Error(\n 'TypeScript services are required for lint-build-call rule. Please ensure you are using @typescript-eslint/parser.',\n );\n }\n\n return {\n CallExpression(node: TSESTree.CallExpression) {\n if (!isPrismaNextQueryBuildCall(node, services)) {\n return;\n }\n lintQuery(node, extractCallChain(node));\n },\n };\n\n function lintQuery(node: TSESTree.CallExpression, callChain: BuilderCall[]) {\n if (isSelectQuery(callChain)) {\n checkUnboundedQuery(node, callChain);\n checkLimitExceedsMax(node, callChain);\n }\n }\n\n function isSelectQuery(callChain: BuilderCall[]): boolean {\n return SELECT_QUERY_METHODS.some((method) =>\n callChain.some((call) => call.method === method),\n );\n }\n\n function checkUnboundedQuery(node: TSESTree.CallExpression, callChain: BuilderCall[]) {\n if (options.requireLimit && !callChain.some((call) => call.method === 'limit')) {\n reportUnboundedQuery(node);\n }\n }\n\n function checkLimitExceedsMax(node: TSESTree.CallExpression, callChain: BuilderCall[]) {\n if (!options.maxLimit) return;\n\n const limitArg = callChain.find((call) => call.method === 'limit')?.args.pop();\n const literalValue = limitArg ? extractNumericLiteral(limitArg) : undefined;\n if (literalValue !== undefined && literalValue > options.maxLimit) {\n reportLimitExceeded(node);\n }\n }\n\n function extractNumericLiteral(\n arg: TSESTree.Expression | TSESTree.SpreadElement,\n ): number | undefined {\n if (arg?.type === 'Literal' && 'value' in arg && typeof arg.value === 'number') {\n return arg.value;\n }\n return;\n }\n\n function reportUnboundedQuery(node: TSESTree.CallExpression) {\n context.report({\n node,\n messageId: 'unboundedQuery',\n });\n }\n\n function reportLimitExceeded(node: TSESTree.CallExpression) {\n context.report({\n node,\n messageId: 'maxLimitExceeded',\n data: { maxLimit: options.maxLimit?.toString() ?? 'undefined' },\n });\n }\n },\n});\n","import { name, version } from '../package.json';\nimport { lintBuildCall } from './rules/lint-build-call';\n\n// Plugin metadata\nconst PLUGIN_META = {\n name,\n version,\n};\n\n// Rule definitions\nconst RULES = {\n 'lint-build-call': lintBuildCall,\n};\n\n// Configuration presets\nconst RULE_CONFIG = {\n '@prisma-next/lint-build-call': 'error',\n};\n\n// Plugin interface\ninterface ESLintPlugin {\n meta: {\n name: string;\n version: string;\n };\n // biome-ignore lint/suspicious/noExplicitAny: Required for ESLint plugin interface compatibility\n rules: Record<string, any>;\n // biome-ignore lint/suspicious/noExplicitAny: Required for ESLint plugin interface compatibility\n configs: Record<string, any>;\n}\n\n// Plugin implementation\nconst plugin: ESLintPlugin = {\n meta: PLUGIN_META,\n rules: RULES,\n configs: {\n recommended: {\n plugins: ['@prisma-next'],\n rules: RULE_CONFIG,\n },\n },\n};\n\n// Add flat config after plugin is defined to avoid circular reference\nplugin.configs['flat/recommended'] = {\n plugins: {\n '@prisma-next': plugin,\n },\n rules: RULE_CONFIG,\n};\n\n// Exports\nexport default plugin;\nexport { lintBuildCall };\nexport { plugin };\nexport type { ESLintPlugin };\n"],"mappings":";;;;;;;;ACKA,MAAM,2BAA2B,CAC/B,yBACA,kCACD;AAED,MAAM,qBAAqB,CAAC,iBAAiB;;;;AAe7C,SAAgB,sBACd,SAC2B;AAC3B,KAAI;EACF,MAAM,iBAAiB,YAAY,kBAAkB,SAAS,MAAM;AAEpE,MAAI,CAAC,gBAAgB,QACnB,QAAO;AAGT,SAAO;GACL,SAAS,eAAe;GACxB,SAAS,eAAe,QAAQ,gBAAgB;GAChD,uBAAuB,eAAe;GACtC,uBAAuB,eAAe;GACvC;SACK;AACN,SAAO;;;;;;AAOX,SAAgB,aAAa,MAA+B,YAA6B;AACvF,QACE,KAAK,OAAO,SAAS,sBACrB,KAAK,OAAO,SAAS,SAAS,gBAC9B,KAAK,OAAO,SAAS,SAAS;;;;;;AAQlC,SAAgB,2BACd,MACA,UACS;AACT,KAAI,CAAC,aAAa,MAAM,QAAQ,IAAI,KAAK,UAAU,SAAS,KAAK,CAAC,SAChE,QAAO;AAGT,KAAI,KAAK,OAAO,SAAS,mBACvB,QAAO;CAGT,MAAM,aAAa,cAAc,KAAK,OAAO,QAAQ,SAAS;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CAAC;;EAGJ,SAAS,oBAAoB,MAA+B;AAC1D,WAAQ,OAAO;IACb;IACA,WAAW;IACX,MAAM,EAAE,UAAU,QAAQ,UAAU,UAAU,IAAI,aAAa;IAChE,CAAC;;;CAGP,CAAC;;;;AChIF,MAAM,cAAc;CAClB;CACA;CACD;AAGD,MAAM,QAAQ,EACZ,mBAAmB,eACpB;AAGD,MAAM,cAAc,EAClB,gCAAgC,SACjC;AAeD,MAAMC,SAAuB;CAC3B,MAAM;CACN,OAAO;CACP,SAAS,EACP,aAAa;EACX,SAAS,CAAC,eAAe;EACzB,OAAO;EACR,EACF;CACF;AAGD,OAAO,QAAQ,sBAAsB;CACnC,SAAS,EACP,gBAAgB,QACjB;CACD,OAAO;CACR;AAGD,kBAAe"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/eslint-plugin",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.64",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "ESLint plugin for Prisma Next query builder type checking and linting",
|
|
@@ -15,46 +15,51 @@
|
|
|
15
15
|
"dist",
|
|
16
16
|
"src"
|
|
17
17
|
],
|
|
18
|
-
"main": "./dist/index.
|
|
19
|
-
"types": "./dist/index.d.
|
|
18
|
+
"main": "./dist/index.mjs",
|
|
19
|
+
"types": "./dist/index.d.mts",
|
|
20
20
|
"exports": {
|
|
21
|
-
".":
|
|
22
|
-
|
|
23
|
-
"import": "./dist/index.js"
|
|
24
|
-
}
|
|
21
|
+
".": "./dist/index.mjs",
|
|
22
|
+
"./package.json": "./package.json"
|
|
25
23
|
},
|
|
26
24
|
"dependencies": {
|
|
27
25
|
"@typescript-eslint/types": "^8.0.0",
|
|
28
26
|
"@typescript-eslint/utils": "^8.0.0"
|
|
29
27
|
},
|
|
30
28
|
"devDependencies": {
|
|
31
|
-
"@typescript-eslint/parser": "^8.0.0",
|
|
32
29
|
"@types/eslint": "^9.0.0",
|
|
33
30
|
"@types/node": "24.10.4",
|
|
34
|
-
"@
|
|
31
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
35
32
|
"eslint": "^9.0.0",
|
|
36
|
-
"
|
|
33
|
+
"tsdown": "0.18.4",
|
|
37
34
|
"typescript": "5.9.3",
|
|
38
|
-
"vitest": "4.0.
|
|
39
|
-
"@prisma-next/sql-contract": "0.3.0-dev.
|
|
40
|
-
"@prisma-next/sql-contract-ts": "0.3.0-dev.
|
|
41
|
-
"@prisma-next/sql-
|
|
42
|
-
"@prisma-next/sql-
|
|
43
|
-
"@prisma-next/sql-
|
|
35
|
+
"vitest": "4.0.17",
|
|
36
|
+
"@prisma-next/sql-contract": "0.3.0-dev.64",
|
|
37
|
+
"@prisma-next/sql-contract-ts": "0.3.0-dev.64",
|
|
38
|
+
"@prisma-next/sql-relational-core": "0.3.0-dev.64",
|
|
39
|
+
"@prisma-next/sql-runtime": "0.3.0-dev.64",
|
|
40
|
+
"@prisma-next/sql-lane": "0.3.0-dev.64",
|
|
41
|
+
"@prisma-next/tsconfig": "0.0.0",
|
|
42
|
+
"@prisma-next/tsdown": "0.0.0"
|
|
44
43
|
},
|
|
45
44
|
"peerDependencies": {
|
|
46
45
|
"@typescript-eslint/parser": "^8.0.0",
|
|
47
46
|
"eslint": "^9.0.0",
|
|
48
47
|
"typescript": "*"
|
|
49
48
|
},
|
|
49
|
+
"module": "./dist/index.mjs",
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "https://github.com/prisma/prisma-next.git",
|
|
53
|
+
"directory": "packages/1-framework/3-tooling/eslint-plugin"
|
|
54
|
+
},
|
|
50
55
|
"scripts": {
|
|
51
|
-
"build": "
|
|
56
|
+
"build": "tsdown",
|
|
52
57
|
"test": "vitest run",
|
|
53
58
|
"test:coverage": "vitest run --coverage",
|
|
54
59
|
"typecheck": "tsc --noEmit",
|
|
55
|
-
"lint": "biome check . --
|
|
56
|
-
"lint:fix": "biome check --write .
|
|
57
|
-
"lint:fix:unsafe": "biome check --write --unsafe .
|
|
58
|
-
"clean": "
|
|
60
|
+
"lint": "biome check . --error-on-warnings",
|
|
61
|
+
"lint:fix": "biome check --write .",
|
|
62
|
+
"lint:fix:unsafe": "biome check --write --unsafe .",
|
|
63
|
+
"clean": "rm -rf dist dist-tsc dist-tsc-prod coverage .tmp-output"
|
|
59
64
|
}
|
|
60
65
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { lintBuildCall } from './rules/lint-build-call';
|
|
2
|
-
interface ESLintPlugin {
|
|
3
|
-
meta: {
|
|
4
|
-
name: string;
|
|
5
|
-
version: string;
|
|
6
|
-
};
|
|
7
|
-
rules: Record<string, any>;
|
|
8
|
-
configs: Record<string, any>;
|
|
9
|
-
}
|
|
10
|
-
declare const plugin: ESLintPlugin;
|
|
11
|
-
export default plugin;
|
|
12
|
-
export { lintBuildCall };
|
|
13
|
-
export { plugin };
|
|
14
|
-
export type { ESLintPlugin };
|
|
15
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAmBxD,UAAU,YAAY;IACpB,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IAEF,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B;AAGD,QAAA,MAAM,MAAM,EAAE,YASb,CAAC;AAWF,eAAe,MAAM,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,YAAY,EAAE,YAAY,EAAE,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
// package.json
|
|
2
|
-
var name = "@prisma-next/eslint-plugin";
|
|
3
|
-
var version = "0.3.0-dev.6";
|
|
4
|
-
|
|
5
|
-
// src/rules/lint-build-call.ts
|
|
6
|
-
import { ESLintUtils as ESLintUtils2 } from "@typescript-eslint/utils";
|
|
7
|
-
|
|
8
|
-
// src/utils.ts
|
|
9
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
10
|
-
var PRISMA_NEXT_SQL_PACKAGES = [
|
|
11
|
-
"@prisma-next/sql-lane",
|
|
12
|
-
"packages/2-sql/4-lanes/sql-lane"
|
|
13
|
-
];
|
|
14
|
-
var PLAN_TYPE_PATTERNS = [/^SqlQueryPlan$/];
|
|
15
|
-
function getTypeScriptServices(context) {
|
|
16
|
-
try {
|
|
17
|
-
const parserServices = ESLintUtils.getParserServices(context, false);
|
|
18
|
-
if (!parserServices?.program) {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
program: parserServices.program,
|
|
23
|
-
checker: parserServices.program.getTypeChecker(),
|
|
24
|
-
esTreeNodeToTSNodeMap: parserServices.esTreeNodeToTSNodeMap,
|
|
25
|
-
tsNodeToESTreeNodeMap: parserServices.tsNodeToESTreeNodeMap
|
|
26
|
-
};
|
|
27
|
-
} catch {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function isMethodCall(node, methodName) {
|
|
32
|
-
return node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier" && node.callee.property.name === methodName;
|
|
33
|
-
}
|
|
34
|
-
function isPrismaNextQueryBuildCall(node, services) {
|
|
35
|
-
if (!isMethodCall(node, "build") || node.arguments.length > 1 || !services) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
if (node.callee.type !== "MemberExpression") {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
const objectType = getTypeOfNode(node.callee.object, services);
|
|
42
|
-
if (!objectType) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
if (!isTypeFromPackages(objectType, PRISMA_NEXT_SQL_PACKAGES)) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
const returnType = getTypeOfNode(node, services);
|
|
49
|
-
return returnType ? isPrismaNextQueryPlanType(returnType) : false;
|
|
50
|
-
}
|
|
51
|
-
function getTypeOfNode(node, services) {
|
|
52
|
-
try {
|
|
53
|
-
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
54
|
-
return tsNode ? services.checker.getTypeAtLocation(tsNode) : null;
|
|
55
|
-
} catch {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function isPrismaNextQueryPlanType(type) {
|
|
60
|
-
return PLAN_TYPE_PATTERNS.some((pattern) => pattern.test(type.symbol.name));
|
|
61
|
-
}
|
|
62
|
-
function extractCallChain(node) {
|
|
63
|
-
const chain = [];
|
|
64
|
-
function traverse(current) {
|
|
65
|
-
switch (current.type) {
|
|
66
|
-
case "CallExpression":
|
|
67
|
-
if (current.callee.type === "MemberExpression") {
|
|
68
|
-
traverse(current.callee.object);
|
|
69
|
-
if (current.callee.property.type === "Identifier") {
|
|
70
|
-
chain.push({ method: current.callee.property.name, args: current.arguments });
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
break;
|
|
74
|
-
case "MemberExpression":
|
|
75
|
-
traverse(current.object);
|
|
76
|
-
break;
|
|
77
|
-
case "Identifier":
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
traverse(node);
|
|
82
|
-
return chain;
|
|
83
|
-
}
|
|
84
|
-
function isTypeFromPackages(type, packages) {
|
|
85
|
-
const fileName = type.getSymbol()?.valueDeclaration?.getSourceFile().fileName;
|
|
86
|
-
return fileName ? packages.some((pkg) => fileName.includes(`${pkg}/`)) : false;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// src/rules/lint-build-call.ts
|
|
90
|
-
var DEFAULT_OPTIONS = {
|
|
91
|
-
requireLimit: true,
|
|
92
|
-
maxLimit: 1e3,
|
|
93
|
-
requiredFields: []
|
|
94
|
-
};
|
|
95
|
-
var SELECT_QUERY_METHODS = ["select", "from"];
|
|
96
|
-
var lintBuildCall = ESLintUtils2.RuleCreator.withoutDocs({
|
|
97
|
-
meta: {
|
|
98
|
-
type: "problem",
|
|
99
|
-
docs: {
|
|
100
|
-
description: "Validate query builder build() calls using TypeScript type information"
|
|
101
|
-
},
|
|
102
|
-
schema: [
|
|
103
|
-
{
|
|
104
|
-
type: "object",
|
|
105
|
-
properties: {
|
|
106
|
-
requireLimit: {
|
|
107
|
-
type: "boolean",
|
|
108
|
-
description: "Enforce limit() calls on SELECT queries"
|
|
109
|
-
},
|
|
110
|
-
maxLimit: {
|
|
111
|
-
type: "number",
|
|
112
|
-
description: "Maximum allowed limit value",
|
|
113
|
-
minimum: 1
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
additionalProperties: false
|
|
117
|
-
}
|
|
118
|
-
],
|
|
119
|
-
messages: {
|
|
120
|
-
unboundedQuery: "Query build() call may result in unbounded query. Consider adding .limit() to prevent fetching too many rows.",
|
|
121
|
-
maxLimitExceeded: "Query build() call has a limit() value that exceeds the maximum allowed of {{maxLimit}}."
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
defaultOptions: [DEFAULT_OPTIONS],
|
|
125
|
-
create(context, [options]) {
|
|
126
|
-
const services = getTypeScriptServices(context);
|
|
127
|
-
if (!services) {
|
|
128
|
-
throw new Error(
|
|
129
|
-
"TypeScript services are required for lint-build-call rule. Please ensure you are using @typescript-eslint/parser."
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
CallExpression(node) {
|
|
134
|
-
if (!isPrismaNextQueryBuildCall(node, services)) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
lintQuery(node, extractCallChain(node));
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
function lintQuery(node, callChain) {
|
|
141
|
-
if (isSelectQuery(callChain)) {
|
|
142
|
-
checkUnboundedQuery(node, callChain);
|
|
143
|
-
checkLimitExceedsMax(node, callChain);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
function isSelectQuery(callChain) {
|
|
147
|
-
return SELECT_QUERY_METHODS.some(
|
|
148
|
-
(method) => callChain.some((call) => call.method === method)
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
function checkUnboundedQuery(node, callChain) {
|
|
152
|
-
if (options.requireLimit && !callChain.some((call) => call.method === "limit")) {
|
|
153
|
-
reportUnboundedQuery(node);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
function checkLimitExceedsMax(node, callChain) {
|
|
157
|
-
if (!options.maxLimit) return;
|
|
158
|
-
const limitArg = callChain.find((call) => call.method === "limit")?.args.pop();
|
|
159
|
-
const literalValue = limitArg ? extractNumericLiteral(limitArg) : void 0;
|
|
160
|
-
if (literalValue !== void 0 && literalValue > options.maxLimit) {
|
|
161
|
-
reportLimitExceeded(node);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
function extractNumericLiteral(arg) {
|
|
165
|
-
if (arg?.type === "Literal" && "value" in arg && typeof arg.value === "number") {
|
|
166
|
-
return arg.value;
|
|
167
|
-
}
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
function reportUnboundedQuery(node) {
|
|
171
|
-
context.report({
|
|
172
|
-
node,
|
|
173
|
-
messageId: "unboundedQuery"
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
function reportLimitExceeded(node) {
|
|
177
|
-
context.report({
|
|
178
|
-
node,
|
|
179
|
-
messageId: "maxLimitExceeded",
|
|
180
|
-
data: { maxLimit: options.maxLimit?.toString() ?? "undefined" }
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
// src/index.ts
|
|
187
|
-
var PLUGIN_META = {
|
|
188
|
-
name,
|
|
189
|
-
version
|
|
190
|
-
};
|
|
191
|
-
var RULES = {
|
|
192
|
-
"lint-build-call": lintBuildCall
|
|
193
|
-
};
|
|
194
|
-
var RULE_CONFIG = {
|
|
195
|
-
"@prisma-next/lint-build-call": "error"
|
|
196
|
-
};
|
|
197
|
-
var plugin = {
|
|
198
|
-
meta: PLUGIN_META,
|
|
199
|
-
rules: RULES,
|
|
200
|
-
configs: {
|
|
201
|
-
recommended: {
|
|
202
|
-
plugins: ["@prisma-next"],
|
|
203
|
-
rules: RULE_CONFIG
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
plugin.configs["flat/recommended"] = {
|
|
208
|
-
plugins: {
|
|
209
|
-
"@prisma-next": plugin
|
|
210
|
-
},
|
|
211
|
-
rules: RULE_CONFIG
|
|
212
|
-
};
|
|
213
|
-
var index_default = plugin;
|
|
214
|
-
export {
|
|
215
|
-
index_default as default,
|
|
216
|
-
lintBuildCall,
|
|
217
|
-
plugin
|
|
218
|
-
};
|
|
219
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json","../src/rules/lint-build-call.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@prisma-next/eslint-plugin\",\n \"version\": \"0.3.0-dev.6\",\n \"type\": \"module\",\n \"sideEffects\": false,\n \"description\": \"ESLint plugin for Prisma Next query builder type checking and linting\",\n \"keywords\": [\n \"eslint\",\n \"eslintplugin\",\n \"typescript\",\n \"prisma-next\",\n \"query-builder\"\n ],\n \"files\": [\n \"dist\",\n \"src\"\n ],\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\"\n }\n },\n \"scripts\": {\n \"build\": \"tsup --config tsup.config.ts && tsc --project tsconfig.build.json\",\n \"test\": \"vitest run\",\n \"test:coverage\": \"vitest run --coverage\",\n \"typecheck\": \"tsc --noEmit\",\n \"lint\": \"biome check . --config-path ../../../../biome.json --error-on-warnings\",\n \"lint:fix\": \"biome check --write . --config-path ../../../../biome.json\",\n \"lint:fix:unsafe\": \"biome check --write --unsafe . --config-path ../../../../biome.json\",\n \"clean\": \"node ../../../../scripts/clean.mjs\"\n },\n \"dependencies\": {\n \"@typescript-eslint/types\": \"^8.0.0\",\n \"@typescript-eslint/utils\": \"^8.0.0\"\n },\n \"devDependencies\": {\n \"@prisma-next/sql-contract\": \"workspace:*\",\n \"@prisma-next/sql-contract-ts\": \"workspace:*\",\n \"@prisma-next/sql-lane\": \"workspace:*\",\n \"@prisma-next/sql-relational-core\": \"workspace:*\",\n \"@prisma-next/sql-runtime\": \"workspace:*\",\n \"@typescript-eslint/parser\": \"^8.0.0\",\n \"@types/eslint\": \"^9.0.0\",\n \"@types/node\": \"catalog:\",\n \"@vitest/coverage-v8\": \"catalog:\",\n \"eslint\": \"^9.0.0\",\n \"tsup\": \"catalog:\",\n \"typescript\": \"catalog:\",\n \"vitest\": \"catalog:\"\n },\n \"peerDependencies\": {\n \"@typescript-eslint/parser\": \"^8.0.0\",\n \"eslint\": \"^9.0.0\",\n \"typescript\": \"*\"\n }\n}\n","import type { TSESTree } from '@typescript-eslint/types';\nimport { ESLintUtils } from '@typescript-eslint/utils';\nimport {\n type BuilderCall,\n extractCallChain,\n getTypeScriptServices,\n isPrismaNextQueryBuildCall,\n} from '../utils';\n\nconst DEFAULT_OPTIONS = {\n requireLimit: true,\n maxLimit: 1000,\n requiredFields: [],\n};\n\nconst SELECT_QUERY_METHODS = ['select', 'from'] as const;\n\n// Types\ntype MessageIds = 'unboundedQuery' | 'maxLimitExceeded';\n\ninterface RuleOptions {\n /** Enforce limit() calls on SELECT queries to prevent unbounded queries */\n requireLimit?: boolean;\n /** Maximum allowed limit value */\n maxLimit?: number;\n}\n\ntype Options = [RuleOptions];\n\n// Rule implementation\nexport const lintBuildCall = ESLintUtils.RuleCreator.withoutDocs<Options, MessageIds>({\n meta: {\n type: 'problem',\n docs: {\n description: 'Validate query builder build() calls using TypeScript type information',\n },\n schema: [\n {\n type: 'object',\n properties: {\n requireLimit: {\n type: 'boolean',\n description: 'Enforce limit() calls on SELECT queries',\n },\n maxLimit: {\n type: 'number',\n description: 'Maximum allowed limit value',\n minimum: 1,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n unboundedQuery:\n 'Query build() call may result in unbounded query. Consider adding .limit() to prevent fetching too many rows.',\n maxLimitExceeded:\n 'Query build() call has a limit() value that exceeds the maximum allowed of {{maxLimit}}.',\n },\n },\n defaultOptions: [DEFAULT_OPTIONS],\n create(context, [options]) {\n const services = getTypeScriptServices(context);\n\n if (!services) {\n throw new Error(\n 'TypeScript services are required for lint-build-call rule. Please ensure you are using @typescript-eslint/parser.',\n );\n }\n\n return {\n CallExpression(node: TSESTree.CallExpression) {\n if (!isPrismaNextQueryBuildCall(node, services)) {\n return;\n }\n lintQuery(node, extractCallChain(node));\n },\n };\n\n function lintQuery(node: TSESTree.CallExpression, callChain: BuilderCall[]) {\n if (isSelectQuery(callChain)) {\n checkUnboundedQuery(node, callChain);\n checkLimitExceedsMax(node, callChain);\n }\n }\n\n function isSelectQuery(callChain: BuilderCall[]): boolean {\n return SELECT_QUERY_METHODS.some((method) =>\n callChain.some((call) => call.method === method),\n );\n }\n\n function checkUnboundedQuery(node: TSESTree.CallExpression, callChain: BuilderCall[]) {\n if (options.requireLimit && !callChain.some((call) => call.method === 'limit')) {\n reportUnboundedQuery(node);\n }\n }\n\n function checkLimitExceedsMax(node: TSESTree.CallExpression, callChain: BuilderCall[]) {\n if (!options.maxLimit) return;\n\n const limitArg = callChain.find((call) => call.method === 'limit')?.args.pop();\n const literalValue = limitArg ? extractNumericLiteral(limitArg) : undefined;\n if (literalValue !== undefined && literalValue > options.maxLimit) {\n reportLimitExceeded(node);\n }\n }\n\n function extractNumericLiteral(\n arg: TSESTree.Expression | TSESTree.SpreadElement,\n ): number | undefined {\n if (arg?.type === 'Literal' && 'value' in arg && typeof arg.value === 'number') {\n return arg.value;\n }\n return;\n }\n\n function reportUnboundedQuery(node: TSESTree.CallExpression) {\n context.report({\n node,\n messageId: 'unboundedQuery',\n });\n }\n\n function reportLimitExceeded(node: TSESTree.CallExpression) {\n context.report({\n node,\n messageId: 'maxLimitExceeded',\n data: { maxLimit: options.maxLimit?.toString() ?? 'undefined' },\n });\n }\n },\n});\n","import type { TSESTree } from '@typescript-eslint/types';\nimport type { ParserServices } from '@typescript-eslint/utils';\nimport { ESLintUtils } from '@typescript-eslint/utils';\nimport type * as ts from 'typescript';\n\nconst PRISMA_NEXT_SQL_PACKAGES = [\n '@prisma-next/sql-lane',\n 'packages/2-sql/4-lanes/sql-lane',\n] as const;\n\nconst PLAN_TYPE_PATTERNS = [/^SqlQueryPlan$/] as const;\n\nexport type BuilderCall = { method: string; args: TSESTree.CallExpressionArgument[] };\n\n// Types\nexport interface TypeScriptServices {\n program: ts.Program;\n checker: ts.TypeChecker;\n esTreeNodeToTSNodeMap: ParserServices['esTreeNodeToTSNodeMap'];\n tsNodeToESTreeNodeMap: ParserServices['tsNodeToESTreeNodeMap'];\n}\n\n/**\n * Get TypeScript services from ESLint context\n */\nexport function getTypeScriptServices(\n context: Parameters<typeof ESLintUtils.getParserServices>[0],\n): TypeScriptServices | null {\n try {\n const parserServices = ESLintUtils.getParserServices(context, false);\n\n if (!parserServices?.program) {\n return null;\n }\n\n return {\n program: parserServices.program,\n checker: parserServices.program.getTypeChecker(),\n esTreeNodeToTSNodeMap: parserServices.esTreeNodeToTSNodeMap,\n tsNodeToESTreeNodeMap: parserServices.tsNodeToESTreeNodeMap,\n };\n } catch {\n return null;\n }\n}\n\n/**\n * Check if a call expression is a method call with a specific name\n */\nexport function isMethodCall(node: TSESTree.CallExpression, methodName: string): boolean {\n return (\n node.callee.type === 'MemberExpression' &&\n node.callee.property.type === 'Identifier' &&\n node.callee.property.name === methodName\n );\n}\n\n/**\n * Check if a call expression is a query builder build() call\n * Uses type information to verify it's actually our query builder's build method\n */\nexport function isPrismaNextQueryBuildCall(\n node: TSESTree.CallExpression,\n services?: TypeScriptServices | null,\n): boolean {\n if (!isMethodCall(node, 'build') || node.arguments.length > 1 || !services) {\n return false;\n }\n\n if (node.callee.type !== 'MemberExpression') {\n return false;\n }\n\n const objectType = getTypeOfNode(node.callee.object, services);\n if (!objectType) {\n return false;\n }\n\n if (!isTypeFromPackages(objectType, PRISMA_NEXT_SQL_PACKAGES)) {\n return false;\n }\n\n const returnType = getTypeOfNode(node, services);\n return returnType ? isPrismaNextQueryPlanType(returnType) : false;\n}\n\n/**\n * Get the TypeScript type of an ESTree node\n */\nexport function getTypeOfNode(node: TSESTree.Node, services: TypeScriptServices): ts.Type | null {\n try {\n const tsNode = services.esTreeNodeToTSNodeMap.get(node);\n return tsNode ? services.checker.getTypeAtLocation(tsNode) : null;\n } catch {\n return null;\n }\n}\n\n/**\n * Check if a type has a specific property\n */\nexport function typeHasProperty(\n type: ts.Type,\n propertyName: string,\n checker: ts.TypeChecker,\n): boolean {\n try {\n const properties = checker.getPropertiesOfType(type);\n return properties.some((prop) => prop.getName() === propertyName);\n } catch {\n return false;\n }\n}\n\n/**\n * Check if type is a Prisma Next query plan type by name and origin\n */\nexport function isPrismaNextQueryPlanType(type: ts.Type): boolean {\n return PLAN_TYPE_PATTERNS.some((pattern) => pattern.test(type.symbol.name));\n}\n\n/**\n * Extract call chain from a call expression\n * Returns array of method names called in sequence\n */\nexport function extractCallChain(node: TSESTree.CallExpression): BuilderCall[] {\n const chain: BuilderCall[] = [];\n\n function traverse(current: TSESTree.Node): void {\n switch (current.type) {\n case 'CallExpression':\n if (current.callee.type === 'MemberExpression') {\n traverse(current.callee.object);\n if (current.callee.property.type === 'Identifier') {\n chain.push({ method: current.callee.property.name, args: current.arguments });\n }\n }\n break;\n\n case 'MemberExpression':\n traverse(current.object);\n break;\n\n case 'Identifier':\n break;\n }\n }\n\n traverse(node);\n return chain;\n}\n\n/**\n * Helper to check if a type originates from specific packages\n */\nfunction isTypeFromPackages(type: ts.Type, packages: readonly string[]): boolean {\n const fileName = type.getSymbol()?.valueDeclaration?.getSourceFile().fileName;\n return fileName ? packages.some((pkg) => fileName.includes(`${pkg}/`)) : false;\n}\n","import { name, version } from '../package.json';\nimport { lintBuildCall } from './rules/lint-build-call';\n\n// Plugin metadata\nconst PLUGIN_META = {\n name,\n version,\n};\n\n// Rule definitions\nconst RULES = {\n 'lint-build-call': lintBuildCall,\n};\n\n// Configuration presets\nconst RULE_CONFIG = {\n '@prisma-next/lint-build-call': 'error',\n};\n\n// Plugin interface\ninterface ESLintPlugin {\n meta: {\n name: string;\n version: string;\n };\n // biome-ignore lint/suspicious/noExplicitAny: Required for ESLint plugin interface compatibility\n rules: Record<string, any>;\n // biome-ignore lint/suspicious/noExplicitAny: Required for ESLint plugin interface compatibility\n configs: Record<string, any>;\n}\n\n// Plugin implementation\nconst plugin: ESLintPlugin = {\n meta: PLUGIN_META,\n rules: RULES,\n configs: {\n recommended: {\n plugins: ['@prisma-next'],\n rules: RULE_CONFIG,\n },\n },\n};\n\n// Add flat config after plugin is defined to avoid circular reference\nplugin.configs['flat/recommended'] = {\n plugins: {\n '@prisma-next': plugin,\n },\n rules: RULE_CONFIG,\n};\n\n// Exports\nexport default plugin;\nexport { lintBuildCall };\nexport { plugin };\nexport type { ESLintPlugin };\n"],"mappings":";AACE,WAAQ;AACR,cAAW;;;ACDb,SAAS,eAAAA,oBAAmB;;;ACC5B,SAAS,mBAAmB;AAG5B,IAAM,2BAA2B;AAAA,EAC/B;AAAA,EACA;AACF;AAEA,IAAM,qBAAqB,CAAC,gBAAgB;AAerC,SAAS,sBACd,SAC2B;AAC3B,MAAI;AACF,UAAM,iBAAiB,YAAY,kBAAkB,S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B,MAA+B;AAC1D,cAAQ,OAAO;AAAA,QACb;AAAA,QACA,WAAW;AAAA,QACX,MAAM,EAAE,UAAU,QAAQ,UAAU,SAAS,KAAK,YAAY;AAAA,MAChE,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;AEhID,IAAM,cAAc;AAAA,EAClB;AAAA,EACA;AACF;AAGA,IAAM,QAAQ;AAAA,EACZ,mBAAmB;AACrB;AAGA,IAAM,cAAc;AAAA,EAClB,gCAAgC;AAClC;AAeA,IAAM,SAAuB;AAAA,EAC3B,MAAM;AAAA,EACN,OAAO;AAAA,EACP,SAAS;AAAA,IACP,aAAa;AAAA,MACX,SAAS,CAAC,cAAc;AAAA,MACxB,OAAO;AAAA,IACT;AAAA,EACF;AACF;AAGA,OAAO,QAAQ,kBAAkB,IAAI;AAAA,EACnC,SAAS;AAAA,IACP,gBAAgB;AAAA,EAClB;AAAA,EACA,OAAO;AACT;AAGA,IAAO,gBAAQ;","names":["ESLintUtils","ESLintUtils"]}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
-
type MessageIds = 'unboundedQuery' | 'maxLimitExceeded';
|
|
3
|
-
interface RuleOptions {
|
|
4
|
-
/** Enforce limit() calls on SELECT queries to prevent unbounded queries */
|
|
5
|
-
requireLimit?: boolean;
|
|
6
|
-
/** Maximum allowed limit value */
|
|
7
|
-
maxLimit?: number;
|
|
8
|
-
}
|
|
9
|
-
type Options = [RuleOptions];
|
|
10
|
-
export declare const lintBuildCall: ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=lint-build-call.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lint-build-call.d.ts","sourceRoot":"","sources":["../../src/rules/lint-build-call.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAiBvD,KAAK,UAAU,GAAG,gBAAgB,GAAG,kBAAkB,CAAC;AAExD,UAAU,WAAW;IACnB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,KAAK,OAAO,GAAG,CAAC,WAAW,CAAC,CAAC;AAG7B,eAAO,MAAM,aAAa,gFAsGxB,CAAC"}
|
package/dist/utils.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { TSESTree } from '@typescript-eslint/types';
|
|
2
|
-
import type { ParserServices } from '@typescript-eslint/utils';
|
|
3
|
-
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
4
|
-
import type * as ts from 'typescript';
|
|
5
|
-
export type BuilderCall = {
|
|
6
|
-
method: string;
|
|
7
|
-
args: TSESTree.CallExpressionArgument[];
|
|
8
|
-
};
|
|
9
|
-
export interface TypeScriptServices {
|
|
10
|
-
program: ts.Program;
|
|
11
|
-
checker: ts.TypeChecker;
|
|
12
|
-
esTreeNodeToTSNodeMap: ParserServices['esTreeNodeToTSNodeMap'];
|
|
13
|
-
tsNodeToESTreeNodeMap: ParserServices['tsNodeToESTreeNodeMap'];
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Get TypeScript services from ESLint context
|
|
17
|
-
*/
|
|
18
|
-
export declare function getTypeScriptServices(context: Parameters<typeof ESLintUtils.getParserServices>[0]): TypeScriptServices | null;
|
|
19
|
-
/**
|
|
20
|
-
* Check if a call expression is a method call with a specific name
|
|
21
|
-
*/
|
|
22
|
-
export declare function isMethodCall(node: TSESTree.CallExpression, methodName: string): boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Check if a call expression is a query builder build() call
|
|
25
|
-
* Uses type information to verify it's actually our query builder's build method
|
|
26
|
-
*/
|
|
27
|
-
export declare function isPrismaNextQueryBuildCall(node: TSESTree.CallExpression, services?: TypeScriptServices | null): boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Get the TypeScript type of an ESTree node
|
|
30
|
-
*/
|
|
31
|
-
export declare function getTypeOfNode(node: TSESTree.Node, services: TypeScriptServices): ts.Type | null;
|
|
32
|
-
/**
|
|
33
|
-
* Check if a type has a specific property
|
|
34
|
-
*/
|
|
35
|
-
export declare function typeHasProperty(type: ts.Type, propertyName: string, checker: ts.TypeChecker): boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Check if type is a Prisma Next query plan type by name and origin
|
|
38
|
-
*/
|
|
39
|
-
export declare function isPrismaNextQueryPlanType(type: ts.Type): boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Extract call chain from a call expression
|
|
42
|
-
* Returns array of method names called in sequence
|
|
43
|
-
*/
|
|
44
|
-
export declare function extractCallChain(node: TSESTree.CallExpression): BuilderCall[];
|
|
45
|
-
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAStC,MAAM,MAAM,WAAW,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAC,sBAAsB,EAAE,CAAA;CAAE,CAAC;AAGtF,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC;IACpB,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC;IACxB,qBAAqB,EAAE,cAAc,CAAC,uBAAuB,CAAC,CAAC;IAC/D,qBAAqB,EAAE,cAAc,CAAC,uBAAuB,CAAC,CAAC;CAChE;AAED;;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