@aburi/effects-prisma 0.3.0 → 0.4.1

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 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,98 +1,47 @@
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
  /**
5
5
  * Classify a CallCandidate against Prisma Client conventions.
6
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. Malformed targets (empty string, adjacent / leading / trailing dots) throw — the
18
- * language plugin's contract is a normalized non-empty callee, so a violation
19
- * here is an upstream bug we surface loudly instead of silently miscategorizing.
7
+ * Two shapes are accepted once the file imports a Prisma Client module (`hasPrismaImport`):
8
+ * - `<...>.<model>.<verb>` (3+ segments) — a model delegate call. The client segment is
9
+ * what separates it from two-segment collisions such as Express `router.create(...)`.
10
+ * - `<...>.$transaction` (2+ segments) — the transaction API on the client itself.
20
11
  *
21
- * The function is a pure lookup — no I/O, no state, no async — matching the per-call
22
- * timeout budget the core enforces (effect-plugin.md §5.1.1).
12
+ * The import gate is not a receiver check: `this.cache.items.delete(key)` is a `Map` and
13
+ * `session.user.update(fields)` an object, both three segments with a delegate verb in a
14
+ * file that also uses Prisma. A literal first argument rules a call out — no Prisma method
15
+ * takes one — and the receiver plus argument count decide the tier, downgrading rather
16
+ * than dropping (`receiverConfidence`). A model addressed through brackets arrives as
17
+ * `<computed>` and supplies the third segment without a model, so there the receiver must
18
+ * name a client outright.
19
+ *
20
+ * Throws on a malformed target (`assertNonEmptySegments`): an upstream contract violation,
21
+ * not a classification decision. Pure with respect to plugin state (effect-plugin.md).
23
22
  */
24
23
  declare function classifyPrismaCall(call: CallCandidate, ctx: ClassifyContext): EffectClassification | null;
25
24
  //#endregion
26
25
  //#region src/constants.d.ts
27
- /**
28
- * Package-relative plugin name. Doubles as the prefix of every thrown message, so a caught
29
- * exception names the plugin that rejected the input. `manifest.ts` declares the same
30
- * string as `name`.
31
- */
26
+ /** Plugin name: the manifest's `name` and the prefix of every thrown message. */
32
27
  declare const EFFECTS_PRISMA_PLUGIN_NAME: "effects-prisma";
33
- /**
34
- * Shared derivedBy namespace. `manifest.ts` imports this same const for its
35
- * `derivedByPrefixes` entry, so the classifier's tag builder and the registry
36
- * declaration cannot drift.
37
- */
28
+ /** derivedBy namespace shared by the classifier's tag builder and the manifest. */
38
29
  declare const EFFECTS_PRISMA_DERIVED_BY_PREFIX: "effects-plugin:prisma";
39
30
  //#endregion
40
31
  //#region src/imports.d.ts
41
- /**
42
- * True when the file's import list contains any recognized Prisma Client module. An
43
- * empty source string on an ImportEdge is rejected by the shared guard: the language
44
- * plugin's contract is to emit normalized non-empty specifiers, and treating `""` as
45
- * unmatched would silently hide upstream bugs.
46
- *
47
- * `filePath` is required and threaded into any thrown error message so a caught
48
- * exception in production tooling (CI logs, error reporters) points directly at the
49
- * offending source file rather than a bare "empty source" string.
50
- */
32
+ /** True when the file imports a Prisma Client module; see `hasMatchingImport`. */
51
33
  declare function hasPrismaImport(imports: readonly ImportEdge[], filePath: string): boolean;
52
34
  //#endregion
53
35
  //#region src/manifest.d.ts
54
- /**
55
- * Manifest for `@aburi/effects-prisma`. `as const satisfies EffectsManifest` keeps
56
- * every literal narrow so downstream registry checks see the exact shape.
57
- *
58
- * The plugin returns core-owned effect ids (`db.read` / `db.write` / `db.transaction`)
59
- * from `classify()`; per extension-vocab.md §5.1 core vocab lives in the reserved
60
- * namespace and MUST NOT appear in a plugin's `provides.effects`. The plugin's own
61
- * `x-prisma:*` namespace currently has no bindings — model-specific effects would sit there
62
- * once introduced. `derivedByPrefixes` shares its literal with the classifier's tag
63
- * builder so both stay in lockstep across edits.
64
- */
65
- declare const effectsPrismaManifest: {
66
- readonly $schema: "https://aburi.kage1020.com/schema/aburi.plugin.v1.json";
67
- readonly name: "effects-prisma";
68
- readonly version: "0.0.0";
69
- readonly type: "effects";
70
- readonly engines: {
71
- readonly aburi: "*";
72
- };
73
- readonly provides: {
74
- readonly effects: [];
75
- readonly effectPrefixes: [];
76
- readonly extKinds: [];
77
- readonly extKindPrefixes: [];
78
- readonly derivedByPrefixes: ["effects-plugin:prisma"];
79
- readonly frameworks: [];
80
- };
81
- };
36
+ /** See `defineEffectsManifest` for why `provides` claims no vocabulary of its own. */
37
+ declare const effectsPrismaManifest: import("@aburi/plugin-registry/plugin-input").EffectsPluginManifest<"effects-prisma", "effects-plugin:prisma">;
82
38
  //#endregion
83
39
  //#region src/methods.d.ts
84
40
  /**
85
- * Prisma model delegate method vocabulary.
86
- *
87
- * Each `_LIST` is the single source of truth — the union type and the runtime `Set` are
88
- * both derived from it, so extending the vocabulary is a table edit in exactly one
89
- * place. Extending as Prisma ships new delegate methods keeps the classifier honest
90
- * without a code rewrite.
91
- *
92
- * Only methods that map cleanly onto core `db.read` / `db.write` vocabulary are listed.
93
- * Delegate helpers whose semantics do not match (metadata accessors, raw SQL escapes,
94
- * connection lifecycle) stay out — the plugin returns `null` for them so downstream
95
- * effect plugins get a chance.
41
+ * Prisma model delegate method vocabulary. Each `_LIST` is the single source of truth for
42
+ * its union type and runtime `Set`. Only methods that map onto core `db.read` / `db.write`
43
+ * are listed; metadata accessors, raw SQL escapes and connection lifecycle stay out, so the
44
+ * plugin returns `null` for them and downstream effect plugins get a chance.
96
45
  */
97
46
  declare const PRISMA_READ_METHODS_LIST: readonly ["findUnique", "findUniqueOrThrow", "findFirst", "findFirstOrThrow", "findMany", "count", "aggregate", "groupBy"];
98
47
  declare const PRISMA_WRITE_METHODS_LIST: readonly ["create", "createMany", "createManyAndReturn", "update", "updateMany", "updateManyAndReturn", "upsert", "delete", "deleteMany"];
@@ -109,45 +58,45 @@ declare function isPrismaTransactionMethod(name: string): name is PrismaTransact
109
58
  //#endregion
110
59
  //#region src/plugin.d.ts
111
60
  /**
112
- * Prisma effect plugin. Sits behind the language plugin's `walkBody` output, mapping
113
- * `prisma.<model>.<verb>` and `prisma.$transaction` call expressions into the core
114
- * `db.read` / `db.write` / `db.transaction` effect vocabulary.
115
- *
116
- * `init` and `classify` are both pure with respect to plugin state — no lazy resources,
117
- * no per-run caches — so repeated invocations against the same CallCandidate produce
118
- * identical results. This matches the per-call timeout contract in
119
- * effect-plugin.md §5.1.1 and the "pure classifier" recommendation in §11.1.
61
+ * Prisma effect plugin: maps `prisma.<model>.<verb>` and `prisma.$transaction` call
62
+ * expressions onto the core `db.read` / `db.write` / `db.transaction` vocabulary. `classify`
63
+ * is pure (effect-plugin.md) and throws on a malformed CallCandidate — an
64
+ * upstream contract violation, surfaced rather than swallowed.
120
65
  */
121
66
  declare class PrismaEffectsPlugin implements EffectPlugin {
122
- readonly manifest: {
123
- readonly $schema: "https://aburi.kage1020.com/schema/aburi.plugin.v1.json";
124
- readonly name: "effects-prisma";
125
- readonly version: "0.0.0";
126
- readonly type: "effects";
127
- readonly engines: {
128
- readonly aburi: "*";
129
- };
130
- readonly provides: {
131
- readonly effects: [];
132
- readonly effectPrefixes: [];
133
- readonly extKinds: [];
134
- readonly extKindPrefixes: [];
135
- readonly derivedByPrefixes: ["effects-plugin:prisma"];
136
- readonly frameworks: [];
137
- };
138
- };
67
+ readonly manifest: import("@aburi/plugin-registry/plugin-input").EffectsPluginManifest<"effects-prisma", "effects-plugin:prisma">;
139
68
  init(_ctx: PluginContext): Promise<void>;
140
69
  classify(call: CallCandidate, ctx: ClassifyContext): EffectClassification | null;
141
70
  }
71
+ /** Ready-to-register instance; left unannotated so the manifest literals stay visible. */
72
+ declare const prismaEffectsPlugin: PrismaEffectsPlugin;
73
+ //#endregion
74
+ //#region src/receivers.d.ts
142
75
  /**
143
- * Ready-to-register instance. Callers pass this to `@aburi/plugin-registry` or a scan
144
- * pipeline. The type annotation is omitted deliberately: `class implements EffectPlugin`
145
- * already enforces the structural contract, and inferring the narrow class type keeps
146
- * the manifest literals (`readonly ["effects-plugin:prisma"]`, `"effects-prisma"`)
147
- * visible to consumers that want to compare against them without a separate manifest
148
- * import.
76
+ * The words a Prisma Client binding is spelled with. The callee string is all a classifier
77
+ * sees (effect-plugin.md), and matching is per word (`identifierWords`): `prisma`,
78
+ * `prismaClient`, `readReplicaDb` and `_prisma` count; `cache`, `router`, `items` and
79
+ * `feedback` do not. `tx` / `trx` cover the interactive-transaction callback parameter.
80
+ *
81
+ * Deliberately absent: `client`, which would hand an SDK's `apiClient.users.update(payload)`
82
+ * — spelled exactly like a delegate call — a high-confidence `db.write`; `transaction`,
83
+ * which names a domain noun (`paymentTransaction`) far more often than a client; and
84
+ * `datasource`, which `identifierWords("dataSource")` splits so only the all-lowercase form
85
+ * ever matched. See docs/design/effect-plugin.md.
149
86
  */
150
- declare const prismaEffectsPlugin: PrismaEffectsPlugin;
87
+ declare const PRISMA_CLIENT_WORDS_LIST: readonly ["prisma", "db", "database", "orm", "tx", "trx"];
88
+ type PrismaClientWord = (typeof PRISMA_CLIENT_WORDS_LIST)[number];
89
+ declare const PRISMA_CLIENT_WORDS: ReadonlySet<PrismaClientWord>;
90
+ /** True when `segment` spells a word this package recognizes as a Prisma client binding. */
91
+ declare function namesPrismaClient(segment: string): boolean;
92
+ /**
93
+ * The most arguments a Prisma call takes before it stops looking like Prisma's own API: a
94
+ * delegate method takes one options object or nothing; `$transaction(fn, { timeout })`
95
+ * takes two.
96
+ */
97
+ declare const PRISMA_DELEGATE_MAX_ARGUMENTS = 1;
98
+ declare const PRISMA_TRANSACTION_MAX_ARGUMENTS = 2;
99
+ /** `receiverConfidence` under this package's client vocabulary. */
100
+ declare function classificationConfidence(clientSegment: string | undefined, call: CallCandidate, maxArguments: number): Confidence;
151
101
  //#endregion
152
- export { EFFECTS_PRISMA_DERIVED_BY_PREFIX, EFFECTS_PRISMA_PLUGIN_NAME, PRISMA_READ_METHODS, PRISMA_TRANSACTION_METHOD, PRISMA_WRITE_METHODS, PrismaEffectsPlugin, type PrismaReadMethod, type PrismaTransactionMethod, type PrismaWriteMethod, classifyPrismaCall, effectsPrismaManifest, hasPrismaImport, isPrismaReadMethod, isPrismaTransactionMethod, isPrismaWriteMethod, prismaEffectsPlugin };
153
- //# sourceMappingURL=index.d.mts.map
102
+ 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 { assertNonEmptySegments, hasMatchingImport } from "@aburi/plugin-registry/plugin-input";
2
-
3
- //#region src/constants.ts
4
- /**
5
- * Package-relative plugin name. Doubles as the prefix of every thrown message, so a caught
6
- * exception names the plugin that rejected the input. `manifest.ts` declares the same
7
- * string as `name`.
8
- */
9
- const EFFECTS_PRISMA_PLUGIN_NAME = "effects-prisma";
10
- /**
11
- * Shared derivedBy namespace. `manifest.ts` imports this same const for its
12
- * `derivedByPrefixes` entry, so the classifier's tag builder and the registry
13
- * declaration cannot drift.
14
- */
15
- const EFFECTS_PRISMA_DERIVED_BY_PREFIX = "effects-plugin:prisma";
16
-
17
- //#endregion
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,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.3.0",
3
+ "version": "0.4.1",
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,16 @@
33
32
  "access": "public"
34
33
  },
35
34
  "dependencies": {
36
- "@aburi/plugin-registry": "0.3.0",
37
- "@aburi/types": "0.3.0"
35
+ "@aburi/plugin-registry": "0.5.0",
36
+ "@aburi/types": "0.5.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.9",
44
- "@aburi/lang-typescript": "0.3.0"
42
+ "vitest": "^4.1.11",
43
+ "@aburi/lang-typescript": "0.5.0",
44
+ "@aburi/test-support": "0.0.1"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "tsdown",
@@ -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"}
@@ -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 }