@aburi/effects-prisma 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,121 +1,23 @@
1
1
  import { CallCandidate, ClassifyContext, Confidence, EffectClassification, EffectPlugin, ImportEdge, PluginContext } from "@aburi/types";
2
2
 
3
3
  //#region src/classify.d.ts
4
- /**
5
- * Classify a CallCandidate against Prisma Client conventions.
6
- *
7
- * Recognition strategy:
8
- * 1. The owning file must import a Prisma Client module (see `hasPrismaImport`). No
9
- * import → `null`, so callers can chain other effect plugins after this one.
10
- * 2. The target is split on `.`; the plugin looks at the trailing segments to match
11
- * Prisma's fixed client surface. Two shapes are accepted:
12
- * - `<...>.<model>.<verb>` (3+ segments) — a model delegate call. The client
13
- * segment stops two-segment method collisions (Express `router.create(...)`)
14
- * from false-classifying.
15
- * - `<...>.$transaction` (2+ segments) — the top-level transaction API on the
16
- * client itself.
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
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 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
- *
38
- * The function is a pure lookup — no I/O, no state, no async — matching the per-call
39
- * timeout budget the core enforces (effect-plugin.md §5.1.1).
40
- */
41
4
  declare function classifyPrismaCall(call: CallCandidate, ctx: ClassifyContext): EffectClassification | null;
42
5
  //#endregion
43
6
  //#region src/constants.d.ts
44
- /**
45
- * Package-relative plugin name. Doubles as the prefix of every thrown message, so a caught
46
- * exception names the plugin that rejected the input. `manifest.ts` declares the same
47
- * string as `name`.
48
- */
49
7
  declare const EFFECTS_PRISMA_PLUGIN_NAME: "effects-prisma";
50
- /**
51
- * Shared derivedBy namespace. `manifest.ts` imports this same const for its
52
- * `derivedByPrefixes` entry, so the classifier's tag builder and the registry
53
- * declaration cannot drift.
54
- */
55
8
  declare const EFFECTS_PRISMA_DERIVED_BY_PREFIX: "effects-plugin:prisma";
56
9
  //#endregion
57
10
  //#region src/imports.d.ts
58
- /**
59
- * True when the file's import list contains any recognized Prisma Client module. An
60
- * empty source string on an ImportEdge is rejected by the shared guard: the language
61
- * plugin's contract is to emit normalized non-empty specifiers, and treating `""` as
62
- * unmatched would silently hide upstream bugs.
63
- *
64
- * `filePath` is required and threaded into any thrown error message so a caught
65
- * exception in production tooling (CI logs, error reporters) points directly at the
66
- * offending source file rather than a bare "empty source" string.
67
- */
68
11
  declare function hasPrismaImport(imports: readonly ImportEdge[], filePath: string): boolean;
69
12
  //#endregion
70
13
  //#region src/manifest.d.ts
71
- /**
72
- * Manifest for `@aburi/effects-prisma`. `as const satisfies EffectsManifest` keeps
73
- * every literal narrow so downstream registry checks see the exact shape.
74
- *
75
- * The plugin returns core-owned effect ids (`db.read` / `db.write` / `db.transaction`)
76
- * from `classify()`; per extension-vocab.md §5.1 core vocab lives in the reserved
77
- * namespace and MUST NOT appear in a plugin's `provides.effects`. The plugin's own
78
- * `x-prisma:*` namespace currently has no bindings — model-specific effects would sit there
79
- * once introduced. `derivedByPrefixes` shares its literal with the classifier's tag
80
- * builder so both stay in lockstep across edits.
81
- */
82
- declare const effectsPrismaManifest: {
83
- readonly $schema: "https://aburi.kage1020.com/schema/aburi.plugin.v1.json";
84
- readonly name: "effects-prisma";
85
- readonly version: "0.0.0";
86
- readonly type: "effects";
87
- readonly engines: {
88
- readonly aburi: "*";
89
- };
90
- readonly provides: {
91
- readonly effects: [];
92
- readonly effectPrefixes: [];
93
- readonly extKinds: [];
94
- readonly extKindPrefixes: [];
95
- readonly derivedByPrefixes: ["effects-plugin:prisma"];
96
- readonly frameworks: [];
97
- };
98
- };
14
+ declare const effectsPrismaManifest: import("@aburi/plugin-registry/plugin-input").EffectsPluginManifest<"effects-prisma", "effects-plugin:prisma">;
99
15
  //#endregion
100
16
  //#region src/methods.d.ts
101
- /**
102
- * Prisma model delegate method vocabulary.
103
- *
104
- * Each `_LIST` is the single source of truth — the union type and the runtime `Set` are
105
- * both derived from it, so extending the vocabulary is a table edit in exactly one
106
- * place. Extending as Prisma ships new delegate methods keeps the classifier honest
107
- * without a code rewrite.
108
- *
109
- * Only methods that map cleanly onto core `db.read` / `db.write` vocabulary are listed.
110
- * Delegate helpers whose semantics do not match (metadata accessors, raw SQL escapes,
111
- * connection lifecycle) stay out — the plugin returns `null` for them so downstream
112
- * effect plugins get a chance.
113
- */
114
17
  declare const PRISMA_READ_METHODS_LIST: readonly ["findUnique", "findUniqueOrThrow", "findFirst", "findFirstOrThrow", "findMany", "count", "aggregate", "groupBy"];
115
18
  declare const PRISMA_WRITE_METHODS_LIST: readonly ["create", "createMany", "createManyAndReturn", "update", "updateMany", "updateManyAndReturn", "upsert", "delete", "deleteMany"];
116
19
  type PrismaReadMethod = (typeof PRISMA_READ_METHODS_LIST)[number];
117
20
  type PrismaWriteMethod = (typeof PRISMA_WRITE_METHODS_LIST)[number];
118
- /** Top-level client method: `prisma.$transaction(...)`. Not nested under a model. */
119
21
  type PrismaTransactionMethod = "$transaction";
120
22
  declare const PRISMA_READ_METHODS: ReadonlySet<PrismaReadMethod>;
121
23
  declare const PRISMA_WRITE_METHODS: ReadonlySet<PrismaWriteMethod>;
@@ -125,130 +27,21 @@ declare function isPrismaWriteMethod(name: string): name is PrismaWriteMethod;
125
27
  declare function isPrismaTransactionMethod(name: string): name is PrismaTransactionMethod;
126
28
  //#endregion
127
29
  //#region src/plugin.d.ts
128
- /**
129
- * Prisma effect plugin. Sits behind the language plugin's `walkBody` output, mapping
130
- * `prisma.<model>.<verb>` and `prisma.$transaction` call expressions into the core
131
- * `db.read` / `db.write` / `db.transaction` effect vocabulary.
132
- *
133
- * `init` and `classify` are both pure with respect to plugin state — no lazy resources,
134
- * no per-run caches — so repeated invocations against the same CallCandidate produce
135
- * identical results. This matches the per-call timeout contract in
136
- * effect-plugin.md §5.1.1 and the "pure classifier" recommendation in §11.1.
137
- */
138
30
  declare class PrismaEffectsPlugin implements EffectPlugin {
139
- readonly manifest: {
140
- readonly $schema: "https://aburi.kage1020.com/schema/aburi.plugin.v1.json";
141
- readonly name: "effects-prisma";
142
- readonly version: "0.0.0";
143
- readonly type: "effects";
144
- readonly engines: {
145
- readonly aburi: "*";
146
- };
147
- readonly provides: {
148
- readonly effects: [];
149
- readonly effectPrefixes: [];
150
- readonly extKinds: [];
151
- readonly extKindPrefixes: [];
152
- readonly derivedByPrefixes: ["effects-plugin:prisma"];
153
- readonly frameworks: [];
154
- };
155
- };
31
+ readonly manifest: import("@aburi/plugin-registry/plugin-input").EffectsPluginManifest<"effects-prisma", "effects-plugin:prisma">;
156
32
  init(_ctx: PluginContext): Promise<void>;
157
33
  classify(call: CallCandidate, ctx: ClassifyContext): EffectClassification | null;
158
34
  }
159
- /**
160
- * Ready-to-register instance. Callers pass this to `@aburi/plugin-registry` or a scan
161
- * pipeline. The type annotation is omitted deliberately: `class implements EffectPlugin`
162
- * already enforces the structural contract, and inferring the narrow class type keeps
163
- * the manifest literals (`readonly ["effects-plugin:prisma"]`, `"effects-prisma"`)
164
- * visible to consumers that want to compare against them without a separate manifest
165
- * import.
166
- */
35
+ /** Left unannotated so the manifest literals stay visible. */
167
36
  declare const prismaEffectsPlugin: PrismaEffectsPlugin;
168
37
  //#endregion
169
38
  //#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
39
  declare const PRISMA_CLIENT_WORDS_LIST: readonly ["prisma", "db", "database", "orm", "tx", "trx"];
209
40
  type PrismaClientWord = (typeof PRISMA_CLIENT_WORDS_LIST)[number];
210
41
  declare const PRISMA_CLIENT_WORDS: ReadonlySet<PrismaClientWord>;
211
- /** True when `segment` spells a word this package recognizes as a Prisma client binding. */
212
42
  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
43
  declare const PRISMA_DELEGATE_MAX_ARGUMENTS = 1;
221
44
  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
45
  declare function classificationConfidence(clientSegment: string | undefined, call: CallCandidate, maxArguments: number): Confidence;
253
46
  //#endregion
254
47
  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 +1 @@
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};
1
+ import{assertNonEmptySegments as e,defineEffectsManifest as t,hasLiteralFirstArgument as n,hasMatchingImport as r,identifierMentions as i,receiverConfidence as a}from"@aburi/plugin-registry/plugin-input";import{COMPUTED_TARGET_SEGMENT as o}from"@aburi/types";const s=`effects-prisma`,c=`effects-plugin:prisma`,l=new Set([`@prisma/client`,`@prisma/client/edge`]);function u(e){return l.has(e)}function d(e,t){return r(e,{plugin:s,filePath:t},u)}const f=[`findUnique`,`findUniqueOrThrow`,`findFirst`,`findFirstOrThrow`,`findMany`,`count`,`aggregate`,`groupBy`],p=[`create`,`createMany`,`createManyAndReturn`,`update`,`updateMany`,`updateManyAndReturn`,`upsert`,`delete`,`deleteMany`],m=new Set(f),h=new Set(p),g=`$transaction`;function _(e){return m.has(e)}function v(e){return h.has(e)}function y(e){return e===g}const b=new Set([`prisma`,`db`,`database`,`orm`,`tx`,`trx`]);function x(e){return i(e,b)}const S=1,C=2;function w(e,t,n){return a(e,t,n,x)}function T(t,r){let i={plugin:s,filePath:r.file.path},{segments:a,last:l}=e(t.target,i);if(!d(r.file.imports,r.file.path))return null;if(y(l))return a.length<2||n(t)?null:{effectId:`db.transaction`,confidence:w(a.at(-2),t,2),derivedBy:`${c}:tx`};if(a.length<3||n(t))return null;let u=a.at(-3);if(u!==void 0&&a.at(-2)===o&&!x(u))return null;let f=w(u,t,1);return _(l)?{effectId:`db.read`,confidence:f,derivedBy:`${c}:read`}:v(l)?{effectId:`db.write`,confidence:f,derivedBy:`${c}:write`}:null}const E=t(s,c);var D=class{manifest=E;async init(e){}classify(e,t){return T(e,t)}};const O=new D;export{c as EFFECTS_PRISMA_DERIVED_BY_PREFIX,s as EFFECTS_PRISMA_PLUGIN_NAME,b as PRISMA_CLIENT_WORDS,S as PRISMA_DELEGATE_MAX_ARGUMENTS,m as PRISMA_READ_METHODS,C as PRISMA_TRANSACTION_MAX_ARGUMENTS,g as PRISMA_TRANSACTION_METHOD,h as PRISMA_WRITE_METHODS,D as PrismaEffectsPlugin,w as classificationConfidence,T as classifyPrismaCall,E as effectsPrismaManifest,d as hasPrismaImport,_ as isPrismaReadMethod,y as isPrismaTransactionMethod,v as isPrismaWriteMethod,x as namesPrismaClient,O as prismaEffectsPlugin};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aburi/effects-prisma",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
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",
@@ -32,15 +32,18 @@
32
32
  "access": "public"
33
33
  },
34
34
  "dependencies": {
35
- "@aburi/plugin-registry": "0.4.0",
36
- "@aburi/types": "0.4.0"
35
+ "@aburi/plugin-registry": "0.5.1",
36
+ "@aburi/types": "0.6.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^26.0.1",
40
40
  "tsdown": "^0.22.3",
41
41
  "typescript": "^6.0.3",
42
42
  "vitest": "^4.1.11",
43
- "@aburi/lang-typescript": "0.4.0"
43
+ "@aburi/core": "0.6.0",
44
+ "@aburi/lang-typescript": "0.6.0",
45
+ "@aburi/test-harness": "0.0.1",
46
+ "@aburi/test-support": "0.0.2"
44
47
  },
45
48
  "scripts": {
46
49
  "build": "tsdown",