@aburi/effects-prisma 0.1.0 → 0.2.0
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 +21 -0
- package/README.md +2 -2
- package/dist/index.d.mts +23 -15
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +41 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
- package/src/classify.ts +7 -49
- package/src/constants.ts +17 -0
- package/src/imports.ts +19 -15
- package/src/index.ts +2 -1
- package/src/manifest.ts +3 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kage1020
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ Recognised shapes:
|
|
|
13
13
|
| `<client>.$transaction(...)` | `db.transaction` |
|
|
14
14
|
|
|
15
15
|
Raw SQL (`$queryRaw` / `$executeRaw` / `$queryRawUnsafe` / `$executeRawUnsafe`)
|
|
16
|
-
is intentionally **not** classified
|
|
16
|
+
is intentionally **not** classified today — statically distinguishing a read
|
|
17
17
|
raw query from a write raw query would require SQL parsing, which is out of the
|
|
18
18
|
current scope. A future revision may add it under a `medium` confidence tier.
|
|
19
19
|
|
|
@@ -37,4 +37,4 @@ import { prismaEffectsPlugin } from "@aburi/effects-prisma"
|
|
|
37
37
|
|
|
38
38
|
## See also
|
|
39
39
|
|
|
40
|
-
- [`design/
|
|
40
|
+
- [`docs/design/effect-plugin.md`](../../docs/design/effect-plugin.md)
|
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { CallCandidate, ClassifyContext, EffectClassification, EffectPlugin, ImportEdge, PluginContext } from "@aburi/types";
|
|
2
2
|
|
|
3
3
|
//#region src/classify.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Shared derivedBy namespace. `manifest.ts` imports this same const for its
|
|
6
|
-
* `derivedByPrefixes` entry, so the classifier's tag builder and the registry
|
|
7
|
-
* declaration cannot drift.
|
|
8
|
-
*/
|
|
9
|
-
declare const EFFECTS_PRISMA_DERIVED_BY_PREFIX: "effects-plugin:prisma";
|
|
10
4
|
/**
|
|
11
5
|
* Classify a CallCandidate against Prisma Client conventions.
|
|
12
6
|
*
|
|
@@ -29,18 +23,32 @@ declare const EFFECTS_PRISMA_DERIVED_BY_PREFIX: "effects-plugin:prisma";
|
|
|
29
23
|
*/
|
|
30
24
|
declare function classifyPrismaCall(call: CallCandidate, ctx: ClassifyContext): EffectClassification | null;
|
|
31
25
|
//#endregion
|
|
26
|
+
//#region src/constants.d.ts
|
|
27
|
+
/**
|
|
28
|
+
* Package-relative plugin name. Doubles as the prefix of every thrown message, so a caught
|
|
29
|
+
* exception names the plugin that rejected the input. `manifest.ts` declares the same
|
|
30
|
+
* string as `name`.
|
|
31
|
+
*/
|
|
32
|
+
declare const EFFECTS_PRISMA_PLUGIN_NAME: "effects-prisma";
|
|
33
|
+
/**
|
|
34
|
+
* Shared derivedBy namespace. `manifest.ts` imports this same const for its
|
|
35
|
+
* `derivedByPrefixes` entry, so the classifier's tag builder and the registry
|
|
36
|
+
* declaration cannot drift.
|
|
37
|
+
*/
|
|
38
|
+
declare const EFFECTS_PRISMA_DERIVED_BY_PREFIX: "effects-plugin:prisma";
|
|
39
|
+
//#endregion
|
|
32
40
|
//#region src/imports.d.ts
|
|
33
41
|
/**
|
|
34
42
|
* True when the file's import list contains any recognized Prisma Client module. An
|
|
35
|
-
* empty source string on an ImportEdge is rejected
|
|
36
|
-
* to emit normalized non-empty specifiers, and treating `""` as
|
|
37
|
-
* hide upstream bugs.
|
|
43
|
+
* empty source string on an ImportEdge is rejected by the shared guard: the language
|
|
44
|
+
* plugin's contract is to emit normalized non-empty specifiers, and treating `""` as
|
|
45
|
+
* unmatched would silently hide upstream bugs.
|
|
38
46
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
47
|
+
* `filePath` is required and threaded into any thrown error message so a caught
|
|
48
|
+
* exception in production tooling (CI logs, error reporters) points directly at the
|
|
49
|
+
* offending source file rather than a bare "empty source" string.
|
|
42
50
|
*/
|
|
43
|
-
declare function hasPrismaImport(imports: readonly ImportEdge[]): boolean;
|
|
51
|
+
declare function hasPrismaImport(imports: readonly ImportEdge[], filePath: string): boolean;
|
|
44
52
|
//#endregion
|
|
45
53
|
//#region src/manifest.d.ts
|
|
46
54
|
/**
|
|
@@ -50,7 +58,7 @@ declare function hasPrismaImport(imports: readonly ImportEdge[]): boolean;
|
|
|
50
58
|
* The plugin returns core-owned effect ids (`db.read` / `db.write` / `db.transaction`)
|
|
51
59
|
* from `classify()`; per extension-vocab.md §5.1 core vocab lives in the reserved
|
|
52
60
|
* namespace and MUST NOT appear in a plugin's `provides.effects`. The plugin's own
|
|
53
|
-
* `x-prisma:*` namespace has no
|
|
61
|
+
* `x-prisma:*` namespace currently has no bindings — model-specific effects would sit there
|
|
54
62
|
* once introduced. `derivedByPrefixes` shares its literal with the classifier's tag
|
|
55
63
|
* builder so both stay in lockstep across edits.
|
|
56
64
|
*/
|
|
@@ -141,5 +149,5 @@ declare class PrismaEffectsPlugin implements EffectPlugin {
|
|
|
141
149
|
*/
|
|
142
150
|
declare const prismaEffectsPlugin: PrismaEffectsPlugin;
|
|
143
151
|
//#endregion
|
|
144
|
-
export { EFFECTS_PRISMA_DERIVED_BY_PREFIX, PRISMA_READ_METHODS, PRISMA_TRANSACTION_METHOD, PRISMA_WRITE_METHODS, PrismaEffectsPlugin, type PrismaReadMethod, type PrismaTransactionMethod, type PrismaWriteMethod, classifyPrismaCall, effectsPrismaManifest, hasPrismaImport, isPrismaReadMethod, isPrismaTransactionMethod, isPrismaWriteMethod, prismaEffectsPlugin };
|
|
152
|
+
export { EFFECTS_PRISMA_DERIVED_BY_PREFIX, EFFECTS_PRISMA_PLUGIN_NAME, PRISMA_READ_METHODS, PRISMA_TRANSACTION_METHOD, PRISMA_WRITE_METHODS, PrismaEffectsPlugin, type PrismaReadMethod, type PrismaTransactionMethod, type PrismaWriteMethod, classifyPrismaCall, effectsPrismaManifest, hasPrismaImport, isPrismaReadMethod, isPrismaTransactionMethod, isPrismaWriteMethod, prismaEffectsPlugin };
|
|
145
153
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/classify.ts","../src/imports.ts","../src/manifest.ts","../src/methods.ts","../src/plugin.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/classify.ts","../src/constants.ts","../src/imports.ts","../src/manifest.ts","../src/methods.ts","../src/plugin.ts"],"mappings":";;;;;AA0BA;;;;;;;;;;;;;;AAGuB;;;;iBAHP,kBAAA,CACd,IAAA,EAAM,aAAA,EACN,GAAA,EAAK,eAAA,GACJ,oBAAA;;;;;;AAHH;;cCjBa,0BAAA;;;;;;cAOA,gCAAA;;;ADaU;;;;ACpBvB;;;;AAAmE;AAOnE;ADauB,iBEWP,eAAA,CAAgB,OAAA,WAAkB,UAAU,IAAI,QAAA;;;;;;AFdhE;;;;;;;;cGZa,qBAAA;EAAA;;;;;;;;;;;;;;;;;;;;;AHYb;;;;;;;;;;cIbM,wBAAA;AAAA,cAWA,yBAAA;AAAA,KAYM,gBAAA,WAA2B,wBAAwB;AAAA,KACnD,iBAAA,WAA4B,yBAAyB;AJR1C;AAAA,KIWX,uBAAA;AAAA,cAEC,mBAAA,EAAqB,WAAW,CAAC,gBAAA;AAAA,cACjC,oBAAA,EAAsB,WAAW,CAAC,iBAAA;AAAA,cAGlC,yBAAA,EAA2B,uBAAwC;AAAA,iBAEhE,kBAAA,CAAmB,IAAA,WAAe,IAAA,IAAQ,gBAAgB;AAAA,iBAI1D,mBAAA,CAAoB,IAAA,WAAe,IAAA,IAAQ,iBAAiB;AAAA,iBAI5D,yBAAA,CAA0B,IAAA,WAAe,IAAA,IAAQ,uBAAuB;;;;;AJ9BxF;;;;;;;;cKNM,mBAAA,YAA+B,YAAA;EAAA,SAC1B,QAAA;IAAA;;;;;;;;;;;;;;;;EAEH,IAAA,CAAK,IAAA,EAAM,aAAA,GAAgB,OAAA;EAEjC,QAAA,CAAS,IAAA,EAAM,aAAA,EAAe,GAAA,EAAK,eAAA,GAAkB,oBAAA;AAAA;;;AHevD;;;;;;cGFa,mBAAA,EAAmB,mBAA4B"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
import { assertNonEmptySegments, hasMatchingImport } from "@aburi/plugin-registry/plugin-input";
|
|
2
|
+
|
|
3
|
+
//#region src/constants.ts
|
|
4
|
+
/**
|
|
5
|
+
* Package-relative plugin name. Doubles as the prefix of every thrown message, so a caught
|
|
6
|
+
* exception names the plugin that rejected the input. `manifest.ts` declares the same
|
|
7
|
+
* string as `name`.
|
|
8
|
+
*/
|
|
9
|
+
const EFFECTS_PRISMA_PLUGIN_NAME = "effects-prisma";
|
|
10
|
+
/**
|
|
11
|
+
* Shared derivedBy namespace. `manifest.ts` imports this same const for its
|
|
12
|
+
* `derivedByPrefixes` entry, so the classifier's tag builder and the registry
|
|
13
|
+
* declaration cannot drift.
|
|
14
|
+
*/
|
|
15
|
+
const EFFECTS_PRISMA_DERIVED_BY_PREFIX = "effects-plugin:prisma";
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
1
18
|
//#region src/imports.ts
|
|
2
19
|
/**
|
|
3
20
|
* npm module specifiers that expose a `PrismaClient`. Any file that pulls in one of
|
|
@@ -14,19 +31,25 @@
|
|
|
14
31
|
*/
|
|
15
32
|
const PRISMA_CLIENT_MODULES_LIST = ["@prisma/client", "@prisma/client/edge"];
|
|
16
33
|
const PRISMA_CLIENT_MODULES = new Set(PRISMA_CLIENT_MODULES_LIST);
|
|
34
|
+
/** Membership test against the closed set of Prisma Client entry points. */
|
|
35
|
+
function isPrismaClientModule(source) {
|
|
36
|
+
return PRISMA_CLIENT_MODULES.has(source);
|
|
37
|
+
}
|
|
17
38
|
/**
|
|
18
39
|
* True when the file's import list contains any recognized Prisma Client module. An
|
|
19
|
-
* empty source string on an ImportEdge is rejected
|
|
20
|
-
* to emit normalized non-empty specifiers, and treating `""` as
|
|
21
|
-
* hide upstream bugs.
|
|
40
|
+
* empty source string on an ImportEdge is rejected by the shared guard: the language
|
|
41
|
+
* plugin's contract is to emit normalized non-empty specifiers, and treating `""` as
|
|
42
|
+
* unmatched would silently hide upstream bugs.
|
|
22
43
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
44
|
+
* `filePath` is required and threaded into any thrown error message so a caught
|
|
45
|
+
* exception in production tooling (CI logs, error reporters) points directly at the
|
|
46
|
+
* offending source file rather than a bare "empty source" string.
|
|
26
47
|
*/
|
|
27
|
-
function hasPrismaImport(imports) {
|
|
28
|
-
|
|
29
|
-
|
|
48
|
+
function hasPrismaImport(imports, filePath) {
|
|
49
|
+
return hasMatchingImport(imports, {
|
|
50
|
+
plugin: EFFECTS_PRISMA_PLUGIN_NAME,
|
|
51
|
+
filePath
|
|
52
|
+
}, isPrismaClientModule);
|
|
30
53
|
}
|
|
31
54
|
|
|
32
55
|
//#endregion
|
|
@@ -81,12 +104,6 @@ function isPrismaTransactionMethod(name) {
|
|
|
81
104
|
//#endregion
|
|
82
105
|
//#region src/classify.ts
|
|
83
106
|
/**
|
|
84
|
-
* Shared derivedBy namespace. `manifest.ts` imports this same const for its
|
|
85
|
-
* `derivedByPrefixes` entry, so the classifier's tag builder and the registry
|
|
86
|
-
* declaration cannot drift.
|
|
87
|
-
*/
|
|
88
|
-
const EFFECTS_PRISMA_DERIVED_BY_PREFIX = "effects-plugin:prisma";
|
|
89
|
-
/**
|
|
90
107
|
* Classify a CallCandidate against Prisma Client conventions.
|
|
91
108
|
*
|
|
92
109
|
* Recognition strategy:
|
|
@@ -107,9 +124,12 @@ const EFFECTS_PRISMA_DERIVED_BY_PREFIX = "effects-plugin:prisma";
|
|
|
107
124
|
* timeout budget the core enforces (effect-plugin.md §5.1.1).
|
|
108
125
|
*/
|
|
109
126
|
function classifyPrismaCall(call, ctx) {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
127
|
+
const origin = {
|
|
128
|
+
plugin: EFFECTS_PRISMA_PLUGIN_NAME,
|
|
129
|
+
filePath: ctx.file.path
|
|
130
|
+
};
|
|
131
|
+
const { segments: parts, last: method } = assertNonEmptySegments(call.target, origin);
|
|
132
|
+
if (!hasPrismaImport(ctx.file.imports, ctx.file.path)) return null;
|
|
113
133
|
if (isPrismaTransactionMethod(method)) {
|
|
114
134
|
if (parts.length < 2) return null;
|
|
115
135
|
return {
|
|
@@ -131,19 +151,6 @@ function classifyPrismaCall(call, ctx) {
|
|
|
131
151
|
};
|
|
132
152
|
return null;
|
|
133
153
|
}
|
|
134
|
-
/**
|
|
135
|
-
* Split `target` on `.` and reject any shape a well-formed language plugin would never
|
|
136
|
-
* emit: an empty target, or one with an empty segment (leading, trailing, or adjacent
|
|
137
|
-
* dots). A malformed target here would otherwise slip through the length gate and
|
|
138
|
-
* false-classify — e.g. `"prisma..create"` has three segments and would match a write
|
|
139
|
-
* verb — so this is the fail-fast the sibling classifiers apply at their entry points.
|
|
140
|
-
*/
|
|
141
|
-
function assertNonEmptySegments(target) {
|
|
142
|
-
if (target.length === 0) throw new Error("effects-prisma: CallCandidate.target is empty — language plugin emitted an unnormalized callee");
|
|
143
|
-
const parts = target.split(".");
|
|
144
|
-
for (const segment of parts) if (segment.length === 0) throw new Error(`effects-prisma: CallCandidate.target "${target}" has empty segment(s) — language plugin emitted an unnormalized callee`);
|
|
145
|
-
return parts;
|
|
146
|
-
}
|
|
147
154
|
|
|
148
155
|
//#endregion
|
|
149
156
|
//#region src/manifest.ts
|
|
@@ -154,13 +161,13 @@ function assertNonEmptySegments(target) {
|
|
|
154
161
|
* The plugin returns core-owned effect ids (`db.read` / `db.write` / `db.transaction`)
|
|
155
162
|
* from `classify()`; per extension-vocab.md §5.1 core vocab lives in the reserved
|
|
156
163
|
* namespace and MUST NOT appear in a plugin's `provides.effects`. The plugin's own
|
|
157
|
-
* `x-prisma:*` namespace has no
|
|
164
|
+
* `x-prisma:*` namespace currently has no bindings — model-specific effects would sit there
|
|
158
165
|
* once introduced. `derivedByPrefixes` shares its literal with the classifier's tag
|
|
159
166
|
* builder so both stay in lockstep across edits.
|
|
160
167
|
*/
|
|
161
168
|
const effectsPrismaManifest = {
|
|
162
169
|
$schema: "https://aburi.dev/schema/aburi.plugin.v1.json",
|
|
163
|
-
name:
|
|
170
|
+
name: EFFECTS_PRISMA_PLUGIN_NAME,
|
|
164
171
|
version: "0.0.0",
|
|
165
172
|
type: "effects",
|
|
166
173
|
engines: { aburi: "*" },
|
|
@@ -204,5 +211,5 @@ var PrismaEffectsPlugin = class {
|
|
|
204
211
|
const prismaEffectsPlugin = new PrismaEffectsPlugin();
|
|
205
212
|
|
|
206
213
|
//#endregion
|
|
207
|
-
export { EFFECTS_PRISMA_DERIVED_BY_PREFIX, PRISMA_READ_METHODS, PRISMA_TRANSACTION_METHOD, PRISMA_WRITE_METHODS, PrismaEffectsPlugin, classifyPrismaCall, effectsPrismaManifest, hasPrismaImport, isPrismaReadMethod, isPrismaTransactionMethod, isPrismaWriteMethod, prismaEffectsPlugin };
|
|
214
|
+
export { EFFECTS_PRISMA_DERIVED_BY_PREFIX, EFFECTS_PRISMA_PLUGIN_NAME, PRISMA_READ_METHODS, PRISMA_TRANSACTION_METHOD, PRISMA_WRITE_METHODS, PrismaEffectsPlugin, classifyPrismaCall, effectsPrismaManifest, hasPrismaImport, isPrismaReadMethod, isPrismaTransactionMethod, isPrismaWriteMethod, prismaEffectsPlugin };
|
|
208
215
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/imports.ts","../src/methods.ts","../src/classify.ts","../src/manifest.ts","../src/plugin.ts"],"sourcesContent":["import type { ImportEdge } from \"@aburi/types\"\n\n/**\n * npm module specifiers that expose a `PrismaClient`. Any file that pulls in one of\n * these is treated as a Prisma consumer; files that reference the identifier without\n * importing Prisma are ignored so an unrelated `db.user.findMany()` from another ORM\n * does not get miscategorized.\n *\n * - `@prisma/client` — the default Prisma Client entry since v4.\n * - `@prisma/client/edge` — the Edge runtime entry used by Vercel Edge, Cloudflare\n * Workers, and Prisma Accelerate. Different bundle, same delegate surface.\n *\n * The set is a literal source of truth. Extending the plugin for community builds or a\n * future Prisma bundle is a table edit here.\n */\nconst PRISMA_CLIENT_MODULES_LIST = [\"@prisma/client\", \"@prisma/client/edge\"] as const\n\nexport type PrismaClientModule = (typeof PRISMA_CLIENT_MODULES_LIST)[number]\n\nexport const PRISMA_CLIENT_MODULES: ReadonlySet<PrismaClientModule> = new Set(\n PRISMA_CLIENT_MODULES_LIST,\n)\n\n/**\n * True when the file's import list contains any recognized Prisma Client module. An\n * empty source string on an ImportEdge is rejected: the language plugin's contract is\n * to emit normalized non-empty specifiers, and treating `\"\"` as unmatched would silently\n * hide upstream bugs.\n *\n * Validation runs across every edge before the match check so ImportEdge order does\n * not make throw behavior non-deterministic. Using `.some()` alone would short-circuit\n * on the first match and never notice a broken edge that happens to sit later.\n */\nexport function hasPrismaImport(imports: readonly ImportEdge[]): boolean {\n for (const edge of imports) {\n if (edge.source.length === 0) {\n throw new Error(\n \"effects-prisma: ImportEdge.source is empty — language plugin emitted an unnormalized import edge\",\n )\n }\n }\n return imports.some((edge) => (PRISMA_CLIENT_MODULES as ReadonlySet<string>).has(edge.source))\n}\n","/**\n * Prisma model delegate method vocabulary.\n *\n * Each `_LIST` is the single source of truth — the union type and the runtime `Set` are\n * both derived from it, so extending the vocabulary is a table edit in exactly one\n * place. Extending as Prisma ships new delegate methods keeps the classifier honest\n * without a code rewrite.\n *\n * Only methods that map cleanly onto core `db.read` / `db.write` vocabulary are listed.\n * Delegate helpers whose semantics do not match (metadata accessors, raw SQL escapes,\n * connection lifecycle) stay out — the plugin returns `null` for them so downstream\n * effect plugins get a chance.\n */\nconst PRISMA_READ_METHODS_LIST = [\n \"findUnique\",\n \"findUniqueOrThrow\",\n \"findFirst\",\n \"findFirstOrThrow\",\n \"findMany\",\n \"count\",\n \"aggregate\",\n \"groupBy\",\n] as const\n\nconst PRISMA_WRITE_METHODS_LIST = [\n \"create\",\n \"createMany\",\n \"createManyAndReturn\",\n \"update\",\n \"updateMany\",\n \"updateManyAndReturn\",\n \"upsert\",\n \"delete\",\n \"deleteMany\",\n] as const\n\nexport type PrismaReadMethod = (typeof PRISMA_READ_METHODS_LIST)[number]\nexport type PrismaWriteMethod = (typeof PRISMA_WRITE_METHODS_LIST)[number]\n\n/** Top-level client method: `prisma.$transaction(...)`. Not nested under a model. */\nexport type PrismaTransactionMethod = \"$transaction\"\n\nexport const PRISMA_READ_METHODS: ReadonlySet<PrismaReadMethod> = new Set(PRISMA_READ_METHODS_LIST)\nexport const PRISMA_WRITE_METHODS: ReadonlySet<PrismaWriteMethod> = new Set(\n PRISMA_WRITE_METHODS_LIST,\n)\nexport const PRISMA_TRANSACTION_METHOD: PrismaTransactionMethod = \"$transaction\"\n\nexport function isPrismaReadMethod(name: string): name is PrismaReadMethod {\n return (PRISMA_READ_METHODS as ReadonlySet<string>).has(name)\n}\n\nexport function isPrismaWriteMethod(name: string): name is PrismaWriteMethod {\n return (PRISMA_WRITE_METHODS as ReadonlySet<string>).has(name)\n}\n\nexport function isPrismaTransactionMethod(name: string): name is PrismaTransactionMethod {\n return name === PRISMA_TRANSACTION_METHOD\n}\n","import type { CallCandidate, ClassifyContext, EffectClassification } from \"@aburi/types\"\nimport { hasPrismaImport } from \"./imports\"\nimport { isPrismaReadMethod, isPrismaTransactionMethod, isPrismaWriteMethod } from \"./methods\"\n\n/**\n * Shared derivedBy namespace. `manifest.ts` imports this same const for its\n * `derivedByPrefixes` entry, so the classifier's tag builder and the registry\n * declaration cannot drift.\n */\nexport const EFFECTS_PRISMA_DERIVED_BY_PREFIX = \"effects-plugin:prisma\" as const\n\n/**\n * Classify a CallCandidate against Prisma Client conventions.\n *\n * Recognition strategy:\n * 1. The owning file must import a Prisma Client module (see `hasPrismaImport`). No\n * import → `null`, so callers can chain other effect plugins after this one.\n * 2. The target is split on `.`; the plugin looks at the trailing segments to match\n * Prisma's fixed client surface. Two shapes are accepted:\n * - `<...>.<model>.<verb>` (3+ segments) — a model delegate call. The client\n * segment stops two-segment method collisions (Express `router.create(...)`)\n * from false-classifying.\n * - `<...>.$transaction` (2+ segments) — the top-level transaction API on the\n * client itself.\n * 3. Malformed targets (empty string, adjacent / leading / trailing dots) throw — the\n * language plugin's contract is a normalized non-empty callee, so a violation\n * here is an upstream bug we surface loudly instead of silently miscategorizing.\n *\n * The function is a pure lookup — no I/O, no state, no async — matching the per-call\n * timeout budget the core enforces (effect-plugin.md §5.1.1).\n */\nexport function classifyPrismaCall(\n call: CallCandidate,\n ctx: ClassifyContext,\n): EffectClassification | null {\n // Fail-fast runs BEFORE the import gate so a malformed target throws on every file,\n // not just the ~1% that import Prisma. Ordering the other way lets the same bug\n // surface only in Prisma-consuming files and stay silent everywhere else —\n // catastrophic for reproducing upstream language-plugin bugs.\n const parts = assertNonEmptySegments(call.target)\n\n if (!hasPrismaImport(ctx.file.imports)) return null\n\n // `parts` is guaranteed non-empty by `assertNonEmptySegments`, but `at()`'s general\n // signature still widens to `string | undefined`. `.at(-1) as string` records the\n // intent without a non-null assertion (Biome disallows `!` under noNonNullAssertion).\n const method = parts.at(-1) as string\n\n if (isPrismaTransactionMethod(method)) {\n // Bare `$transaction()` (single segment) is not a Prisma call — the transaction\n // API only makes sense as a method on the client (`<client>.$transaction(...)`).\n if (parts.length < 2) return null\n return {\n effectId: \"db.transaction\",\n confidence: \"high\",\n derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:tx`,\n }\n }\n\n // Model delegate calls need `<client>.<model>.<verb>` to distinguish them from\n // unrelated two-segment method calls (Express `router.create(...)`, an Array's\n // hypothetical `.findMany` collision) that would otherwise false-positive in files\n // that colocate Prisma with another library.\n if (parts.length < 3) return null\n\n if (isPrismaReadMethod(method)) {\n return {\n effectId: \"db.read\",\n confidence: \"high\",\n derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:read`,\n }\n }\n\n if (isPrismaWriteMethod(method)) {\n return {\n effectId: \"db.write\",\n confidence: \"high\",\n derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:write`,\n }\n }\n\n return null\n}\n\n/**\n * A non-empty split — after `assertNonEmptySegments` runs there is guaranteed to be at\n * least one segment, so the tuple type reflects that.\n */\ntype NonEmptySegments = readonly [string, ...string[]]\n\n/**\n * Split `target` on `.` and reject any shape a well-formed language plugin would never\n * emit: an empty target, or one with an empty segment (leading, trailing, or adjacent\n * dots). A malformed target here would otherwise slip through the length gate and\n * false-classify — e.g. `\"prisma..create\"` has three segments and would match a write\n * verb — so this is the fail-fast the sibling classifiers apply at their entry points.\n */\nfunction assertNonEmptySegments(target: string): NonEmptySegments {\n if (target.length === 0) {\n throw new Error(\n \"effects-prisma: CallCandidate.target is empty — language plugin emitted an unnormalized callee\",\n )\n }\n const parts = target.split(\".\")\n for (const segment of parts) {\n if (segment.length === 0) {\n throw new Error(\n `effects-prisma: CallCandidate.target \"${target}\" has empty segment(s) — language plugin emitted an unnormalized callee`,\n )\n }\n }\n // Split of a non-empty string yields at least one segment, and the loop above ruled\n // out empty segments — the tuple assertion here reflects a proven invariant.\n return parts as unknown as NonEmptySegments\n}\n","import type { EffectsManifest } from \"@aburi/types\"\nimport { EFFECTS_PRISMA_DERIVED_BY_PREFIX } from \"./classify\"\n\n/**\n * Manifest for `@aburi/effects-prisma`. `as const satisfies EffectsManifest` keeps\n * every literal narrow so downstream registry checks see the exact shape.\n *\n * The plugin returns core-owned effect ids (`db.read` / `db.write` / `db.transaction`)\n * from `classify()`; per extension-vocab.md §5.1 core vocab lives in the reserved\n * namespace and MUST NOT appear in a plugin's `provides.effects`. The plugin's own\n * `x-prisma:*` namespace has no v0.1 bindings — model-specific effects would sit there\n * once introduced. `derivedByPrefixes` shares its literal with the classifier's tag\n * builder so both stay in lockstep across edits.\n */\nexport const effectsPrismaManifest = {\n $schema: \"https://aburi.dev/schema/aburi.plugin.v1.json\",\n name: \"effects-prisma\",\n version: \"0.0.0\",\n type: \"effects\",\n engines: { aburi: \"*\" },\n provides: {\n effects: [],\n effectPrefixes: [],\n extKinds: [],\n extKindPrefixes: [],\n derivedByPrefixes: [EFFECTS_PRISMA_DERIVED_BY_PREFIX],\n frameworks: [],\n },\n} as const satisfies EffectsManifest\n","import type {\n CallCandidate,\n ClassifyContext,\n EffectClassification,\n EffectPlugin,\n PluginContext,\n} from \"@aburi/types\"\nimport { classifyPrismaCall } from \"./classify\"\nimport { effectsPrismaManifest } from \"./manifest\"\n\n/**\n * Prisma effect plugin. Sits behind the language plugin's `walkBody` output, mapping\n * `prisma.<model>.<verb>` and `prisma.$transaction` call expressions into the core\n * `db.read` / `db.write` / `db.transaction` effect vocabulary.\n *\n * `init` and `classify` are both pure with respect to plugin state — no lazy resources,\n * no per-run caches — so repeated invocations against the same CallCandidate produce\n * identical results. This matches the per-call timeout contract in\n * effect-plugin.md §5.1.1 and the \"pure classifier\" recommendation in §11.1.\n */\nclass PrismaEffectsPlugin implements EffectPlugin {\n readonly manifest = effectsPrismaManifest\n\n async init(_ctx: PluginContext): Promise<void> {}\n\n classify(call: CallCandidate, ctx: ClassifyContext): EffectClassification | null {\n return classifyPrismaCall(call, ctx)\n }\n}\n\n/**\n * Ready-to-register instance. Callers pass this to `@aburi/plugin-registry` or a scan\n * pipeline. The type annotation is omitted deliberately: `class implements EffectPlugin`\n * already enforces the structural contract, and inferring the narrow class type keeps\n * the manifest literals (`readonly [\"effects-plugin:prisma\"]`, `\"effects-prisma\"`)\n * visible to consumers that want to compare against them without a separate manifest\n * import.\n */\nexport const prismaEffectsPlugin = new PrismaEffectsPlugin()\n\nexport { PrismaEffectsPlugin }\n"],"mappings":";;;;;;;;;;;;;;AAeA,MAAM,6BAA6B,CAAC,kBAAkB,qBAAqB;AAI3E,MAAa,wBAAyD,IAAI,IACxE,0BACF;;;;;;;;;;;AAYA,SAAgB,gBAAgB,SAAyC;CACvE,KAAK,MAAM,QAAQ,SACjB,IAAI,KAAK,OAAO,WAAW,GACzB,MAAM,IAAI,MACR,kGACF;CAGJ,OAAO,QAAQ,MAAM,SAAU,sBAA8C,IAAI,KAAK,MAAM,CAAC;AAC/F;;;;;;;;;;;;;;;;;AC7BA,MAAM,2BAA2B;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,4BAA4B;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAQA,MAAa,sBAAqD,IAAI,IAAI,wBAAwB;AAClG,MAAa,uBAAuD,IAAI,IACtE,yBACF;AACA,MAAa,4BAAqD;AAElE,SAAgB,mBAAmB,MAAwC;CACzE,OAAQ,oBAA4C,IAAI,IAAI;AAC9D;AAEA,SAAgB,oBAAoB,MAAyC;CAC3E,OAAQ,qBAA6C,IAAI,IAAI;AAC/D;AAEA,SAAgB,0BAA0B,MAA+C;CACvF,OAAO,SAAS;AAClB;;;;;;;;;ACjDA,MAAa,mCAAmC;;;;;;;;;;;;;;;;;;;;;AAsBhD,SAAgB,mBACd,MACA,KAC6B;CAK7B,MAAM,QAAQ,uBAAuB,KAAK,MAAM;CAEhD,IAAI,CAAC,gBAAgB,IAAI,KAAK,OAAO,GAAG,OAAO;CAK/C,MAAM,SAAS,MAAM,GAAG,EAAE;CAE1B,IAAI,0BAA0B,MAAM,GAAG;EAGrC,IAAI,MAAM,SAAS,GAAG,OAAO;EAC7B,OAAO;GACL,UAAU;GACV,YAAY;GACZ,WAAW,GAAG,iCAAiC;EACjD;CACF;CAMA,IAAI,MAAM,SAAS,GAAG,OAAO;CAE7B,IAAI,mBAAmB,MAAM,GAC3B,OAAO;EACL,UAAU;EACV,YAAY;EACZ,WAAW,GAAG,iCAAiC;CACjD;CAGF,IAAI,oBAAoB,MAAM,GAC5B,OAAO;EACL,UAAU;EACV,YAAY;EACZ,WAAW,GAAG,iCAAiC;CACjD;CAGF,OAAO;AACT;;;;;;;;AAeA,SAAS,uBAAuB,QAAkC;CAChE,IAAI,OAAO,WAAW,GACpB,MAAM,IAAI,MACR,gGACF;CAEF,MAAM,QAAQ,OAAO,MAAM,GAAG;CAC9B,KAAK,MAAM,WAAW,OACpB,IAAI,QAAQ,WAAW,GACrB,MAAM,IAAI,MACR,yCAAyC,OAAO,wEAClD;CAKJ,OAAO;AACT;;;;;;;;;;;;;;;ACpGA,MAAa,wBAAwB;CACnC,SAAS;CACT,MAAM;CACN,SAAS;CACT,MAAM;CACN,SAAS,EAAE,OAAO,IAAI;CACtB,UAAU;EACR,SAAS,CAAC;EACV,gBAAgB,CAAC;EACjB,UAAU,CAAC;EACX,iBAAiB,CAAC;EAClB,mBAAmB,CAAC,gCAAgC;EACpD,YAAY,CAAC;CACf;AACF;;;;;;;;;;;;;;ACRA,IAAM,sBAAN,MAAkD;CAChD,AAAS,WAAW;CAEpB,MAAM,KAAK,MAAoC,CAAC;CAEhD,SAAS,MAAqB,KAAmD;EAC/E,OAAO,mBAAmB,MAAM,GAAG;CACrC;AACF;;;;;;;;;AAUA,MAAa,sBAAsB,IAAI,oBAAoB"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/constants.ts","../src/imports.ts","../src/methods.ts","../src/classify.ts","../src/manifest.ts","../src/plugin.ts"],"sourcesContent":["// Plugin identity, kept in a leaf module so `classify.ts`, `imports.ts`, and `manifest.ts`\n// can all reach it without importing each other. Putting these next to the classifier\n// instead would make `imports.ts → classify.ts → imports.ts` a cycle.\n\n/**\n * Package-relative plugin name. Doubles as the prefix of every thrown message, so a caught\n * exception names the plugin that rejected the input. `manifest.ts` declares the same\n * string as `name`.\n */\nexport const EFFECTS_PRISMA_PLUGIN_NAME = \"effects-prisma\" as const\n\n/**\n * Shared derivedBy namespace. `manifest.ts` imports this same const for its\n * `derivedByPrefixes` entry, so the classifier's tag builder and the registry\n * declaration cannot drift.\n */\nexport const EFFECTS_PRISMA_DERIVED_BY_PREFIX = \"effects-plugin:prisma\" as const\n","import { hasMatchingImport } from \"@aburi/plugin-registry/plugin-input\"\nimport type { ImportEdge } from \"@aburi/types\"\nimport { EFFECTS_PRISMA_PLUGIN_NAME } from \"./constants\"\n\n/**\n * npm module specifiers that expose a `PrismaClient`. Any file that pulls in one of\n * these is treated as a Prisma consumer; files that reference the identifier without\n * importing Prisma are ignored so an unrelated `db.user.findMany()` from another ORM\n * does not get miscategorized.\n *\n * - `@prisma/client` — the default Prisma Client entry since v4.\n * - `@prisma/client/edge` — the Edge runtime entry used by Vercel Edge, Cloudflare\n * Workers, and Prisma Accelerate. Different bundle, same delegate surface.\n *\n * The set is a literal source of truth. Extending the plugin for community builds or a\n * future Prisma bundle is a table edit here.\n */\nconst PRISMA_CLIENT_MODULES_LIST = [\"@prisma/client\", \"@prisma/client/edge\"] as const\n\nexport type PrismaClientModule = (typeof PRISMA_CLIENT_MODULES_LIST)[number]\n\nexport const PRISMA_CLIENT_MODULES: ReadonlySet<PrismaClientModule> = new Set(\n PRISMA_CLIENT_MODULES_LIST,\n)\n\n/** Membership test against the closed set of Prisma Client entry points. */\nfunction isPrismaClientModule(source: string): boolean {\n return (PRISMA_CLIENT_MODULES as ReadonlySet<string>).has(source)\n}\n\n/**\n * True when the file's import list contains any recognized Prisma Client module. An\n * empty source string on an ImportEdge is rejected by the shared guard: the language\n * plugin's contract is to emit normalized non-empty specifiers, and treating `\"\"` as\n * unmatched would silently hide upstream bugs.\n *\n * `filePath` is required and threaded into any thrown error message so a caught\n * exception in production tooling (CI logs, error reporters) points directly at the\n * offending source file rather than a bare \"empty source\" string.\n */\nexport function hasPrismaImport(imports: readonly ImportEdge[], filePath: string): boolean {\n return hasMatchingImport(\n imports,\n { plugin: EFFECTS_PRISMA_PLUGIN_NAME, filePath },\n isPrismaClientModule,\n )\n}\n","/**\n * Prisma model delegate method vocabulary.\n *\n * Each `_LIST` is the single source of truth — the union type and the runtime `Set` are\n * both derived from it, so extending the vocabulary is a table edit in exactly one\n * place. Extending as Prisma ships new delegate methods keeps the classifier honest\n * without a code rewrite.\n *\n * Only methods that map cleanly onto core `db.read` / `db.write` vocabulary are listed.\n * Delegate helpers whose semantics do not match (metadata accessors, raw SQL escapes,\n * connection lifecycle) stay out — the plugin returns `null` for them so downstream\n * effect plugins get a chance.\n */\nconst PRISMA_READ_METHODS_LIST = [\n \"findUnique\",\n \"findUniqueOrThrow\",\n \"findFirst\",\n \"findFirstOrThrow\",\n \"findMany\",\n \"count\",\n \"aggregate\",\n \"groupBy\",\n] as const\n\nconst PRISMA_WRITE_METHODS_LIST = [\n \"create\",\n \"createMany\",\n \"createManyAndReturn\",\n \"update\",\n \"updateMany\",\n \"updateManyAndReturn\",\n \"upsert\",\n \"delete\",\n \"deleteMany\",\n] as const\n\nexport type PrismaReadMethod = (typeof PRISMA_READ_METHODS_LIST)[number]\nexport type PrismaWriteMethod = (typeof PRISMA_WRITE_METHODS_LIST)[number]\n\n/** Top-level client method: `prisma.$transaction(...)`. Not nested under a model. */\nexport type PrismaTransactionMethod = \"$transaction\"\n\nexport const PRISMA_READ_METHODS: ReadonlySet<PrismaReadMethod> = new Set(PRISMA_READ_METHODS_LIST)\nexport const PRISMA_WRITE_METHODS: ReadonlySet<PrismaWriteMethod> = new Set(\n PRISMA_WRITE_METHODS_LIST,\n)\nexport const PRISMA_TRANSACTION_METHOD: PrismaTransactionMethod = \"$transaction\"\n\nexport function isPrismaReadMethod(name: string): name is PrismaReadMethod {\n return (PRISMA_READ_METHODS as ReadonlySet<string>).has(name)\n}\n\nexport function isPrismaWriteMethod(name: string): name is PrismaWriteMethod {\n return (PRISMA_WRITE_METHODS as ReadonlySet<string>).has(name)\n}\n\nexport function isPrismaTransactionMethod(name: string): name is PrismaTransactionMethod {\n return name === PRISMA_TRANSACTION_METHOD\n}\n","import { assertNonEmptySegments, type PluginInputOrigin } from \"@aburi/plugin-registry/plugin-input\"\nimport type { CallCandidate, ClassifyContext, EffectClassification } from \"@aburi/types\"\nimport { EFFECTS_PRISMA_DERIVED_BY_PREFIX, EFFECTS_PRISMA_PLUGIN_NAME } from \"./constants\"\nimport { hasPrismaImport } from \"./imports\"\nimport { isPrismaReadMethod, isPrismaTransactionMethod, isPrismaWriteMethod } from \"./methods\"\n\n/**\n * Classify a CallCandidate against Prisma Client conventions.\n *\n * Recognition strategy:\n * 1. The owning file must import a Prisma Client module (see `hasPrismaImport`). No\n * import → `null`, so callers can chain other effect plugins after this one.\n * 2. The target is split on `.`; the plugin looks at the trailing segments to match\n * Prisma's fixed client surface. Two shapes are accepted:\n * - `<...>.<model>.<verb>` (3+ segments) — a model delegate call. The client\n * segment stops two-segment method collisions (Express `router.create(...)`)\n * from false-classifying.\n * - `<...>.$transaction` (2+ segments) — the top-level transaction API on the\n * client itself.\n * 3. Malformed targets (empty string, adjacent / leading / trailing dots) throw — the\n * language plugin's contract is a normalized non-empty callee, so a violation\n * here is an upstream bug we surface loudly instead of silently miscategorizing.\n *\n * The function is a pure lookup — no I/O, no state, no async — matching the per-call\n * timeout budget the core enforces (effect-plugin.md §5.1.1).\n */\nexport function classifyPrismaCall(\n call: CallCandidate,\n ctx: ClassifyContext,\n): EffectClassification | null {\n const origin: PluginInputOrigin = { plugin: EFFECTS_PRISMA_PLUGIN_NAME, filePath: ctx.file.path }\n\n // Fail-fast runs BEFORE the import gate — see `assertNonEmptySegments` for why the\n // order is load-bearing.\n const { segments: parts, last: method } = assertNonEmptySegments(call.target, origin)\n\n if (!hasPrismaImport(ctx.file.imports, ctx.file.path)) return null\n\n if (isPrismaTransactionMethod(method)) {\n // Bare `$transaction()` (single segment) is not a Prisma call — the transaction\n // API only makes sense as a method on the client (`<client>.$transaction(...)`).\n if (parts.length < 2) return null\n return {\n effectId: \"db.transaction\",\n confidence: \"high\",\n derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:tx`,\n }\n }\n\n // Model delegate calls need `<client>.<model>.<verb>` to distinguish them from\n // unrelated two-segment method calls (Express `router.create(...)`, an Array's\n // hypothetical `.findMany` collision) that would otherwise false-positive in files\n // that colocate Prisma with another library.\n if (parts.length < 3) return null\n\n if (isPrismaReadMethod(method)) {\n return {\n effectId: \"db.read\",\n confidence: \"high\",\n derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:read`,\n }\n }\n\n if (isPrismaWriteMethod(method)) {\n return {\n effectId: \"db.write\",\n confidence: \"high\",\n derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:write`,\n }\n }\n\n return null\n}\n","import type { EffectsManifest } from \"@aburi/types\"\nimport { EFFECTS_PRISMA_DERIVED_BY_PREFIX, EFFECTS_PRISMA_PLUGIN_NAME } from \"./constants\"\n\n/**\n * Manifest for `@aburi/effects-prisma`. `as const satisfies EffectsManifest` keeps\n * every literal narrow so downstream registry checks see the exact shape.\n *\n * The plugin returns core-owned effect ids (`db.read` / `db.write` / `db.transaction`)\n * from `classify()`; per extension-vocab.md §5.1 core vocab lives in the reserved\n * namespace and MUST NOT appear in a plugin's `provides.effects`. The plugin's own\n * `x-prisma:*` namespace currently has no bindings — model-specific effects would sit there\n * once introduced. `derivedByPrefixes` shares its literal with the classifier's tag\n * builder so both stay in lockstep across edits.\n */\nexport const effectsPrismaManifest = {\n $schema: \"https://aburi.dev/schema/aburi.plugin.v1.json\",\n name: EFFECTS_PRISMA_PLUGIN_NAME,\n version: \"0.0.0\",\n type: \"effects\",\n engines: { aburi: \"*\" },\n provides: {\n effects: [],\n effectPrefixes: [],\n extKinds: [],\n extKindPrefixes: [],\n derivedByPrefixes: [EFFECTS_PRISMA_DERIVED_BY_PREFIX],\n frameworks: [],\n },\n} as const satisfies EffectsManifest\n","import type {\n CallCandidate,\n ClassifyContext,\n EffectClassification,\n EffectPlugin,\n PluginContext,\n} from \"@aburi/types\"\nimport { classifyPrismaCall } from \"./classify\"\nimport { effectsPrismaManifest } from \"./manifest\"\n\n/**\n * Prisma effect plugin. Sits behind the language plugin's `walkBody` output, mapping\n * `prisma.<model>.<verb>` and `prisma.$transaction` call expressions into the core\n * `db.read` / `db.write` / `db.transaction` effect vocabulary.\n *\n * `init` and `classify` are both pure with respect to plugin state — no lazy resources,\n * no per-run caches — so repeated invocations against the same CallCandidate produce\n * identical results. This matches the per-call timeout contract in\n * effect-plugin.md §5.1.1 and the \"pure classifier\" recommendation in §11.1.\n */\nclass PrismaEffectsPlugin implements EffectPlugin {\n readonly manifest = effectsPrismaManifest\n\n async init(_ctx: PluginContext): Promise<void> {}\n\n classify(call: CallCandidate, ctx: ClassifyContext): EffectClassification | null {\n return classifyPrismaCall(call, ctx)\n }\n}\n\n/**\n * Ready-to-register instance. Callers pass this to `@aburi/plugin-registry` or a scan\n * pipeline. The type annotation is omitted deliberately: `class implements EffectPlugin`\n * already enforces the structural contract, and inferring the narrow class type keeps\n * the manifest literals (`readonly [\"effects-plugin:prisma\"]`, `\"effects-prisma\"`)\n * visible to consumers that want to compare against them without a separate manifest\n * import.\n */\nexport const prismaEffectsPlugin = new PrismaEffectsPlugin()\n\nexport { PrismaEffectsPlugin }\n"],"mappings":";;;;;;;;AASA,MAAa,6BAA6B;;;;;;AAO1C,MAAa,mCAAmC;;;;;;;;;;;;;;;;;ACChD,MAAM,6BAA6B,CAAC,kBAAkB,qBAAqB;AAI3E,MAAa,wBAAyD,IAAI,IACxE,0BACF;;AAGA,SAAS,qBAAqB,QAAyB;CACrD,OAAQ,sBAA8C,IAAI,MAAM;AAClE;;;;;;;;;;;AAYA,SAAgB,gBAAgB,SAAgC,UAA2B;CACzF,OAAO,kBACL,SACA;EAAE,QAAQ;EAA4B;CAAS,GAC/C,oBACF;AACF;;;;;;;;;;;;;;;;;ACjCA,MAAM,2BAA2B;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,4BAA4B;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAQA,MAAa,sBAAqD,IAAI,IAAI,wBAAwB;AAClG,MAAa,uBAAuD,IAAI,IACtE,yBACF;AACA,MAAa,4BAAqD;AAElE,SAAgB,mBAAmB,MAAwC;CACzE,OAAQ,oBAA4C,IAAI,IAAI;AAC9D;AAEA,SAAgB,oBAAoB,MAAyC;CAC3E,OAAQ,qBAA6C,IAAI,IAAI;AAC/D;AAEA,SAAgB,0BAA0B,MAA+C;CACvF,OAAO,SAAS;AAClB;;;;;;;;;;;;;;;;;;;;;;;;AChCA,SAAgB,mBACd,MACA,KAC6B;CAC7B,MAAM,SAA4B;EAAE,QAAQ;EAA4B,UAAU,IAAI,KAAK;CAAK;CAIhG,MAAM,EAAE,UAAU,OAAO,MAAM,WAAW,uBAAuB,KAAK,QAAQ,MAAM;CAEpF,IAAI,CAAC,gBAAgB,IAAI,KAAK,SAAS,IAAI,KAAK,IAAI,GAAG,OAAO;CAE9D,IAAI,0BAA0B,MAAM,GAAG;EAGrC,IAAI,MAAM,SAAS,GAAG,OAAO;EAC7B,OAAO;GACL,UAAU;GACV,YAAY;GACZ,WAAW,GAAG,iCAAiC;EACjD;CACF;CAMA,IAAI,MAAM,SAAS,GAAG,OAAO;CAE7B,IAAI,mBAAmB,MAAM,GAC3B,OAAO;EACL,UAAU;EACV,YAAY;EACZ,WAAW,GAAG,iCAAiC;CACjD;CAGF,IAAI,oBAAoB,MAAM,GAC5B,OAAO;EACL,UAAU;EACV,YAAY;EACZ,WAAW,GAAG,iCAAiC;CACjD;CAGF,OAAO;AACT;;;;;;;;;;;;;;;AC1DA,MAAa,wBAAwB;CACnC,SAAS;CACT,MAAM;CACN,SAAS;CACT,MAAM;CACN,SAAS,EAAE,OAAO,IAAI;CACtB,UAAU;EACR,SAAS,CAAC;EACV,gBAAgB,CAAC;EACjB,UAAU,CAAC;EACX,iBAAiB,CAAC;EAClB,mBAAmB,CAAC,gCAAgC;EACpD,YAAY,CAAC;CACf;AACF;;;;;;;;;;;;;;ACRA,IAAM,sBAAN,MAAkD;CAChD,AAAS,WAAW;CAEpB,MAAM,KAAK,MAAoC,CAAC;CAEhD,SAAS,MAAqB,KAAmD;EAC/E,OAAO,mBAAmB,MAAM,GAAG;CACrC;AACF;;;;;;;;;AAUA,MAAa,sBAAsB,IAAI,oBAAoB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aburi/effects-prisma",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Aburi Prisma effects plugin: classifies prisma.<model>.<verb> and prisma.$transaction call expressions into core db.read / db.write / db.transaction effects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "kage1020",
|
|
@@ -33,14 +33,15 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@aburi/types": "0.
|
|
36
|
+
"@aburi/types": "0.2.0",
|
|
37
|
+
"@aburi/plugin-registry": "0.2.0"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@types/node": "^26.0.1",
|
|
40
41
|
"tsdown": "^0.22.3",
|
|
41
42
|
"typescript": "^6.0.3",
|
|
42
43
|
"vitest": "^4.1.9",
|
|
43
|
-
"@aburi/lang-typescript": "0.
|
|
44
|
+
"@aburi/lang-typescript": "0.2.0"
|
|
44
45
|
},
|
|
45
46
|
"scripts": {
|
|
46
47
|
"build": "tsdown",
|
package/src/classify.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
+
import { assertNonEmptySegments, type PluginInputOrigin } from "@aburi/plugin-registry/plugin-input"
|
|
1
2
|
import type { CallCandidate, ClassifyContext, EffectClassification } from "@aburi/types"
|
|
3
|
+
import { EFFECTS_PRISMA_DERIVED_BY_PREFIX, EFFECTS_PRISMA_PLUGIN_NAME } from "./constants"
|
|
2
4
|
import { hasPrismaImport } from "./imports"
|
|
3
5
|
import { isPrismaReadMethod, isPrismaTransactionMethod, isPrismaWriteMethod } from "./methods"
|
|
4
6
|
|
|
5
|
-
/**
|
|
6
|
-
* Shared derivedBy namespace. `manifest.ts` imports this same const for its
|
|
7
|
-
* `derivedByPrefixes` entry, so the classifier's tag builder and the registry
|
|
8
|
-
* declaration cannot drift.
|
|
9
|
-
*/
|
|
10
|
-
export const EFFECTS_PRISMA_DERIVED_BY_PREFIX = "effects-plugin:prisma" as const
|
|
11
|
-
|
|
12
7
|
/**
|
|
13
8
|
* Classify a CallCandidate against Prisma Client conventions.
|
|
14
9
|
*
|
|
@@ -33,18 +28,13 @@ export function classifyPrismaCall(
|
|
|
33
28
|
call: CallCandidate,
|
|
34
29
|
ctx: ClassifyContext,
|
|
35
30
|
): EffectClassification | null {
|
|
36
|
-
|
|
37
|
-
// not just the ~1% that import Prisma. Ordering the other way lets the same bug
|
|
38
|
-
// surface only in Prisma-consuming files and stay silent everywhere else —
|
|
39
|
-
// catastrophic for reproducing upstream language-plugin bugs.
|
|
40
|
-
const parts = assertNonEmptySegments(call.target)
|
|
31
|
+
const origin: PluginInputOrigin = { plugin: EFFECTS_PRISMA_PLUGIN_NAME, filePath: ctx.file.path }
|
|
41
32
|
|
|
42
|
-
|
|
33
|
+
// Fail-fast runs BEFORE the import gate — see `assertNonEmptySegments` for why the
|
|
34
|
+
// order is load-bearing.
|
|
35
|
+
const { segments: parts, last: method } = assertNonEmptySegments(call.target, origin)
|
|
43
36
|
|
|
44
|
-
|
|
45
|
-
// signature still widens to `string | undefined`. `.at(-1) as string` records the
|
|
46
|
-
// intent without a non-null assertion (Biome disallows `!` under noNonNullAssertion).
|
|
47
|
-
const method = parts.at(-1) as string
|
|
37
|
+
if (!hasPrismaImport(ctx.file.imports, ctx.file.path)) return null
|
|
48
38
|
|
|
49
39
|
if (isPrismaTransactionMethod(method)) {
|
|
50
40
|
// Bare `$transaction()` (single segment) is not a Prisma call — the transaction
|
|
@@ -81,35 +71,3 @@ export function classifyPrismaCall(
|
|
|
81
71
|
|
|
82
72
|
return null
|
|
83
73
|
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* A non-empty split — after `assertNonEmptySegments` runs there is guaranteed to be at
|
|
87
|
-
* least one segment, so the tuple type reflects that.
|
|
88
|
-
*/
|
|
89
|
-
type NonEmptySegments = readonly [string, ...string[]]
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Split `target` on `.` and reject any shape a well-formed language plugin would never
|
|
93
|
-
* emit: an empty target, or one with an empty segment (leading, trailing, or adjacent
|
|
94
|
-
* dots). A malformed target here would otherwise slip through the length gate and
|
|
95
|
-
* false-classify — e.g. `"prisma..create"` has three segments and would match a write
|
|
96
|
-
* verb — so this is the fail-fast the sibling classifiers apply at their entry points.
|
|
97
|
-
*/
|
|
98
|
-
function assertNonEmptySegments(target: string): NonEmptySegments {
|
|
99
|
-
if (target.length === 0) {
|
|
100
|
-
throw new Error(
|
|
101
|
-
"effects-prisma: CallCandidate.target is empty — language plugin emitted an unnormalized callee",
|
|
102
|
-
)
|
|
103
|
-
}
|
|
104
|
-
const parts = target.split(".")
|
|
105
|
-
for (const segment of parts) {
|
|
106
|
-
if (segment.length === 0) {
|
|
107
|
-
throw new Error(
|
|
108
|
-
`effects-prisma: CallCandidate.target "${target}" has empty segment(s) — language plugin emitted an unnormalized callee`,
|
|
109
|
-
)
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
// Split of a non-empty string yields at least one segment, and the loop above ruled
|
|
113
|
-
// out empty segments — the tuple assertion here reflects a proven invariant.
|
|
114
|
-
return parts as unknown as NonEmptySegments
|
|
115
|
-
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Plugin identity, kept in a leaf module so `classify.ts`, `imports.ts`, and `manifest.ts`
|
|
2
|
+
// can all reach it without importing each other. Putting these next to the classifier
|
|
3
|
+
// instead would make `imports.ts → classify.ts → imports.ts` a cycle.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Package-relative plugin name. Doubles as the prefix of every thrown message, so a caught
|
|
7
|
+
* exception names the plugin that rejected the input. `manifest.ts` declares the same
|
|
8
|
+
* string as `name`.
|
|
9
|
+
*/
|
|
10
|
+
export const EFFECTS_PRISMA_PLUGIN_NAME = "effects-prisma" as const
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Shared derivedBy namespace. `manifest.ts` imports this same const for its
|
|
14
|
+
* `derivedByPrefixes` entry, so the classifier's tag builder and the registry
|
|
15
|
+
* declaration cannot drift.
|
|
16
|
+
*/
|
|
17
|
+
export const EFFECTS_PRISMA_DERIVED_BY_PREFIX = "effects-plugin:prisma" as const
|
package/src/imports.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { hasMatchingImport } from "@aburi/plugin-registry/plugin-input"
|
|
1
2
|
import type { ImportEdge } from "@aburi/types"
|
|
3
|
+
import { EFFECTS_PRISMA_PLUGIN_NAME } from "./constants"
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* npm module specifiers that expose a `PrismaClient`. Any file that pulls in one of
|
|
@@ -21,23 +23,25 @@ export const PRISMA_CLIENT_MODULES: ReadonlySet<PrismaClientModule> = new Set(
|
|
|
21
23
|
PRISMA_CLIENT_MODULES_LIST,
|
|
22
24
|
)
|
|
23
25
|
|
|
26
|
+
/** Membership test against the closed set of Prisma Client entry points. */
|
|
27
|
+
function isPrismaClientModule(source: string): boolean {
|
|
28
|
+
return (PRISMA_CLIENT_MODULES as ReadonlySet<string>).has(source)
|
|
29
|
+
}
|
|
30
|
+
|
|
24
31
|
/**
|
|
25
32
|
* True when the file's import list contains any recognized Prisma Client module. An
|
|
26
|
-
* empty source string on an ImportEdge is rejected
|
|
27
|
-
* to emit normalized non-empty specifiers, and treating `""` as
|
|
28
|
-
* hide upstream bugs.
|
|
33
|
+
* empty source string on an ImportEdge is rejected by the shared guard: the language
|
|
34
|
+
* plugin's contract is to emit normalized non-empty specifiers, and treating `""` as
|
|
35
|
+
* unmatched would silently hide upstream bugs.
|
|
29
36
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
37
|
+
* `filePath` is required and threaded into any thrown error message so a caught
|
|
38
|
+
* exception in production tooling (CI logs, error reporters) points directly at the
|
|
39
|
+
* offending source file rather than a bare "empty source" string.
|
|
33
40
|
*/
|
|
34
|
-
export function hasPrismaImport(imports: readonly ImportEdge[]): boolean {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return imports.some((edge) => (PRISMA_CLIENT_MODULES as ReadonlySet<string>).has(edge.source))
|
|
41
|
+
export function hasPrismaImport(imports: readonly ImportEdge[], filePath: string): boolean {
|
|
42
|
+
return hasMatchingImport(
|
|
43
|
+
imports,
|
|
44
|
+
{ plugin: EFFECTS_PRISMA_PLUGIN_NAME, filePath },
|
|
45
|
+
isPrismaClientModule,
|
|
46
|
+
)
|
|
43
47
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { classifyPrismaCall
|
|
1
|
+
export { classifyPrismaCall } from "./classify"
|
|
2
|
+
export { EFFECTS_PRISMA_DERIVED_BY_PREFIX, EFFECTS_PRISMA_PLUGIN_NAME } from "./constants"
|
|
2
3
|
export { hasPrismaImport } from "./imports"
|
|
3
4
|
export { effectsPrismaManifest } from "./manifest"
|
|
4
5
|
export {
|
package/src/manifest.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EffectsManifest } from "@aburi/types"
|
|
2
|
-
import { EFFECTS_PRISMA_DERIVED_BY_PREFIX } from "./
|
|
2
|
+
import { EFFECTS_PRISMA_DERIVED_BY_PREFIX, EFFECTS_PRISMA_PLUGIN_NAME } from "./constants"
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Manifest for `@aburi/effects-prisma`. `as const satisfies EffectsManifest` keeps
|
|
@@ -8,13 +8,13 @@ import { EFFECTS_PRISMA_DERIVED_BY_PREFIX } from "./classify"
|
|
|
8
8
|
* The plugin returns core-owned effect ids (`db.read` / `db.write` / `db.transaction`)
|
|
9
9
|
* from `classify()`; per extension-vocab.md §5.1 core vocab lives in the reserved
|
|
10
10
|
* namespace and MUST NOT appear in a plugin's `provides.effects`. The plugin's own
|
|
11
|
-
* `x-prisma:*` namespace has no
|
|
11
|
+
* `x-prisma:*` namespace currently has no bindings — model-specific effects would sit there
|
|
12
12
|
* once introduced. `derivedByPrefixes` shares its literal with the classifier's tag
|
|
13
13
|
* builder so both stay in lockstep across edits.
|
|
14
14
|
*/
|
|
15
15
|
export const effectsPrismaManifest = {
|
|
16
16
|
$schema: "https://aburi.dev/schema/aburi.plugin.v1.json",
|
|
17
|
-
name:
|
|
17
|
+
name: EFFECTS_PRISMA_PLUGIN_NAME,
|
|
18
18
|
version: "0.0.0",
|
|
19
19
|
type: "effects",
|
|
20
20
|
engines: { aburi: "*" },
|