Skip to content

Commit 7be5ba0

Browse files
committed
🔧 Prevent contracts from exposing concrete generator types
Generator and AsyncGenerator are the types of the object a function* produces. Naming one is right when a declaration really is handing a consumer a sequence, so local/prefer-effection-operation reports the narrower thing: the concrete type standing in for Effection work. The yield type settles which is which. A generator that serves a consumer names what it yields; one that yields unknown — or nothing, or any — offers a consumer nothing it can use, which is work waiting for a runner. Effection work yields effects. Everything else is iteration and passes, Generator<number, void, unknown> included. A name is not evidence that a type is an effect: SoundEffect is a sound. An effect is Effect imported from effection, however it is spelled at the import; a type this module declares out of one; or a type this module declares with the effect contract itself — description annotated string, and enter a two-parameter signature returning a function type. Both shapes are checked, because names are cheap: { description: number; enter: boolean } is a doorway. That branch is how DurableEffect is recognized: it restates the contract rather than extending it, to keep enter's variance under its own control, so nothing in its declaration names Effection at all. Shadowing is lexical. A module-level import or declaration covers the module; a nested declaration or a type parameter covers only its own scope, so a contract declared after one still names the built-in. globalThis.Generator reaches past every shadow. Choosing between Operation<T> and naming what a generator yields is a decision about what the declaration means, so there is no fix. Workflow<T> keeps its concrete yield type — that is what stops a workflow yielding a non-durable effect — behind a suppression at that one line. Closes #185
1 parent aa47442 commit 7be5ba0

14 files changed

Lines changed: 828 additions & 0 deletions

‎.oxlintrc.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"local/no-module-scoped-registry": "error",
1818
"local/no-section-divider-comments": "error",
1919
"local/no-yield-in-finally": "error",
20+
"local/prefer-effection-operation": "error",
2021
"local/prefer-effection-result": "error"
2122
},
2223

‎packages/durable-streams/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,5 @@ export interface DurableEffect<T> {
138138
* at compile time — yielding a plain Effect inside a Workflow generator
139139
* is a type error.
140140
*/
141+
// oxlint-disable-next-line local/prefer-effection-operation
141142
export type Workflow<T> = Generator<DurableEffect<unknown>, T, unknown>;

‎scripts/oxlint-plugin.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { noModuleScopedRegistry } from "./oxlint-rules/no-module-scoped-registry
22
import { noRedundantTestScope } from "./oxlint-rules/no-redundant-test-scope.js";
33
import { noSectionDividerComments } from "./oxlint-rules/no-section-divider-comments.js";
44
import { noYieldInFinally } from "./oxlint-rules/no-yield-in-finally.js";
5+
import { preferEffectionOperation } from "./oxlint-rules/prefer-effection-operation.js";
56
import { preferEffectionResult } from "./oxlint-rules/prefer-effection-result.js";
67

78
export default {
@@ -11,6 +12,7 @@ export default {
1112
"no-section-divider-comments": noSectionDividerComments,
1213
"no-redundant-test-scope": noRedundantTestScope,
1314
"no-yield-in-finally": noYieldInFinally,
15+
"prefer-effection-operation": preferEffectionOperation,
1416
"prefer-effection-result": preferEffectionResult,
1517
},
1618
};

0 commit comments

Comments
 (0)