@aburi/effects-prisma 0.3.0 → 0.4.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 +40 -0
- package/dist/index.d.mts +105 -4
- package/dist/index.mjs +1 -215
- package/package.json +5 -6
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/src/classify.ts +0 -73
- package/src/constants.ts +0 -17
- package/src/imports.ts +0 -47
- package/src/index.ts +0 -16
- package/src/manifest.ts +0 -29
- package/src/methods.ts +0 -59
- package/src/plugin.ts +0 -41
package/README.md
CHANGED
|
@@ -23,6 +23,46 @@ lands there) is a prerequisite, and the target must have at least three
|
|
|
23
23
|
call in an unrelated file will not false-classify. Bare `$transaction()`
|
|
24
24
|
without a client segment is also skipped.
|
|
25
25
|
|
|
26
|
+
### Receiver identification
|
|
27
|
+
|
|
28
|
+
The import gate answers "does this file use Prisma", which a file is free to
|
|
29
|
+
answer yes to while most of its calls belong to something else. `delete`,
|
|
30
|
+
`create` and `update` are shared vocabulary across `Map`, `Set`, the DOM and
|
|
31
|
+
every HTTP router, and `this.<x>.<y>.delete(...)` is everyday TypeScript — so
|
|
32
|
+
the shape plus the gate is not evidence that the receiver is a database client.
|
|
33
|
+
|
|
34
|
+
Three further checks decide what is recorded:
|
|
35
|
+
|
|
36
|
+
- **Literal first argument.** A Prisma method takes an options object, an array
|
|
37
|
+
or a callback — never a bare literal. `this.cache.items.delete("session")` is
|
|
38
|
+
a `Map`, and is not classified at all.
|
|
39
|
+
- **Receiver name.** The segment before the model — `prisma` in
|
|
40
|
+
`this.prisma.user.create`, `db` in `db.user.create` — is matched word-wise
|
|
41
|
+
against the client vocabulary (`prisma` / `db` / `database` / `orm` / `tx` /
|
|
42
|
+
`trx`), so `prismaClient`, `readReplicaDb` and `_prisma` all count and
|
|
43
|
+
`cache`, `router`, `store` and `apiClient` do not. `client` is deliberately
|
|
44
|
+
absent: a resource SDK's `<client>.<resource>.<verb>` is a delegate call's
|
|
45
|
+
shape exactly, so the entry would hand `apiClient.users.update(payload)` the
|
|
46
|
+
top tier.
|
|
47
|
+
- **Argument count.** A delegate takes at most one argument, `$transaction`
|
|
48
|
+
two. More than that is evidence against — but only evidence: `argumentCount`
|
|
49
|
+
is a syntactic count, and a drop would erase a real write without logging
|
|
50
|
+
anything, so an overflow costs the tier instead.
|
|
51
|
+
|
|
52
|
+
A match on all three gives `confidence: "high"`; anything short of that still
|
|
53
|
+
records the effect, at `confidence: "medium"`.
|
|
54
|
+
|
|
55
|
+
The `medium` tier is deliberate. Without the AST — which effect plugins never
|
|
56
|
+
see — a client bound under a house naming convention and an unrelated object of
|
|
57
|
+
the same shape are indistinguishable from the callee string, so the uncertainty
|
|
58
|
+
is stated rather than resolved by guessing. A receiver the language plugin
|
|
59
|
+
flagged as dynamic (`getPrisma().user.create()`) is capped at `medium` for the
|
|
60
|
+
same reason: the name in the target is a collapsed expression, not a binding.
|
|
61
|
+
|
|
62
|
+
Naming your client something this vocabulary does not know is not an error — it
|
|
63
|
+
costs the effect its `high` tier, and the table in `src/receivers.ts` is one
|
|
64
|
+
literal list if a house convention deserves to be in it.
|
|
65
|
+
|
|
26
66
|
## Install
|
|
27
67
|
|
|
28
68
|
```bash
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CallCandidate, ClassifyContext, EffectClassification, EffectPlugin, ImportEdge, PluginContext } from "@aburi/types";
|
|
1
|
+
import { CallCandidate, ClassifyContext, Confidence, EffectClassification, EffectPlugin, ImportEdge, PluginContext } from "@aburi/types";
|
|
2
2
|
|
|
3
3
|
//#region src/classify.d.ts
|
|
4
4
|
/**
|
|
@@ -14,10 +14,27 @@ import { CallCandidate, ClassifyContext, EffectClassification, EffectPlugin, Imp
|
|
|
14
14
|
* from false-classifying.
|
|
15
15
|
* - `<...>.$transaction` (2+ segments) — the top-level transaction API on the
|
|
16
16
|
* client itself.
|
|
17
|
-
* 3.
|
|
17
|
+
* 3. A literal first argument rules the call out — no Prisma method takes one — and the
|
|
18
|
+
* receiver and the argument count decide the tier (`classificationConfidence`).
|
|
19
|
+
* 3a. A model segment that names nothing — `prisma[model].create(…)`, which arrives as
|
|
20
|
+
* `prisma.<computed>.create` — supplies the third segment without supplying a model, so
|
|
21
|
+
* the receiver has to carry the claim on its own: it must name a client binding, or the
|
|
22
|
+
* call is not classified at all.
|
|
23
|
+
* 4. Malformed targets (empty string, adjacent / leading / trailing dots) throw — the
|
|
18
24
|
* language plugin's contract is a normalized non-empty callee, so a violation
|
|
19
25
|
* here is an upstream bug we surface loudly instead of silently miscategorizing.
|
|
20
26
|
*
|
|
27
|
+
* **The import gate is not a receiver check.** It answers "does this file use Prisma",
|
|
28
|
+
* which a file is free to answer yes to while most of its calls belong to something else:
|
|
29
|
+
* `this.cache.items.delete(key)` is a `Map`, `session.user.update(fields)` is an object,
|
|
30
|
+
* and both have three segments and a delegate verb. Step 3 is what keeps those from being
|
|
31
|
+
* recorded as `db.write` at the tier a hand-annotated effect gets — a claim that
|
|
32
|
+
* would then propagate through the call graph and into the diff. Where the receiver names
|
|
33
|
+
* the client, the classification still lands at `high`; where it does not, the effect is
|
|
34
|
+
* still emitted but at `medium`, because a syntactic classifier cannot tell a client under
|
|
35
|
+
* a house naming convention apart from an unrelated object of the same shape, and silently
|
|
36
|
+
* dropping the first is as wrong as confidently claiming the second.
|
|
37
|
+
*
|
|
21
38
|
* The function is a pure lookup — no I/O, no state, no async — matching the per-call
|
|
22
39
|
* timeout budget the core enforces (effect-plugin.md §5.1.1).
|
|
23
40
|
*/
|
|
@@ -149,5 +166,89 @@ declare class PrismaEffectsPlugin implements EffectPlugin {
|
|
|
149
166
|
*/
|
|
150
167
|
declare const prismaEffectsPlugin: PrismaEffectsPlugin;
|
|
151
168
|
//#endregion
|
|
152
|
-
|
|
153
|
-
|
|
169
|
+
//#region src/receivers.d.ts
|
|
170
|
+
/**
|
|
171
|
+
* The words a Prisma Client binding is spelled with.
|
|
172
|
+
*
|
|
173
|
+
* A classifier only ever sees the callee string, so "which local binding holds the client"
|
|
174
|
+
* is not a question it can answer outright — the assignment that created the binding
|
|
175
|
+
* (`const prisma = new PrismaClient()`, `constructor(private prisma: PrismaClient)`) is in
|
|
176
|
+
* the AST, which effect plugins deliberately never see (effect-plugin.md §11.1). What the
|
|
177
|
+
* callee does carry is the name the author gave that binding, and Prisma's own docs, the
|
|
178
|
+
* generated client, and every published starter spell it from this handful of words.
|
|
179
|
+
*
|
|
180
|
+
* Matching is per word (`identifierWords`), so `prismaClient`, `readReplicaDb`, `_prisma`,
|
|
181
|
+
* `dbClient` and `prismaRo` all count, while `cache`, `router`, `items` and `store` do not.
|
|
182
|
+
* That is the whole point: `delete`, `create` and `update` are shared vocabulary across
|
|
183
|
+
* `Map`, `Set`, the DOM and every HTTP router, and `this.<x>.<y>.delete(...)` is everyday
|
|
184
|
+
* TypeScript, so the method name plus a file-level import gate is not evidence that the
|
|
185
|
+
* receiver is a database client.
|
|
186
|
+
*
|
|
187
|
+
* `tx` / `trx` are here because the interactive-transaction callback rebinds the client
|
|
188
|
+
* under its own parameter name — `prisma.$transaction(async (tx) => tx.user.create(...))` —
|
|
189
|
+
* and that call is as much a write as the one outside it.
|
|
190
|
+
*
|
|
191
|
+
* **What is deliberately not here.** A word only earns a place if it separates a database
|
|
192
|
+
* client from everything else that shares Prisma's verbs:
|
|
193
|
+
*
|
|
194
|
+
* - `client` matches `apiClient`, `httpClient`, `redisClient`, `sdkClient`. A resource
|
|
195
|
+
* SDK's `<client>.<resource>.<verb>` is spelled exactly like a Prisma delegate, so
|
|
196
|
+
* `apiClient.users.update(payload)` would land at the tier a hand-annotated effect gets
|
|
197
|
+
* — the bug class this module exists to close. `prismaClient`, `dbClient` and `_prisma`
|
|
198
|
+
* match on `prisma` or `db` regardless; a bare `client.user.create()` is all the entry
|
|
199
|
+
* would have bought.
|
|
200
|
+
* - `transaction` matches the domain nouns `paymentTransaction` / `transactionLog` more
|
|
201
|
+
* often than it names a client, and `tx` / `trx` already cover the callback parameter.
|
|
202
|
+
* - `datasource` was unreachable as anyone spells it: `identifierWords("dataSource")` is
|
|
203
|
+
* `["data", "source"]`, so only the all-lowercase form ever matched.
|
|
204
|
+
*
|
|
205
|
+
* A literal source of truth, like every other vocabulary in this package: extending it for
|
|
206
|
+
* a house naming convention is a table edit in exactly one place.
|
|
207
|
+
*/
|
|
208
|
+
declare const PRISMA_CLIENT_WORDS_LIST: readonly ["prisma", "db", "database", "orm", "tx", "trx"];
|
|
209
|
+
type PrismaClientWord = (typeof PRISMA_CLIENT_WORDS_LIST)[number];
|
|
210
|
+
declare const PRISMA_CLIENT_WORDS: ReadonlySet<PrismaClientWord>;
|
|
211
|
+
/** True when `segment` spells a word this package recognizes as a Prisma client binding. */
|
|
212
|
+
declare function namesPrismaClient(segment: string): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* The most arguments a Prisma call takes before it stops looking like Prisma's own API.
|
|
215
|
+
*
|
|
216
|
+
* A model delegate method takes a single options object (`{ where }`, `{ data }`) or
|
|
217
|
+
* nothing at all. `$transaction` takes two: the callback form carries an options object
|
|
218
|
+
* (`$transaction(fn, { timeout })`), while the array form takes one.
|
|
219
|
+
*/
|
|
220
|
+
declare const PRISMA_DELEGATE_MAX_ARGUMENTS = 1;
|
|
221
|
+
declare const PRISMA_TRANSACTION_MAX_ARGUMENTS = 2;
|
|
222
|
+
/**
|
|
223
|
+
* How much the call backs the classification its method name suggests.
|
|
224
|
+
*
|
|
225
|
+
* `high` needs every signal to agree: the receiver segment names a client binding, the
|
|
226
|
+
* receiver is a binding at all rather than a collapsed expression, and the call takes no
|
|
227
|
+
* more arguments than the API allows. Anything else is `medium` — the effect is still
|
|
228
|
+
* recorded, with the uncertainty stated:
|
|
229
|
+
*
|
|
230
|
+
* - **An unrecognized receiver** is either a binding this plugin cannot place by name (a
|
|
231
|
+
* house convention, a client reached through a wrapper) or an unrelated object that
|
|
232
|
+
* happens to share the verb. A syntactic classifier cannot separate those two without
|
|
233
|
+
* the binding table it has no access to, so it says so in `confidence` rather than
|
|
234
|
+
* picking one and being confidently wrong half the time. `medium` is the same tier
|
|
235
|
+
* `@aburi/framework-express` uses for a route that matches the shape without an import
|
|
236
|
+
* anchor.
|
|
237
|
+
* - **A dynamic receiver** (`getClient().user.create()`, `clients[0].user.create()`) is
|
|
238
|
+
* capped at `medium` whatever it is spelled: normalization collapsed an expression down
|
|
239
|
+
* to a name, so the name in `target` is not a binding and reading it as one would
|
|
240
|
+
* manufacture evidence out of a call the language plugin already flagged as unresolvable
|
|
241
|
+
* (`CallCandidate.dynamicReceiver`).
|
|
242
|
+
* - **An argument list longer than the API takes** is evidence against, not proof:
|
|
243
|
+
* `argumentCount` comes from a syntactic walk, and this classifier is the first thing to
|
|
244
|
+
* read it as a signature. Treating an overflow as "not a Prisma call" would let one
|
|
245
|
+
* miscount erase a real write and log nothing — the failure mode with no trace. So it
|
|
246
|
+
* costs the tier instead, which is this module's own rule applied to its own inputs.
|
|
247
|
+
*
|
|
248
|
+
* A literal first argument is the one shape that is *not* a tier question, and it is not
|
|
249
|
+
* decided here: `prisma.user.delete("u1")` is a type error rather than a Prisma call, so
|
|
250
|
+
* `classifyPrismaCall` rejects it outright.
|
|
251
|
+
*/
|
|
252
|
+
declare function classificationConfidence(clientSegment: string | undefined, call: CallCandidate, maxArguments: number): Confidence;
|
|
253
|
+
//#endregion
|
|
254
|
+
export { EFFECTS_PRISMA_DERIVED_BY_PREFIX, EFFECTS_PRISMA_PLUGIN_NAME, PRISMA_CLIENT_WORDS, PRISMA_DELEGATE_MAX_ARGUMENTS, PRISMA_READ_METHODS, PRISMA_TRANSACTION_MAX_ARGUMENTS, PRISMA_TRANSACTION_METHOD, PRISMA_WRITE_METHODS, type PrismaClientWord, PrismaEffectsPlugin, type PrismaReadMethod, type PrismaTransactionMethod, type PrismaWriteMethod, classificationConfidence, classifyPrismaCall, effectsPrismaManifest, hasPrismaImport, isPrismaReadMethod, isPrismaTransactionMethod, isPrismaWriteMethod, namesPrismaClient, prismaEffectsPlugin };
|
package/dist/index.mjs
CHANGED
|
@@ -1,215 +1 @@
|
|
|
1
|
-
import
|
|
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
|
|
18
|
-
//#region src/imports.ts
|
|
19
|
-
/**
|
|
20
|
-
* npm module specifiers that expose a `PrismaClient`. Any file that pulls in one of
|
|
21
|
-
* these is treated as a Prisma consumer; files that reference the identifier without
|
|
22
|
-
* importing Prisma are ignored so an unrelated `db.user.findMany()` from another ORM
|
|
23
|
-
* does not get miscategorized.
|
|
24
|
-
*
|
|
25
|
-
* - `@prisma/client` — the default Prisma Client entry since v4.
|
|
26
|
-
* - `@prisma/client/edge` — the Edge runtime entry used by Vercel Edge, Cloudflare
|
|
27
|
-
* Workers, and Prisma Accelerate. Different bundle, same delegate surface.
|
|
28
|
-
*
|
|
29
|
-
* The set is a literal source of truth. Extending the plugin for community builds or a
|
|
30
|
-
* future Prisma bundle is a table edit here.
|
|
31
|
-
*/
|
|
32
|
-
const PRISMA_CLIENT_MODULES_LIST = ["@prisma/client", "@prisma/client/edge"];
|
|
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
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* True when the file's import list contains any recognized Prisma Client module. An
|
|
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.
|
|
43
|
-
*
|
|
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.
|
|
47
|
-
*/
|
|
48
|
-
function hasPrismaImport(imports, filePath) {
|
|
49
|
-
return hasMatchingImport(imports, {
|
|
50
|
-
plugin: EFFECTS_PRISMA_PLUGIN_NAME,
|
|
51
|
-
filePath
|
|
52
|
-
}, isPrismaClientModule);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
//#endregion
|
|
56
|
-
//#region src/methods.ts
|
|
57
|
-
/**
|
|
58
|
-
* Prisma model delegate method vocabulary.
|
|
59
|
-
*
|
|
60
|
-
* Each `_LIST` is the single source of truth — the union type and the runtime `Set` are
|
|
61
|
-
* both derived from it, so extending the vocabulary is a table edit in exactly one
|
|
62
|
-
* place. Extending as Prisma ships new delegate methods keeps the classifier honest
|
|
63
|
-
* without a code rewrite.
|
|
64
|
-
*
|
|
65
|
-
* Only methods that map cleanly onto core `db.read` / `db.write` vocabulary are listed.
|
|
66
|
-
* Delegate helpers whose semantics do not match (metadata accessors, raw SQL escapes,
|
|
67
|
-
* connection lifecycle) stay out — the plugin returns `null` for them so downstream
|
|
68
|
-
* effect plugins get a chance.
|
|
69
|
-
*/
|
|
70
|
-
const PRISMA_READ_METHODS_LIST = [
|
|
71
|
-
"findUnique",
|
|
72
|
-
"findUniqueOrThrow",
|
|
73
|
-
"findFirst",
|
|
74
|
-
"findFirstOrThrow",
|
|
75
|
-
"findMany",
|
|
76
|
-
"count",
|
|
77
|
-
"aggregate",
|
|
78
|
-
"groupBy"
|
|
79
|
-
];
|
|
80
|
-
const PRISMA_WRITE_METHODS_LIST = [
|
|
81
|
-
"create",
|
|
82
|
-
"createMany",
|
|
83
|
-
"createManyAndReturn",
|
|
84
|
-
"update",
|
|
85
|
-
"updateMany",
|
|
86
|
-
"updateManyAndReturn",
|
|
87
|
-
"upsert",
|
|
88
|
-
"delete",
|
|
89
|
-
"deleteMany"
|
|
90
|
-
];
|
|
91
|
-
const PRISMA_READ_METHODS = new Set(PRISMA_READ_METHODS_LIST);
|
|
92
|
-
const PRISMA_WRITE_METHODS = new Set(PRISMA_WRITE_METHODS_LIST);
|
|
93
|
-
const PRISMA_TRANSACTION_METHOD = "$transaction";
|
|
94
|
-
function isPrismaReadMethod(name) {
|
|
95
|
-
return PRISMA_READ_METHODS.has(name);
|
|
96
|
-
}
|
|
97
|
-
function isPrismaWriteMethod(name) {
|
|
98
|
-
return PRISMA_WRITE_METHODS.has(name);
|
|
99
|
-
}
|
|
100
|
-
function isPrismaTransactionMethod(name) {
|
|
101
|
-
return name === PRISMA_TRANSACTION_METHOD;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
//#endregion
|
|
105
|
-
//#region src/classify.ts
|
|
106
|
-
/**
|
|
107
|
-
* Classify a CallCandidate against Prisma Client conventions.
|
|
108
|
-
*
|
|
109
|
-
* Recognition strategy:
|
|
110
|
-
* 1. The owning file must import a Prisma Client module (see `hasPrismaImport`). No
|
|
111
|
-
* import → `null`, so callers can chain other effect plugins after this one.
|
|
112
|
-
* 2. The target is split on `.`; the plugin looks at the trailing segments to match
|
|
113
|
-
* Prisma's fixed client surface. Two shapes are accepted:
|
|
114
|
-
* - `<...>.<model>.<verb>` (3+ segments) — a model delegate call. The client
|
|
115
|
-
* segment stops two-segment method collisions (Express `router.create(...)`)
|
|
116
|
-
* from false-classifying.
|
|
117
|
-
* - `<...>.$transaction` (2+ segments) — the top-level transaction API on the
|
|
118
|
-
* client itself.
|
|
119
|
-
* 3. Malformed targets (empty string, adjacent / leading / trailing dots) throw — the
|
|
120
|
-
* language plugin's contract is a normalized non-empty callee, so a violation
|
|
121
|
-
* here is an upstream bug we surface loudly instead of silently miscategorizing.
|
|
122
|
-
*
|
|
123
|
-
* The function is a pure lookup — no I/O, no state, no async — matching the per-call
|
|
124
|
-
* timeout budget the core enforces (effect-plugin.md §5.1.1).
|
|
125
|
-
*/
|
|
126
|
-
function classifyPrismaCall(call, ctx) {
|
|
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;
|
|
133
|
-
if (isPrismaTransactionMethod(method)) {
|
|
134
|
-
if (parts.length < 2) return null;
|
|
135
|
-
return {
|
|
136
|
-
effectId: "db.transaction",
|
|
137
|
-
confidence: "high",
|
|
138
|
-
derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:tx`
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
if (parts.length < 3) return null;
|
|
142
|
-
if (isPrismaReadMethod(method)) return {
|
|
143
|
-
effectId: "db.read",
|
|
144
|
-
confidence: "high",
|
|
145
|
-
derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:read`
|
|
146
|
-
};
|
|
147
|
-
if (isPrismaWriteMethod(method)) return {
|
|
148
|
-
effectId: "db.write",
|
|
149
|
-
confidence: "high",
|
|
150
|
-
derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:write`
|
|
151
|
-
};
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
//#endregion
|
|
156
|
-
//#region src/manifest.ts
|
|
157
|
-
/**
|
|
158
|
-
* Manifest for `@aburi/effects-prisma`. `as const satisfies EffectsManifest` keeps
|
|
159
|
-
* every literal narrow so downstream registry checks see the exact shape.
|
|
160
|
-
*
|
|
161
|
-
* The plugin returns core-owned effect ids (`db.read` / `db.write` / `db.transaction`)
|
|
162
|
-
* from `classify()`; per extension-vocab.md §5.1 core vocab lives in the reserved
|
|
163
|
-
* namespace and MUST NOT appear in a plugin's `provides.effects`. The plugin's own
|
|
164
|
-
* `x-prisma:*` namespace currently has no bindings — model-specific effects would sit there
|
|
165
|
-
* once introduced. `derivedByPrefixes` shares its literal with the classifier's tag
|
|
166
|
-
* builder so both stay in lockstep across edits.
|
|
167
|
-
*/
|
|
168
|
-
const effectsPrismaManifest = {
|
|
169
|
-
$schema: "https://aburi.kage1020.com/schema/aburi.plugin.v1.json",
|
|
170
|
-
name: EFFECTS_PRISMA_PLUGIN_NAME,
|
|
171
|
-
version: "0.0.0",
|
|
172
|
-
type: "effects",
|
|
173
|
-
engines: { aburi: "*" },
|
|
174
|
-
provides: {
|
|
175
|
-
effects: [],
|
|
176
|
-
effectPrefixes: [],
|
|
177
|
-
extKinds: [],
|
|
178
|
-
extKindPrefixes: [],
|
|
179
|
-
derivedByPrefixes: [EFFECTS_PRISMA_DERIVED_BY_PREFIX],
|
|
180
|
-
frameworks: []
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
//#endregion
|
|
185
|
-
//#region src/plugin.ts
|
|
186
|
-
/**
|
|
187
|
-
* Prisma effect plugin. Sits behind the language plugin's `walkBody` output, mapping
|
|
188
|
-
* `prisma.<model>.<verb>` and `prisma.$transaction` call expressions into the core
|
|
189
|
-
* `db.read` / `db.write` / `db.transaction` effect vocabulary.
|
|
190
|
-
*
|
|
191
|
-
* `init` and `classify` are both pure with respect to plugin state — no lazy resources,
|
|
192
|
-
* no per-run caches — so repeated invocations against the same CallCandidate produce
|
|
193
|
-
* identical results. This matches the per-call timeout contract in
|
|
194
|
-
* effect-plugin.md §5.1.1 and the "pure classifier" recommendation in §11.1.
|
|
195
|
-
*/
|
|
196
|
-
var PrismaEffectsPlugin = class {
|
|
197
|
-
manifest = effectsPrismaManifest;
|
|
198
|
-
async init(_ctx) {}
|
|
199
|
-
classify(call, ctx) {
|
|
200
|
-
return classifyPrismaCall(call, ctx);
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
/**
|
|
204
|
-
* Ready-to-register instance. Callers pass this to `@aburi/plugin-registry` or a scan
|
|
205
|
-
* pipeline. The type annotation is omitted deliberately: `class implements EffectPlugin`
|
|
206
|
-
* already enforces the structural contract, and inferring the narrow class type keeps
|
|
207
|
-
* the manifest literals (`readonly ["effects-plugin:prisma"]`, `"effects-prisma"`)
|
|
208
|
-
* visible to consumers that want to compare against them without a separate manifest
|
|
209
|
-
* import.
|
|
210
|
-
*/
|
|
211
|
-
const prismaEffectsPlugin = new PrismaEffectsPlugin();
|
|
212
|
-
|
|
213
|
-
//#endregion
|
|
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 };
|
|
215
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import{assertNonEmptySegments as e,hasLiteralFirstArgument as t,hasMatchingImport as n,identifierMentions as r}from"@aburi/plugin-registry/plugin-input";import{COMPUTED_TARGET_SEGMENT as i}from"@aburi/types";const a=`effects-prisma`,o=`effects-plugin:prisma`,s=new Set([`@prisma/client`,`@prisma/client/edge`]);function c(e){return s.has(e)}function l(e,t){return n(e,{plugin:a,filePath:t},c)}const u=[`findUnique`,`findUniqueOrThrow`,`findFirst`,`findFirstOrThrow`,`findMany`,`count`,`aggregate`,`groupBy`],d=[`create`,`createMany`,`createManyAndReturn`,`update`,`updateMany`,`updateManyAndReturn`,`upsert`,`delete`,`deleteMany`],f=new Set(u),p=new Set(d),m=`$transaction`;function h(e){return f.has(e)}function g(e){return p.has(e)}function _(e){return e===m}const v=new Set([`prisma`,`db`,`database`,`orm`,`tx`,`trx`]);function y(e){return r(e,v)}const b=1,x=2;function S(e,t,n){return t.dynamicReceiver===!0||t.argumentCount>n?`medium`:e!==void 0&&y(e)?`high`:`medium`}function C(n,r){let s={plugin:a,filePath:r.file.path},{segments:c,last:u}=e(n.target,s);if(!l(r.file.imports,r.file.path))return null;if(_(u))return c.length<2||t(n)?null:{effectId:`db.transaction`,confidence:S(c.at(-2),n,2),derivedBy:`${o}:tx`};if(c.length<3||t(n))return null;let d=c.at(-3);if(d!==void 0&&c.at(-2)===i&&!y(d))return null;let f=S(d,n,1);return h(u)?{effectId:`db.read`,confidence:f,derivedBy:`${o}:read`}:g(u)?{effectId:`db.write`,confidence:f,derivedBy:`${o}:write`}:null}const w={$schema:`https://aburi.kage1020.com/schema/aburi.plugin.v1.json`,name:a,version:`0.0.0`,type:`effects`,engines:{aburi:`*`},provides:{effects:[],effectPrefixes:[],extKinds:[],extKindPrefixes:[],derivedByPrefixes:[o],frameworks:[]}};var T=class{manifest=w;async init(e){}classify(e,t){return C(e,t)}};const E=new T;export{o as EFFECTS_PRISMA_DERIVED_BY_PREFIX,a as EFFECTS_PRISMA_PLUGIN_NAME,v as PRISMA_CLIENT_WORDS,b as PRISMA_DELEGATE_MAX_ARGUMENTS,f as PRISMA_READ_METHODS,x as PRISMA_TRANSACTION_MAX_ARGUMENTS,m as PRISMA_TRANSACTION_METHOD,p as PRISMA_WRITE_METHODS,T as PrismaEffectsPlugin,S as classificationConfidence,C as classifyPrismaCall,w as effectsPrismaManifest,l as hasPrismaImport,h as isPrismaReadMethod,_ as isPrismaTransactionMethod,g as isPrismaWriteMethod,y as namesPrismaClient,E as prismaEffectsPlugin};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aburi/effects-prisma",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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": "Apache-2.0",
|
|
6
6
|
"author": "kage1020",
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
27
|
"dist",
|
|
28
|
-
"src",
|
|
29
28
|
"README.md"
|
|
30
29
|
],
|
|
31
30
|
"sideEffects": false,
|
|
@@ -33,15 +32,15 @@
|
|
|
33
32
|
"access": "public"
|
|
34
33
|
},
|
|
35
34
|
"dependencies": {
|
|
36
|
-
"@aburi/plugin-registry": "0.
|
|
37
|
-
"@aburi/types": "0.
|
|
35
|
+
"@aburi/plugin-registry": "0.4.0",
|
|
36
|
+
"@aburi/types": "0.4.0"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
39
|
"@types/node": "^26.0.1",
|
|
41
40
|
"tsdown": "^0.22.3",
|
|
42
41
|
"typescript": "^6.0.3",
|
|
43
|
-
"vitest": "^4.1.
|
|
44
|
-
"@aburi/lang-typescript": "0.
|
|
42
|
+
"vitest": "^4.1.11",
|
|
43
|
+
"@aburi/lang-typescript": "0.4.0"
|
|
45
44
|
},
|
|
46
45
|
"scripts": {
|
|
47
46
|
"build": "tsdown",
|
package/dist/index.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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.kage1020.com/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/src/classify.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { assertNonEmptySegments, type PluginInputOrigin } from "@aburi/plugin-registry/plugin-input"
|
|
2
|
-
import type { CallCandidate, ClassifyContext, EffectClassification } from "@aburi/types"
|
|
3
|
-
import { EFFECTS_PRISMA_DERIVED_BY_PREFIX, EFFECTS_PRISMA_PLUGIN_NAME } from "./constants"
|
|
4
|
-
import { hasPrismaImport } from "./imports"
|
|
5
|
-
import { isPrismaReadMethod, isPrismaTransactionMethod, isPrismaWriteMethod } from "./methods"
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Classify a CallCandidate against Prisma Client conventions.
|
|
9
|
-
*
|
|
10
|
-
* Recognition strategy:
|
|
11
|
-
* 1. The owning file must import a Prisma Client module (see `hasPrismaImport`). No
|
|
12
|
-
* import → `null`, so callers can chain other effect plugins after this one.
|
|
13
|
-
* 2. The target is split on `.`; the plugin looks at the trailing segments to match
|
|
14
|
-
* Prisma's fixed client surface. Two shapes are accepted:
|
|
15
|
-
* - `<...>.<model>.<verb>` (3+ segments) — a model delegate call. The client
|
|
16
|
-
* segment stops two-segment method collisions (Express `router.create(...)`)
|
|
17
|
-
* from false-classifying.
|
|
18
|
-
* - `<...>.$transaction` (2+ segments) — the top-level transaction API on the
|
|
19
|
-
* client itself.
|
|
20
|
-
* 3. Malformed targets (empty string, adjacent / leading / trailing dots) throw — the
|
|
21
|
-
* language plugin's contract is a normalized non-empty callee, so a violation
|
|
22
|
-
* here is an upstream bug we surface loudly instead of silently miscategorizing.
|
|
23
|
-
*
|
|
24
|
-
* The function is a pure lookup — no I/O, no state, no async — matching the per-call
|
|
25
|
-
* timeout budget the core enforces (effect-plugin.md §5.1.1).
|
|
26
|
-
*/
|
|
27
|
-
export function classifyPrismaCall(
|
|
28
|
-
call: CallCandidate,
|
|
29
|
-
ctx: ClassifyContext,
|
|
30
|
-
): EffectClassification | null {
|
|
31
|
-
const origin: PluginInputOrigin = { plugin: EFFECTS_PRISMA_PLUGIN_NAME, filePath: ctx.file.path }
|
|
32
|
-
|
|
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)
|
|
36
|
-
|
|
37
|
-
if (!hasPrismaImport(ctx.file.imports, ctx.file.path)) return null
|
|
38
|
-
|
|
39
|
-
if (isPrismaTransactionMethod(method)) {
|
|
40
|
-
// Bare `$transaction()` (single segment) is not a Prisma call — the transaction
|
|
41
|
-
// API only makes sense as a method on the client (`<client>.$transaction(...)`).
|
|
42
|
-
if (parts.length < 2) return null
|
|
43
|
-
return {
|
|
44
|
-
effectId: "db.transaction",
|
|
45
|
-
confidence: "high",
|
|
46
|
-
derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:tx`,
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Model delegate calls need `<client>.<model>.<verb>` to distinguish them from
|
|
51
|
-
// unrelated two-segment method calls (Express `router.create(...)`, an Array's
|
|
52
|
-
// hypothetical `.findMany` collision) that would otherwise false-positive in files
|
|
53
|
-
// that colocate Prisma with another library.
|
|
54
|
-
if (parts.length < 3) return null
|
|
55
|
-
|
|
56
|
-
if (isPrismaReadMethod(method)) {
|
|
57
|
-
return {
|
|
58
|
-
effectId: "db.read",
|
|
59
|
-
confidence: "high",
|
|
60
|
-
derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:read`,
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (isPrismaWriteMethod(method)) {
|
|
65
|
-
return {
|
|
66
|
-
effectId: "db.write",
|
|
67
|
-
confidence: "high",
|
|
68
|
-
derivedBy: `${EFFECTS_PRISMA_DERIVED_BY_PREFIX}:write`,
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return null
|
|
73
|
-
}
|
package/src/constants.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { hasMatchingImport } from "@aburi/plugin-registry/plugin-input"
|
|
2
|
-
import type { ImportEdge } from "@aburi/types"
|
|
3
|
-
import { EFFECTS_PRISMA_PLUGIN_NAME } from "./constants"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* npm module specifiers that expose a `PrismaClient`. Any file that pulls in one of
|
|
7
|
-
* these is treated as a Prisma consumer; files that reference the identifier without
|
|
8
|
-
* importing Prisma are ignored so an unrelated `db.user.findMany()` from another ORM
|
|
9
|
-
* does not get miscategorized.
|
|
10
|
-
*
|
|
11
|
-
* - `@prisma/client` — the default Prisma Client entry since v4.
|
|
12
|
-
* - `@prisma/client/edge` — the Edge runtime entry used by Vercel Edge, Cloudflare
|
|
13
|
-
* Workers, and Prisma Accelerate. Different bundle, same delegate surface.
|
|
14
|
-
*
|
|
15
|
-
* The set is a literal source of truth. Extending the plugin for community builds or a
|
|
16
|
-
* future Prisma bundle is a table edit here.
|
|
17
|
-
*/
|
|
18
|
-
const PRISMA_CLIENT_MODULES_LIST = ["@prisma/client", "@prisma/client/edge"] as const
|
|
19
|
-
|
|
20
|
-
export type PrismaClientModule = (typeof PRISMA_CLIENT_MODULES_LIST)[number]
|
|
21
|
-
|
|
22
|
-
export const PRISMA_CLIENT_MODULES: ReadonlySet<PrismaClientModule> = new Set(
|
|
23
|
-
PRISMA_CLIENT_MODULES_LIST,
|
|
24
|
-
)
|
|
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
|
-
|
|
31
|
-
/**
|
|
32
|
-
* True when the file's import list contains any recognized Prisma Client module. An
|
|
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.
|
|
36
|
-
*
|
|
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.
|
|
40
|
-
*/
|
|
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
|
-
)
|
|
47
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export { classifyPrismaCall } from "./classify"
|
|
2
|
-
export { EFFECTS_PRISMA_DERIVED_BY_PREFIX, EFFECTS_PRISMA_PLUGIN_NAME } from "./constants"
|
|
3
|
-
export { hasPrismaImport } from "./imports"
|
|
4
|
-
export { effectsPrismaManifest } from "./manifest"
|
|
5
|
-
export {
|
|
6
|
-
isPrismaReadMethod,
|
|
7
|
-
isPrismaTransactionMethod,
|
|
8
|
-
isPrismaWriteMethod,
|
|
9
|
-
PRISMA_READ_METHODS,
|
|
10
|
-
PRISMA_TRANSACTION_METHOD,
|
|
11
|
-
PRISMA_WRITE_METHODS,
|
|
12
|
-
type PrismaReadMethod,
|
|
13
|
-
type PrismaTransactionMethod,
|
|
14
|
-
type PrismaWriteMethod,
|
|
15
|
-
} from "./methods"
|
|
16
|
-
export { PrismaEffectsPlugin, prismaEffectsPlugin } from "./plugin"
|
package/src/manifest.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { EffectsManifest } from "@aburi/types"
|
|
2
|
-
import { EFFECTS_PRISMA_DERIVED_BY_PREFIX, EFFECTS_PRISMA_PLUGIN_NAME } from "./constants"
|
|
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 currently has no 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.kage1020.com/schema/aburi.plugin.v1.json",
|
|
17
|
-
name: EFFECTS_PRISMA_PLUGIN_NAME,
|
|
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
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
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 }
|