@aburi/effects-prisma 0.1.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/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # @aburi/effects-prisma
2
+
3
+ Prisma effect plugin for `@aburi/core`. Classifies Prisma client calls into core
4
+ effect vocabulary so the IR can distinguish "reads the database" from "writes
5
+ the database" without needing to render every raw call.
6
+
7
+ Recognised shapes:
8
+
9
+ | Source shape | Effect |
10
+ |---|---|
11
+ | `<client>.<model>.findUnique / findUniqueOrThrow / findFirst / findFirstOrThrow / findMany / count / aggregate / groupBy` | `db.read` |
12
+ | `<client>.<model>.create / createMany / createManyAndReturn / update / updateMany / updateManyAndReturn / upsert / delete / deleteMany` | `db.write` |
13
+ | `<client>.$transaction(...)` | `db.transaction` |
14
+
15
+ Raw SQL (`$queryRaw` / `$executeRaw` / `$queryRawUnsafe` / `$executeRawUnsafe`)
16
+ is intentionally **not** classified in v0.1 — statically distinguishing a read
17
+ raw query from a write raw query would require SQL parsing, which is out of the
18
+ current scope. A future revision may add it under a `medium` confidence tier.
19
+
20
+ Layered gate: a file that imports `@prisma/client` (or a re-export chain that
21
+ lands there) is a prerequisite, and the target must have at least three
22
+ `.`-separated segments (`<client>.<model>.<verb>`) so a random `foo.findMany()`
23
+ call in an unrelated file will not false-classify. Bare `$transaction()`
24
+ without a client segment is also skipped.
25
+
26
+ ## Install
27
+
28
+ ```bash
29
+ pnpm add @aburi/effects-prisma
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ```ts
35
+ import { prismaEffectsPlugin } from "@aburi/effects-prisma"
36
+ ```
37
+
38
+ ## See also
39
+
40
+ - [`design/details/effect-plugin.md`](../../design/details/effect-plugin.md)
@@ -0,0 +1,145 @@
1
+ import { CallCandidate, ClassifyContext, EffectClassification, EffectPlugin, ImportEdge, PluginContext } from "@aburi/types";
2
+
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
+ /**
11
+ * Classify a CallCandidate against Prisma Client conventions.
12
+ *
13
+ * Recognition strategy:
14
+ * 1. The owning file must import a Prisma Client module (see `hasPrismaImport`). No
15
+ * import → `null`, so callers can chain other effect plugins after this one.
16
+ * 2. The target is split on `.`; the plugin looks at the trailing segments to match
17
+ * Prisma's fixed client surface. Two shapes are accepted:
18
+ * - `<...>.<model>.<verb>` (3+ segments) — a model delegate call. The client
19
+ * segment stops two-segment method collisions (Express `router.create(...)`)
20
+ * from false-classifying.
21
+ * - `<...>.$transaction` (2+ segments) — the top-level transaction API on the
22
+ * client itself.
23
+ * 3. Malformed targets (empty string, adjacent / leading / trailing dots) throw — the
24
+ * language plugin's contract is a normalized non-empty callee, so a violation
25
+ * here is an upstream bug we surface loudly instead of silently miscategorizing.
26
+ *
27
+ * The function is a pure lookup — no I/O, no state, no async — matching the per-call
28
+ * timeout budget the core enforces (effect-plugin.md §5.1.1).
29
+ */
30
+ declare function classifyPrismaCall(call: CallCandidate, ctx: ClassifyContext): EffectClassification | null;
31
+ //#endregion
32
+ //#region src/imports.d.ts
33
+ /**
34
+ * True when the file's import list contains any recognized Prisma Client module. An
35
+ * empty source string on an ImportEdge is rejected: the language plugin's contract is
36
+ * to emit normalized non-empty specifiers, and treating `""` as unmatched would silently
37
+ * hide upstream bugs.
38
+ *
39
+ * Validation runs across every edge before the match check so ImportEdge order does
40
+ * not make throw behavior non-deterministic. Using `.some()` alone would short-circuit
41
+ * on the first match and never notice a broken edge that happens to sit later.
42
+ */
43
+ declare function hasPrismaImport(imports: readonly ImportEdge[]): boolean;
44
+ //#endregion
45
+ //#region src/manifest.d.ts
46
+ /**
47
+ * Manifest for `@aburi/effects-prisma`. `as const satisfies EffectsManifest` keeps
48
+ * every literal narrow so downstream registry checks see the exact shape.
49
+ *
50
+ * The plugin returns core-owned effect ids (`db.read` / `db.write` / `db.transaction`)
51
+ * from `classify()`; per extension-vocab.md §5.1 core vocab lives in the reserved
52
+ * namespace and MUST NOT appear in a plugin's `provides.effects`. The plugin's own
53
+ * `x-prisma:*` namespace has no v0.1 bindings — model-specific effects would sit there
54
+ * once introduced. `derivedByPrefixes` shares its literal with the classifier's tag
55
+ * builder so both stay in lockstep across edits.
56
+ */
57
+ declare const effectsPrismaManifest: {
58
+ readonly $schema: "https://aburi.dev/schema/aburi.plugin.v1.json";
59
+ readonly name: "effects-prisma";
60
+ readonly version: "0.0.0";
61
+ readonly type: "effects";
62
+ readonly engines: {
63
+ readonly aburi: "*";
64
+ };
65
+ readonly provides: {
66
+ readonly effects: [];
67
+ readonly effectPrefixes: [];
68
+ readonly extKinds: [];
69
+ readonly extKindPrefixes: [];
70
+ readonly derivedByPrefixes: ["effects-plugin:prisma"];
71
+ readonly frameworks: [];
72
+ };
73
+ };
74
+ //#endregion
75
+ //#region src/methods.d.ts
76
+ /**
77
+ * Prisma model delegate method vocabulary.
78
+ *
79
+ * Each `_LIST` is the single source of truth — the union type and the runtime `Set` are
80
+ * both derived from it, so extending the vocabulary is a table edit in exactly one
81
+ * place. Extending as Prisma ships new delegate methods keeps the classifier honest
82
+ * without a code rewrite.
83
+ *
84
+ * Only methods that map cleanly onto core `db.read` / `db.write` vocabulary are listed.
85
+ * Delegate helpers whose semantics do not match (metadata accessors, raw SQL escapes,
86
+ * connection lifecycle) stay out — the plugin returns `null` for them so downstream
87
+ * effect plugins get a chance.
88
+ */
89
+ declare const PRISMA_READ_METHODS_LIST: readonly ["findUnique", "findUniqueOrThrow", "findFirst", "findFirstOrThrow", "findMany", "count", "aggregate", "groupBy"];
90
+ declare const PRISMA_WRITE_METHODS_LIST: readonly ["create", "createMany", "createManyAndReturn", "update", "updateMany", "updateManyAndReturn", "upsert", "delete", "deleteMany"];
91
+ type PrismaReadMethod = (typeof PRISMA_READ_METHODS_LIST)[number];
92
+ type PrismaWriteMethod = (typeof PRISMA_WRITE_METHODS_LIST)[number];
93
+ /** Top-level client method: `prisma.$transaction(...)`. Not nested under a model. */
94
+ type PrismaTransactionMethod = "$transaction";
95
+ declare const PRISMA_READ_METHODS: ReadonlySet<PrismaReadMethod>;
96
+ declare const PRISMA_WRITE_METHODS: ReadonlySet<PrismaWriteMethod>;
97
+ declare const PRISMA_TRANSACTION_METHOD: PrismaTransactionMethod;
98
+ declare function isPrismaReadMethod(name: string): name is PrismaReadMethod;
99
+ declare function isPrismaWriteMethod(name: string): name is PrismaWriteMethod;
100
+ declare function isPrismaTransactionMethod(name: string): name is PrismaTransactionMethod;
101
+ //#endregion
102
+ //#region src/plugin.d.ts
103
+ /**
104
+ * Prisma effect plugin. Sits behind the language plugin's `walkBody` output, mapping
105
+ * `prisma.<model>.<verb>` and `prisma.$transaction` call expressions into the core
106
+ * `db.read` / `db.write` / `db.transaction` effect vocabulary.
107
+ *
108
+ * `init` and `classify` are both pure with respect to plugin state — no lazy resources,
109
+ * no per-run caches — so repeated invocations against the same CallCandidate produce
110
+ * identical results. This matches the per-call timeout contract in
111
+ * effect-plugin.md §5.1.1 and the "pure classifier" recommendation in §11.1.
112
+ */
113
+ declare class PrismaEffectsPlugin implements EffectPlugin {
114
+ readonly manifest: {
115
+ readonly $schema: "https://aburi.dev/schema/aburi.plugin.v1.json";
116
+ readonly name: "effects-prisma";
117
+ readonly version: "0.0.0";
118
+ readonly type: "effects";
119
+ readonly engines: {
120
+ readonly aburi: "*";
121
+ };
122
+ readonly provides: {
123
+ readonly effects: [];
124
+ readonly effectPrefixes: [];
125
+ readonly extKinds: [];
126
+ readonly extKindPrefixes: [];
127
+ readonly derivedByPrefixes: ["effects-plugin:prisma"];
128
+ readonly frameworks: [];
129
+ };
130
+ };
131
+ init(_ctx: PluginContext): Promise<void>;
132
+ classify(call: CallCandidate, ctx: ClassifyContext): EffectClassification | null;
133
+ }
134
+ /**
135
+ * Ready-to-register instance. Callers pass this to `@aburi/plugin-registry` or a scan
136
+ * pipeline. The type annotation is omitted deliberately: `class implements EffectPlugin`
137
+ * already enforces the structural contract, and inferring the narrow class type keeps
138
+ * the manifest literals (`readonly ["effects-plugin:prisma"]`, `"effects-prisma"`)
139
+ * visible to consumers that want to compare against them without a separate manifest
140
+ * import.
141
+ */
142
+ declare const prismaEffectsPlugin: PrismaEffectsPlugin;
143
+ //#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 };
145
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +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":";;;;;AASA;;;cAAa,gCAAA;AAAmE;AAsBhF;;;;;;;;;;;;;;AAGuB;;;;ACDvB;ADxBgF,iBAsBhE,kBAAA,CACd,IAAA,EAAM,aAAA,EACN,GAAA,EAAK,eAAA,GACJ,oBAAA;;;;;;;;AAAoB;;;;ACDvB;iBAAgB,eAAA,CAAgB,OAA8B,WAAZ,UAAU;;;;;;ADxB5D;;;;AAAgF;AAsBhF;;;cEjBa,qBAAA;EAAA;;;;;;;;;;;;;;;;;;;;;AFLb;;;;AAAgF;AAsBhF;;;;;cGlBM,wBAAA;AAAA,cAWA,yBAAA;AAAA,KAYM,gBAAA,WAA2B,wBAAwB;AAAA,KACnD,iBAAA,WAA4B,yBAAyB;;KAGrD,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;;;;;AH/CxF;;;;AAAgF;AAsBhF;;;cIXM,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;;;AFXvD;;;;;;cEwBa,mBAAA,EAAmB,mBAA4B"}
package/dist/index.mjs ADDED
@@ -0,0 +1,208 @@
1
+ //#region src/imports.ts
2
+ /**
3
+ * npm module specifiers that expose a `PrismaClient`. Any file that pulls in one of
4
+ * these is treated as a Prisma consumer; files that reference the identifier without
5
+ * importing Prisma are ignored so an unrelated `db.user.findMany()` from another ORM
6
+ * does not get miscategorized.
7
+ *
8
+ * - `@prisma/client` — the default Prisma Client entry since v4.
9
+ * - `@prisma/client/edge` — the Edge runtime entry used by Vercel Edge, Cloudflare
10
+ * Workers, and Prisma Accelerate. Different bundle, same delegate surface.
11
+ *
12
+ * The set is a literal source of truth. Extending the plugin for community builds or a
13
+ * future Prisma bundle is a table edit here.
14
+ */
15
+ const PRISMA_CLIENT_MODULES_LIST = ["@prisma/client", "@prisma/client/edge"];
16
+ const PRISMA_CLIENT_MODULES = new Set(PRISMA_CLIENT_MODULES_LIST);
17
+ /**
18
+ * True when the file's import list contains any recognized Prisma Client module. An
19
+ * empty source string on an ImportEdge is rejected: the language plugin's contract is
20
+ * to emit normalized non-empty specifiers, and treating `""` as unmatched would silently
21
+ * hide upstream bugs.
22
+ *
23
+ * Validation runs across every edge before the match check so ImportEdge order does
24
+ * not make throw behavior non-deterministic. Using `.some()` alone would short-circuit
25
+ * on the first match and never notice a broken edge that happens to sit later.
26
+ */
27
+ function hasPrismaImport(imports) {
28
+ for (const edge of imports) if (edge.source.length === 0) throw new Error("effects-prisma: ImportEdge.source is empty — language plugin emitted an unnormalized import edge");
29
+ return imports.some((edge) => PRISMA_CLIENT_MODULES.has(edge.source));
30
+ }
31
+
32
+ //#endregion
33
+ //#region src/methods.ts
34
+ /**
35
+ * Prisma model delegate method vocabulary.
36
+ *
37
+ * Each `_LIST` is the single source of truth — the union type and the runtime `Set` are
38
+ * both derived from it, so extending the vocabulary is a table edit in exactly one
39
+ * place. Extending as Prisma ships new delegate methods keeps the classifier honest
40
+ * without a code rewrite.
41
+ *
42
+ * Only methods that map cleanly onto core `db.read` / `db.write` vocabulary are listed.
43
+ * Delegate helpers whose semantics do not match (metadata accessors, raw SQL escapes,
44
+ * connection lifecycle) stay out — the plugin returns `null` for them so downstream
45
+ * effect plugins get a chance.
46
+ */
47
+ const PRISMA_READ_METHODS_LIST = [
48
+ "findUnique",
49
+ "findUniqueOrThrow",
50
+ "findFirst",
51
+ "findFirstOrThrow",
52
+ "findMany",
53
+ "count",
54
+ "aggregate",
55
+ "groupBy"
56
+ ];
57
+ const PRISMA_WRITE_METHODS_LIST = [
58
+ "create",
59
+ "createMany",
60
+ "createManyAndReturn",
61
+ "update",
62
+ "updateMany",
63
+ "updateManyAndReturn",
64
+ "upsert",
65
+ "delete",
66
+ "deleteMany"
67
+ ];
68
+ const PRISMA_READ_METHODS = new Set(PRISMA_READ_METHODS_LIST);
69
+ const PRISMA_WRITE_METHODS = new Set(PRISMA_WRITE_METHODS_LIST);
70
+ const PRISMA_TRANSACTION_METHOD = "$transaction";
71
+ function isPrismaReadMethod(name) {
72
+ return PRISMA_READ_METHODS.has(name);
73
+ }
74
+ function isPrismaWriteMethod(name) {
75
+ return PRISMA_WRITE_METHODS.has(name);
76
+ }
77
+ function isPrismaTransactionMethod(name) {
78
+ return name === PRISMA_TRANSACTION_METHOD;
79
+ }
80
+
81
+ //#endregion
82
+ //#region src/classify.ts
83
+ /**
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
+ * Classify a CallCandidate against Prisma Client conventions.
91
+ *
92
+ * Recognition strategy:
93
+ * 1. The owning file must import a Prisma Client module (see `hasPrismaImport`). No
94
+ * import → `null`, so callers can chain other effect plugins after this one.
95
+ * 2. The target is split on `.`; the plugin looks at the trailing segments to match
96
+ * Prisma's fixed client surface. Two shapes are accepted:
97
+ * - `<...>.<model>.<verb>` (3+ segments) — a model delegate call. The client
98
+ * segment stops two-segment method collisions (Express `router.create(...)`)
99
+ * from false-classifying.
100
+ * - `<...>.$transaction` (2+ segments) — the top-level transaction API on the
101
+ * client itself.
102
+ * 3. Malformed targets (empty string, adjacent / leading / trailing dots) throw — the
103
+ * language plugin's contract is a normalized non-empty callee, so a violation
104
+ * here is an upstream bug we surface loudly instead of silently miscategorizing.
105
+ *
106
+ * The function is a pure lookup — no I/O, no state, no async — matching the per-call
107
+ * timeout budget the core enforces (effect-plugin.md §5.1.1).
108
+ */
109
+ function classifyPrismaCall(call, ctx) {
110
+ const parts = assertNonEmptySegments(call.target);
111
+ if (!hasPrismaImport(ctx.file.imports)) return null;
112
+ const method = parts.at(-1);
113
+ if (isPrismaTransactionMethod(method)) {
114
+ if (parts.length < 2) return null;
115
+ return {
116
+ effectId: "db.transaction",
117
+ confidence: "high",
118
+ derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:tx`
119
+ };
120
+ }
121
+ if (parts.length < 3) return null;
122
+ if (isPrismaReadMethod(method)) return {
123
+ effectId: "db.read",
124
+ confidence: "high",
125
+ derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:read`
126
+ };
127
+ if (isPrismaWriteMethod(method)) return {
128
+ effectId: "db.write",
129
+ confidence: "high",
130
+ derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:write`
131
+ };
132
+ return null;
133
+ }
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
+
148
+ //#endregion
149
+ //#region src/manifest.ts
150
+ /**
151
+ * Manifest for `@aburi/effects-prisma`. `as const satisfies EffectsManifest` keeps
152
+ * every literal narrow so downstream registry checks see the exact shape.
153
+ *
154
+ * The plugin returns core-owned effect ids (`db.read` / `db.write` / `db.transaction`)
155
+ * from `classify()`; per extension-vocab.md §5.1 core vocab lives in the reserved
156
+ * namespace and MUST NOT appear in a plugin's `provides.effects`. The plugin's own
157
+ * `x-prisma:*` namespace has no v0.1 bindings — model-specific effects would sit there
158
+ * once introduced. `derivedByPrefixes` shares its literal with the classifier's tag
159
+ * builder so both stay in lockstep across edits.
160
+ */
161
+ const effectsPrismaManifest = {
162
+ $schema: "https://aburi.dev/schema/aburi.plugin.v1.json",
163
+ name: "effects-prisma",
164
+ version: "0.0.0",
165
+ type: "effects",
166
+ engines: { aburi: "*" },
167
+ provides: {
168
+ effects: [],
169
+ effectPrefixes: [],
170
+ extKinds: [],
171
+ extKindPrefixes: [],
172
+ derivedByPrefixes: [EFFECTS_PRISMA_DERIVED_BY_PREFIX],
173
+ frameworks: []
174
+ }
175
+ };
176
+
177
+ //#endregion
178
+ //#region src/plugin.ts
179
+ /**
180
+ * Prisma effect plugin. Sits behind the language plugin's `walkBody` output, mapping
181
+ * `prisma.<model>.<verb>` and `prisma.$transaction` call expressions into the core
182
+ * `db.read` / `db.write` / `db.transaction` effect vocabulary.
183
+ *
184
+ * `init` and `classify` are both pure with respect to plugin state — no lazy resources,
185
+ * no per-run caches — so repeated invocations against the same CallCandidate produce
186
+ * identical results. This matches the per-call timeout contract in
187
+ * effect-plugin.md §5.1.1 and the "pure classifier" recommendation in §11.1.
188
+ */
189
+ var PrismaEffectsPlugin = class {
190
+ manifest = effectsPrismaManifest;
191
+ async init(_ctx) {}
192
+ classify(call, ctx) {
193
+ return classifyPrismaCall(call, ctx);
194
+ }
195
+ };
196
+ /**
197
+ * Ready-to-register instance. Callers pass this to `@aburi/plugin-registry` or a scan
198
+ * pipeline. The type annotation is omitted deliberately: `class implements EffectPlugin`
199
+ * already enforces the structural contract, and inferring the narrow class type keeps
200
+ * the manifest literals (`readonly ["effects-plugin:prisma"]`, `"effects-prisma"`)
201
+ * visible to consumers that want to compare against them without a separate manifest
202
+ * import.
203
+ */
204
+ const prismaEffectsPlugin = new PrismaEffectsPlugin();
205
+
206
+ //#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 };
208
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@aburi/effects-prisma",
3
+ "version": "0.1.0",
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
+ "license": "MIT",
6
+ "author": "kage1020",
7
+ "homepage": "https://github.com/kage1020/Aburi/tree/main/packages/effects-prisma#readme",
8
+ "bugs": {
9
+ "url": "https://github.com/kage1020/Aburi/issues"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/kage1020/Aburi.git",
14
+ "directory": "packages/effects-prisma"
15
+ },
16
+ "type": "module",
17
+ "main": "./dist/index.mjs",
18
+ "types": "./dist/index.d.mts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.mts",
22
+ "default": "./dist/index.mjs"
23
+ },
24
+ "./package.json": "./package.json"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "src",
29
+ "README.md"
30
+ ],
31
+ "sideEffects": false,
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "dependencies": {
36
+ "@aburi/types": "0.1.0"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "^26.0.1",
40
+ "tsdown": "^0.22.3",
41
+ "typescript": "^6.0.3",
42
+ "vitest": "^4.1.9",
43
+ "@aburi/lang-typescript": "0.1.0"
44
+ },
45
+ "scripts": {
46
+ "build": "tsdown",
47
+ "typecheck": "tsc -p tsconfig.json --noEmit",
48
+ "test": "vitest run"
49
+ }
50
+ }
@@ -0,0 +1,115 @@
1
+ import type { CallCandidate, ClassifyContext, EffectClassification } from "@aburi/types"
2
+ import { hasPrismaImport } from "./imports"
3
+ import { isPrismaReadMethod, isPrismaTransactionMethod, isPrismaWriteMethod } from "./methods"
4
+
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
+ /**
13
+ * Classify a CallCandidate against Prisma Client conventions.
14
+ *
15
+ * Recognition strategy:
16
+ * 1. The owning file must import a Prisma Client module (see `hasPrismaImport`). No
17
+ * import → `null`, so callers can chain other effect plugins after this one.
18
+ * 2. The target is split on `.`; the plugin looks at the trailing segments to match
19
+ * Prisma's fixed client surface. Two shapes are accepted:
20
+ * - `<...>.<model>.<verb>` (3+ segments) — a model delegate call. The client
21
+ * segment stops two-segment method collisions (Express `router.create(...)`)
22
+ * from false-classifying.
23
+ * - `<...>.$transaction` (2+ segments) — the top-level transaction API on the
24
+ * client itself.
25
+ * 3. Malformed targets (empty string, adjacent / leading / trailing dots) throw — the
26
+ * language plugin's contract is a normalized non-empty callee, so a violation
27
+ * here is an upstream bug we surface loudly instead of silently miscategorizing.
28
+ *
29
+ * The function is a pure lookup — no I/O, no state, no async — matching the per-call
30
+ * timeout budget the core enforces (effect-plugin.md §5.1.1).
31
+ */
32
+ export function classifyPrismaCall(
33
+ call: CallCandidate,
34
+ ctx: ClassifyContext,
35
+ ): EffectClassification | null {
36
+ // Fail-fast runs BEFORE the import gate so a malformed target throws on every file,
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)
41
+
42
+ if (!hasPrismaImport(ctx.file.imports)) return null
43
+
44
+ // `parts` is guaranteed non-empty by `assertNonEmptySegments`, but `at()`'s general
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
48
+
49
+ if (isPrismaTransactionMethod(method)) {
50
+ // Bare `$transaction()` (single segment) is not a Prisma call — the transaction
51
+ // API only makes sense as a method on the client (`<client>.$transaction(...)`).
52
+ if (parts.length < 2) return null
53
+ return {
54
+ effectId: "db.transaction",
55
+ confidence: "high",
56
+ derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:tx`,
57
+ }
58
+ }
59
+
60
+ // Model delegate calls need `<client>.<model>.<verb>` to distinguish them from
61
+ // unrelated two-segment method calls (Express `router.create(...)`, an Array's
62
+ // hypothetical `.findMany` collision) that would otherwise false-positive in files
63
+ // that colocate Prisma with another library.
64
+ if (parts.length < 3) return null
65
+
66
+ if (isPrismaReadMethod(method)) {
67
+ return {
68
+ effectId: "db.read",
69
+ confidence: "high",
70
+ derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:read`,
71
+ }
72
+ }
73
+
74
+ if (isPrismaWriteMethod(method)) {
75
+ return {
76
+ effectId: "db.write",
77
+ confidence: "high",
78
+ derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:write`,
79
+ }
80
+ }
81
+
82
+ return null
83
+ }
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/imports.ts ADDED
@@ -0,0 +1,43 @@
1
+ import type { ImportEdge } from "@aburi/types"
2
+
3
+ /**
4
+ * npm module specifiers that expose a `PrismaClient`. Any file that pulls in one of
5
+ * these is treated as a Prisma consumer; files that reference the identifier without
6
+ * importing Prisma are ignored so an unrelated `db.user.findMany()` from another ORM
7
+ * does not get miscategorized.
8
+ *
9
+ * - `@prisma/client` — the default Prisma Client entry since v4.
10
+ * - `@prisma/client/edge` — the Edge runtime entry used by Vercel Edge, Cloudflare
11
+ * Workers, and Prisma Accelerate. Different bundle, same delegate surface.
12
+ *
13
+ * The set is a literal source of truth. Extending the plugin for community builds or a
14
+ * future Prisma bundle is a table edit here.
15
+ */
16
+ const PRISMA_CLIENT_MODULES_LIST = ["@prisma/client", "@prisma/client/edge"] as const
17
+
18
+ export type PrismaClientModule = (typeof PRISMA_CLIENT_MODULES_LIST)[number]
19
+
20
+ export const PRISMA_CLIENT_MODULES: ReadonlySet<PrismaClientModule> = new Set(
21
+ PRISMA_CLIENT_MODULES_LIST,
22
+ )
23
+
24
+ /**
25
+ * True when the file's import list contains any recognized Prisma Client module. An
26
+ * empty source string on an ImportEdge is rejected: the language plugin's contract is
27
+ * to emit normalized non-empty specifiers, and treating `""` as unmatched would silently
28
+ * hide upstream bugs.
29
+ *
30
+ * Validation runs across every edge before the match check so ImportEdge order does
31
+ * not make throw behavior non-deterministic. Using `.some()` alone would short-circuit
32
+ * on the first match and never notice a broken edge that happens to sit later.
33
+ */
34
+ export function hasPrismaImport(imports: readonly ImportEdge[]): boolean {
35
+ for (const edge of imports) {
36
+ if (edge.source.length === 0) {
37
+ throw new Error(
38
+ "effects-prisma: ImportEdge.source is empty — language plugin emitted an unnormalized import edge",
39
+ )
40
+ }
41
+ }
42
+ return imports.some((edge) => (PRISMA_CLIENT_MODULES as ReadonlySet<string>).has(edge.source))
43
+ }
package/src/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ export { classifyPrismaCall, EFFECTS_PRISMA_DERIVED_BY_PREFIX } from "./classify"
2
+ export { hasPrismaImport } from "./imports"
3
+ export { effectsPrismaManifest } from "./manifest"
4
+ export {
5
+ isPrismaReadMethod,
6
+ isPrismaTransactionMethod,
7
+ isPrismaWriteMethod,
8
+ PRISMA_READ_METHODS,
9
+ PRISMA_TRANSACTION_METHOD,
10
+ PRISMA_WRITE_METHODS,
11
+ type PrismaReadMethod,
12
+ type PrismaTransactionMethod,
13
+ type PrismaWriteMethod,
14
+ } from "./methods"
15
+ export { PrismaEffectsPlugin, prismaEffectsPlugin } from "./plugin"
@@ -0,0 +1,29 @@
1
+ import type { EffectsManifest } from "@aburi/types"
2
+ import { EFFECTS_PRISMA_DERIVED_BY_PREFIX } from "./classify"
3
+
4
+ /**
5
+ * Manifest for `@aburi/effects-prisma`. `as const satisfies EffectsManifest` keeps
6
+ * every literal narrow so downstream registry checks see the exact shape.
7
+ *
8
+ * The plugin returns core-owned effect ids (`db.read` / `db.write` / `db.transaction`)
9
+ * from `classify()`; per extension-vocab.md §5.1 core vocab lives in the reserved
10
+ * namespace and MUST NOT appear in a plugin's `provides.effects`. The plugin's own
11
+ * `x-prisma:*` namespace has no v0.1 bindings — model-specific effects would sit there
12
+ * once introduced. `derivedByPrefixes` shares its literal with the classifier's tag
13
+ * builder so both stay in lockstep across edits.
14
+ */
15
+ export const effectsPrismaManifest = {
16
+ $schema: "https://aburi.dev/schema/aburi.plugin.v1.json",
17
+ name: "effects-prisma",
18
+ version: "0.0.0",
19
+ type: "effects",
20
+ engines: { aburi: "*" },
21
+ provides: {
22
+ effects: [],
23
+ effectPrefixes: [],
24
+ extKinds: [],
25
+ extKindPrefixes: [],
26
+ derivedByPrefixes: [EFFECTS_PRISMA_DERIVED_BY_PREFIX],
27
+ frameworks: [],
28
+ },
29
+ } as const satisfies EffectsManifest
package/src/methods.ts ADDED
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Prisma model delegate method vocabulary.
3
+ *
4
+ * Each `_LIST` is the single source of truth — the union type and the runtime `Set` are
5
+ * both derived from it, so extending the vocabulary is a table edit in exactly one
6
+ * place. Extending as Prisma ships new delegate methods keeps the classifier honest
7
+ * without a code rewrite.
8
+ *
9
+ * Only methods that map cleanly onto core `db.read` / `db.write` vocabulary are listed.
10
+ * Delegate helpers whose semantics do not match (metadata accessors, raw SQL escapes,
11
+ * connection lifecycle) stay out — the plugin returns `null` for them so downstream
12
+ * effect plugins get a chance.
13
+ */
14
+ const PRISMA_READ_METHODS_LIST = [
15
+ "findUnique",
16
+ "findUniqueOrThrow",
17
+ "findFirst",
18
+ "findFirstOrThrow",
19
+ "findMany",
20
+ "count",
21
+ "aggregate",
22
+ "groupBy",
23
+ ] as const
24
+
25
+ const PRISMA_WRITE_METHODS_LIST = [
26
+ "create",
27
+ "createMany",
28
+ "createManyAndReturn",
29
+ "update",
30
+ "updateMany",
31
+ "updateManyAndReturn",
32
+ "upsert",
33
+ "delete",
34
+ "deleteMany",
35
+ ] as const
36
+
37
+ export type PrismaReadMethod = (typeof PRISMA_READ_METHODS_LIST)[number]
38
+ export type PrismaWriteMethod = (typeof PRISMA_WRITE_METHODS_LIST)[number]
39
+
40
+ /** Top-level client method: `prisma.$transaction(...)`. Not nested under a model. */
41
+ export type PrismaTransactionMethod = "$transaction"
42
+
43
+ export const PRISMA_READ_METHODS: ReadonlySet<PrismaReadMethod> = new Set(PRISMA_READ_METHODS_LIST)
44
+ export const PRISMA_WRITE_METHODS: ReadonlySet<PrismaWriteMethod> = new Set(
45
+ PRISMA_WRITE_METHODS_LIST,
46
+ )
47
+ export const PRISMA_TRANSACTION_METHOD: PrismaTransactionMethod = "$transaction"
48
+
49
+ export function isPrismaReadMethod(name: string): name is PrismaReadMethod {
50
+ return (PRISMA_READ_METHODS as ReadonlySet<string>).has(name)
51
+ }
52
+
53
+ export function isPrismaWriteMethod(name: string): name is PrismaWriteMethod {
54
+ return (PRISMA_WRITE_METHODS as ReadonlySet<string>).has(name)
55
+ }
56
+
57
+ export function isPrismaTransactionMethod(name: string): name is PrismaTransactionMethod {
58
+ return name === PRISMA_TRANSACTION_METHOD
59
+ }
package/src/plugin.ts ADDED
@@ -0,0 +1,41 @@
1
+ import type {
2
+ CallCandidate,
3
+ ClassifyContext,
4
+ EffectClassification,
5
+ EffectPlugin,
6
+ PluginContext,
7
+ } from "@aburi/types"
8
+ import { classifyPrismaCall } from "./classify"
9
+ import { effectsPrismaManifest } from "./manifest"
10
+
11
+ /**
12
+ * Prisma effect plugin. Sits behind the language plugin's `walkBody` output, mapping
13
+ * `prisma.<model>.<verb>` and `prisma.$transaction` call expressions into the core
14
+ * `db.read` / `db.write` / `db.transaction` effect vocabulary.
15
+ *
16
+ * `init` and `classify` are both pure with respect to plugin state — no lazy resources,
17
+ * no per-run caches — so repeated invocations against the same CallCandidate produce
18
+ * identical results. This matches the per-call timeout contract in
19
+ * effect-plugin.md §5.1.1 and the "pure classifier" recommendation in §11.1.
20
+ */
21
+ class PrismaEffectsPlugin implements EffectPlugin {
22
+ readonly manifest = effectsPrismaManifest
23
+
24
+ async init(_ctx: PluginContext): Promise<void> {}
25
+
26
+ classify(call: CallCandidate, ctx: ClassifyContext): EffectClassification | null {
27
+ return classifyPrismaCall(call, ctx)
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Ready-to-register instance. Callers pass this to `@aburi/plugin-registry` or a scan
33
+ * pipeline. The type annotation is omitted deliberately: `class implements EffectPlugin`
34
+ * already enforces the structural contract, and inferring the narrow class type keeps
35
+ * the manifest literals (`readonly ["effects-plugin:prisma"]`, `"effects-prisma"`)
36
+ * visible to consumers that want to compare against them without a separate manifest
37
+ * import.
38
+ */
39
+ export const prismaEffectsPlugin = new PrismaEffectsPlugin()
40
+
41
+ export { PrismaEffectsPlugin }