@punks/cli 2.6.0 → 3.0.0-beta.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/AGENTS.md +1 -1
- package/README.md +45 -23
- package/dist/BASELINE_CHANGELOG.md +66 -0
- package/dist/CHANGELOG.md +102 -0
- package/dist/data/scripts/harness-projection/adapters/claude.d.mts +3 -0
- package/dist/data/scripts/harness-projection/adapters/claude.mjs +124 -0
- package/dist/data/scripts/harness-projection/adapters/codex.d.mts +3 -0
- package/dist/data/scripts/harness-projection/adapters/codex.mjs +137 -0
- package/dist/data/scripts/harness-projection/adapters/cursor.d.mts +5 -0
- package/dist/data/scripts/harness-projection/adapters/cursor.mjs +106 -0
- package/dist/data/scripts/harness-projection/adapters/opencode.d.mts +5 -0
- package/dist/data/scripts/harness-projection/adapters/opencode.mjs +100 -0
- package/dist/data/scripts/harness-projection/apply.d.mts +12 -0
- package/dist/data/scripts/harness-projection/apply.mjs +96 -0
- package/dist/data/scripts/harness-projection/core.d.mts +8 -0
- package/dist/data/scripts/harness-projection/core.mjs +239 -0
- package/dist/data/scripts/harness-projection/test-fixtures/application-context-plan.json +27 -0
- package/dist/data/scripts/harness-projection/test-fixtures/claude/actions.json +109 -0
- package/dist/data/scripts/harness-projection/test-fixtures/claude/context-plan.json +150 -0
- package/dist/data/scripts/harness-projection/test-fixtures/claude/matrix.json +23 -0
- package/dist/data/scripts/harness-projection/test-fixtures/claude/traces.json +15 -0
- package/dist/data/scripts/harness-projection/test-fixtures/codex/actions.json +124 -0
- package/dist/data/scripts/harness-projection/test-fixtures/codex/context-plan.json +150 -0
- package/dist/data/scripts/harness-projection/test-fixtures/codex/matrix.json +23 -0
- package/dist/data/scripts/harness-projection/test-fixtures/codex/traces.json +15 -0
- package/dist/data/scripts/harness-projection/test-fixtures/cursor/compiler-input.json +93 -0
- package/dist/data/scripts/harness-projection/test-fixtures/cursor/context-plan.json +108 -0
- package/dist/data/scripts/harness-projection/test-fixtures/cursor/matrix.json +19 -0
- package/dist/data/scripts/harness-projection/test-fixtures/cursor/projection.json +54 -0
- package/dist/data/scripts/harness-projection/test-fixtures/mixed-context-plan.json +35 -0
- package/dist/data/scripts/harness-projection/test-fixtures/opencode/compiler-input.json +93 -0
- package/dist/data/scripts/harness-projection/test-fixtures/opencode/context-plan.json +108 -0
- package/dist/data/scripts/harness-projection/test-fixtures/opencode/matrix.json +19 -0
- package/dist/data/scripts/harness-projection/test-fixtures/opencode/projection.json +51 -0
- package/dist/data/scripts/sync-subagents.mjs +1113 -33
- package/dist/data/subagents/manifest.mjs +5 -6
- package/dist/index.js +1375 -62557
- package/dist/skills/agnostic/cli/hi-cli/SKILL.md +22 -15
- package/dist/skills/agnostic/cli/hi-cli/references/commands.md +21 -5
- package/dist/skills/agnostic/cli/hi-cli/references/post-command-flow.md +87 -55
- package/dist/skills/agnostic/docs/docs-onboarding/SKILL.md +1 -1
- package/dist/skills/agnostic/docs/docs-onboarding/references/artifact-contract.md +2 -2
- package/dist/skills/agnostic/planning/create-plan/SKILL.md +12 -11
- package/dist/skills/agnostic/planning/create-plan/references/grill-ambiguity.md +10 -31
- package/dist/skills/agnostic/planning/create-plan/references/plan-schema.md +20 -2
- package/dist/skills/agnostic/planning/create-spec/SKILL.md +3 -5
- package/dist/skills/agnostic/planning/create-spec/assets/SPEC-TEMPLATE.md +1 -0
- package/dist/skills/agnostic/planning/create-spec/references/backlog-sync.md +2 -2
- package/dist/skills/agnostic/planning/create-spec/references/grill-phase.md +4 -9
- package/dist/skills/agnostic/planning/create-spec/references/spec-quality-bar.md +1 -0
- package/dist/skills/agnostic/planning/implement-spec/SKILL.md +3 -1
- package/dist/skills/agnostic/planning/implement-spec/assets/IMPLEMENTATION-NOTES-TEMPLATE.md +6 -0
- package/dist/skills/agnostic/planning/implement-spec/references/lifecycle.md +12 -1
- package/dist/skills/agnostic/planning/implement-spec/references/parallel-orchestration.md +5 -0
- package/dist/skills/agnostic/planning/implement-spec/references/parallel-worker-brief.md +7 -0
- package/dist/skills/agnostic/planning/implement-spec/references/runtime-product-validation.md +50 -0
- package/dist/skills/agnostic/planning/implement-spec/references/sequential.md +7 -5
- package/dist/skills/agnostic/requirements/grilling/LICENSE +21 -0
- package/dist/skills/agnostic/requirements/grilling/SKILL.md +6 -30
- package/dist/skills/agnostic/requirements/grilling/UPSTREAM.md +16 -0
- package/dist/skills/agnostic/requirements/requirements-grill/SKILL.md +3 -5
- package/dist/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +40 -16
- package/dist/skills/agnostic/requirements/requirements-grill/references/grilling-flow.md +3 -16
- package/dist/skills/agnostic/requirements/write-backlog/REFERENCE.md +21 -15
- package/dist/skills/agnostic/requirements/write-backlog/SKILL.md +14 -14
- package/dist/skills/agnostic/requirements/write-backlog/assets/concepts/backlog-model.md +28 -9
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/azure-devops-create-payload.md +45 -5
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/github-projects-create-payload.md +48 -28
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/linear-create-payload.md +22 -6
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/monday-create-payload.md +47 -22
- package/dist/skills/frameworks/effect/effect/LICENSE +21 -0
- package/dist/skills/frameworks/effect/effect/SKILL.md +100 -0
- package/dist/skills/frameworks/effect/effect/UPSTREAM.md +11 -0
- package/dist/skills/frameworks/effect/effect/references/CACHING.md +76 -0
- package/dist/skills/frameworks/effect/effect/references/CONFIG.md +67 -0
- package/dist/skills/frameworks/effect/effect/references/HTTP_CLIENTS.md +101 -0
- package/dist/skills/frameworks/effect/{effect-authoring/references/otel-patterns.md → effect/references/OBSERVABILITY.md} +4 -29
- package/dist/skills/frameworks/effect/effect/references/SCHEDULING.md +135 -0
- package/dist/skills/frameworks/effect/effect/references/SCHEMA.md +130 -0
- package/dist/skills/frameworks/effect/effect/references/SERVICES_LAYERS.md +168 -0
- package/dist/skills/frameworks/effect/effect/references/STREAMS.md +135 -0
- package/dist/skills/frameworks/effect/effect/references/TESTING.md +118 -0
- package/dist/skills/frameworks/effect/effect-backend-structure/SKILL.md +7 -8
- package/dist/skills/frameworks/effect/effect-recoverable-actions/SKILL.md +1 -1
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/.gitignore +29 -0
- package/dist/skills/misc/secrets-cli/SKILL.md +54 -0
- package/dist/skills/misc/secrets-cli/references/command-reference.md +107 -0
- package/dist/skills/misc/secrets-cli/references/safety-and-errors.md +54 -0
- package/dist/skills/misc/secrets-cli/references/workflows.md +106 -0
- package/dist/skills/phases/design-phase/phases/grill.md +1 -1
- package/dist/skills/phases/requirements-phase/SKILL.md +2 -4
- package/dist/skills/phases/review-phase/REFERENCE.md +13 -5
- package/dist/skills/phases/review-phase/SKILL.md +3 -2
- package/package.json +1 -1
- package/dist/skills/agnostic/planning/create-spec/references/handoff.md +0 -47
- package/dist/skills/frameworks/effect/effect-authoring/SKILL.md +0 -116
- package/dist/skills/frameworks/effect/effect-authoring/references/branded-types.md +0 -98
- package/dist/skills/frameworks/effect/effect-authoring/references/effect-primitives.md +0 -144
- package/dist/skills/frameworks/effect/effect-authoring/references/error-patterns.md +0 -156
- package/dist/skills/frameworks/effect/effect-authoring/references/test-patterns.md +0 -146
- package/dist/skills/frameworks/effect/effect-best-practices/SKILL.md +0 -517
- package/dist/skills/frameworks/effect/effect-best-practices/references/anti-patterns.md +0 -392
- package/dist/skills/frameworks/effect/effect-best-practices/references/effect-atom-patterns.md +0 -653
- package/dist/skills/frameworks/effect/effect-best-practices/references/error-patterns.md +0 -464
- package/dist/skills/frameworks/effect/effect-best-practices/references/language-server.md +0 -287
- package/dist/skills/frameworks/effect/effect-best-practices/references/layer-patterns.md +0 -495
- package/dist/skills/frameworks/effect/effect-best-practices/references/observability-patterns.md +0 -342
- package/dist/skills/frameworks/effect/effect-best-practices/references/rpc-cluster-patterns.md +0 -418
- package/dist/skills/frameworks/effect/effect-best-practices/references/schema-patterns.md +0 -353
- package/dist/skills/frameworks/effect/effect-best-practices/references/service-patterns.md +0 -299
- /package/dist/skills/frameworks/effect/{effect-authoring/references/effect-atom-patterns.md → effect/references/EFFECT_ATOM.md} +0 -0
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
# Anti-Patterns (Forbidden)
|
|
2
|
-
|
|
3
|
-
These patterns are **never acceptable** in Effect-TS code. Each is listed with rationale and the correct alternative.
|
|
4
|
-
|
|
5
|
-
## FORBIDDEN: Effect.runSync/runPromise Inside Services
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
// FORBIDDEN
|
|
9
|
-
export class UserService extends Effect.Service<UserService>()("UserService", {
|
|
10
|
-
effect: Effect.gen(function* () {
|
|
11
|
-
const findById = (id: UserId) => {
|
|
12
|
-
// Running effects synchronously breaks composition
|
|
13
|
-
const user = Effect.runSync(repo.findById(id))
|
|
14
|
-
return user
|
|
15
|
-
}
|
|
16
|
-
return { findById }
|
|
17
|
-
}),
|
|
18
|
-
}) {}
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
**Why:** Breaks Effect's composition model, loses error handling, can't be tested, loses tracing.
|
|
22
|
-
|
|
23
|
-
**Correct:**
|
|
24
|
-
```typescript
|
|
25
|
-
const findById = Effect.fn("UserService.findById")(function* (id: UserId) {
|
|
26
|
-
return yield* repo.findById(id)
|
|
27
|
-
})
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## FORBIDDEN: throw Inside Effect.gen
|
|
31
|
-
|
|
32
|
-
```typescript
|
|
33
|
-
// FORBIDDEN
|
|
34
|
-
yield* Effect.gen(function* () {
|
|
35
|
-
const user = yield* repo.findById(id)
|
|
36
|
-
if (!user) {
|
|
37
|
-
throw new Error("User not found") // Bypasses Effect error channel
|
|
38
|
-
}
|
|
39
|
-
return user
|
|
40
|
-
})
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
**Why:** Throws bypass Effect's error channel, can't be caught with `catchTag`, breaks type safety.
|
|
44
|
-
|
|
45
|
-
**Correct:**
|
|
46
|
-
```typescript
|
|
47
|
-
yield* Effect.gen(function* () {
|
|
48
|
-
const user = yield* repo.findById(id)
|
|
49
|
-
if (!user) {
|
|
50
|
-
return yield* Effect.fail(new UserNotFoundError({ userId: id, message: "Not found" }))
|
|
51
|
-
}
|
|
52
|
-
return user
|
|
53
|
-
})
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## FORBIDDEN: catchAll Losing Type Information
|
|
57
|
-
|
|
58
|
-
```typescript
|
|
59
|
-
// FORBIDDEN
|
|
60
|
-
yield* someEffect.pipe(
|
|
61
|
-
Effect.catchAll((err) =>
|
|
62
|
-
Effect.fail(new GenericError({ message: "Something failed" }))
|
|
63
|
-
)
|
|
64
|
-
)
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
**Why:** Loses specific error information, makes debugging harder, prevents specific error handling downstream.
|
|
68
|
-
|
|
69
|
-
**Correct:**
|
|
70
|
-
```typescript
|
|
71
|
-
yield* someEffect.pipe(
|
|
72
|
-
Effect.catchTags({
|
|
73
|
-
DatabaseError: (err) => Effect.fail(new ServiceUnavailableError({ message: err.message })),
|
|
74
|
-
ValidationError: (err) => Effect.fail(new BadRequestError({ message: err.message })),
|
|
75
|
-
}),
|
|
76
|
-
)
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## FORBIDDEN: any/unknown Casts
|
|
80
|
-
|
|
81
|
-
```typescript
|
|
82
|
-
// FORBIDDEN
|
|
83
|
-
const data = someValue as any
|
|
84
|
-
const result = (await fetch(url)) as unknown as MyType
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
**Why:** Completely bypasses type safety, can cause runtime errors, loses Effect's type guarantees.
|
|
88
|
-
|
|
89
|
-
**Correct:**
|
|
90
|
-
```typescript
|
|
91
|
-
// Use Schema for parsing unknown data
|
|
92
|
-
const result = yield* Schema.decodeUnknown(MyType)(someValue)
|
|
93
|
-
|
|
94
|
-
// Or explicit type guards
|
|
95
|
-
if (isMyType(someValue)) {
|
|
96
|
-
// Now safely typed
|
|
97
|
-
}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
## FORBIDDEN: Promise in Service Signatures
|
|
101
|
-
|
|
102
|
-
```typescript
|
|
103
|
-
// FORBIDDEN
|
|
104
|
-
export class UserService extends Effect.Service<UserService>()("UserService", {
|
|
105
|
-
effect: Effect.gen(function* () {
|
|
106
|
-
return {
|
|
107
|
-
findById: async (id: UserId): Promise<User> => {
|
|
108
|
-
// Using Promise instead of Effect
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}),
|
|
112
|
-
}) {}
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
**Why:** Loses Effect's error handling, can't compose with other Effects, loses tracing/metrics.
|
|
116
|
-
|
|
117
|
-
**Correct:**
|
|
118
|
-
```typescript
|
|
119
|
-
const findById = Effect.fn("UserService.findById")(
|
|
120
|
-
function* (id: UserId): Effect.Effect<User, UserNotFoundError> {
|
|
121
|
-
// ...
|
|
122
|
-
}
|
|
123
|
-
)
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## FORBIDDEN: console.log
|
|
127
|
-
|
|
128
|
-
```typescript
|
|
129
|
-
// FORBIDDEN
|
|
130
|
-
console.log("Processing order:", orderId)
|
|
131
|
-
console.error("Error:", error)
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
**Why:** Not structured, not captured by Effect's logging system, lost in production telemetry.
|
|
135
|
-
|
|
136
|
-
**Correct:**
|
|
137
|
-
```typescript
|
|
138
|
-
yield* Effect.log("Processing order", { orderId })
|
|
139
|
-
yield* Effect.logError("Operation failed", { error: String(error) })
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
## FORBIDDEN: process.env Directly
|
|
143
|
-
|
|
144
|
-
```typescript
|
|
145
|
-
// FORBIDDEN
|
|
146
|
-
const apiKey = process.env.API_KEY
|
|
147
|
-
const port = parseInt(process.env.PORT || "3000")
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
**Why:** No validation, no type safety, fails silently if missing, hard to test.
|
|
151
|
-
|
|
152
|
-
**Correct:**
|
|
153
|
-
```typescript
|
|
154
|
-
const config = yield* Config.all({
|
|
155
|
-
apiKey: Config.redacted("API_KEY"),
|
|
156
|
-
port: Config.integer("PORT").pipe(Config.withDefault(3000)),
|
|
157
|
-
})
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
## FORBIDDEN: Config.secret (Deprecated)
|
|
161
|
-
|
|
162
|
-
```typescript
|
|
163
|
-
// FORBIDDEN (deprecated)
|
|
164
|
-
const secretConfig = Config.all({
|
|
165
|
-
apiKey: Config.secret("API_KEY"),
|
|
166
|
-
dbPassword: Config.secret("DB_PASSWORD"),
|
|
167
|
-
})
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
**Why:** `Config.secret` is deprecated. Use `Config.redacted` instead, which provides the same functionality with better naming and can wrap any config type.
|
|
171
|
-
|
|
172
|
-
**Correct:**
|
|
173
|
-
```typescript
|
|
174
|
-
import { Config, Redacted } from "effect"
|
|
175
|
-
|
|
176
|
-
const secretConfig = Config.all({
|
|
177
|
-
apiKey: Config.redacted("API_KEY"), // Returns Redacted<string>
|
|
178
|
-
dbPassword: Config.redacted("DB_PASSWORD"),
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
// Using redacted values
|
|
182
|
-
const program = Effect.gen(function* () {
|
|
183
|
-
const { apiKey } = yield* secretConfig
|
|
184
|
-
const key = Redacted.value(apiKey) // Unwrap when needed
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
// Can wrap any config type
|
|
188
|
-
const secretNumber = Config.redacted(Config.integer("SECRET_PORT"))
|
|
189
|
-
// ^? Redacted<number>
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
## FORBIDDEN: null/undefined in Domain Types
|
|
193
|
-
|
|
194
|
-
```typescript
|
|
195
|
-
// FORBIDDEN
|
|
196
|
-
type User = {
|
|
197
|
-
name: string
|
|
198
|
-
bio: string | null
|
|
199
|
-
avatar: string | undefined
|
|
200
|
-
}
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
**Why:** Null/undefined handling is error-prone, loses the explicit "absence" semantics.
|
|
204
|
-
|
|
205
|
-
**Correct:**
|
|
206
|
-
```typescript
|
|
207
|
-
const User = Schema.Struct({
|
|
208
|
-
name: Schema.String,
|
|
209
|
-
bio: Schema.Option(Schema.String),
|
|
210
|
-
avatar: Schema.Option(Schema.String),
|
|
211
|
-
})
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
## FORBIDDEN: Option.getOrThrow
|
|
215
|
-
|
|
216
|
-
```typescript
|
|
217
|
-
// FORBIDDEN
|
|
218
|
-
const user = Option.getOrThrow(maybeUser)
|
|
219
|
-
const name = pipe(maybeName, Option.getOrThrow)
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
**Why:** Throws exceptions, bypasses Effect's error handling, fails at runtime instead of compile time.
|
|
223
|
-
|
|
224
|
-
**Correct:**
|
|
225
|
-
```typescript
|
|
226
|
-
// Handle both cases explicitly
|
|
227
|
-
yield* Option.match(maybeUser, {
|
|
228
|
-
onNone: () => Effect.fail(new UserNotFoundError({ userId, message: "Not found" })),
|
|
229
|
-
onSome: Effect.succeed,
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
// Or provide a default
|
|
233
|
-
const name = Option.getOrElse(maybeName, () => "Anonymous")
|
|
234
|
-
|
|
235
|
-
// Or use Option.map for transformations
|
|
236
|
-
const upperName = Option.map(maybeName, (n) => n.toUpperCase())
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
## FORBIDDEN: Context.Tag for Business Services
|
|
240
|
-
|
|
241
|
-
```typescript
|
|
242
|
-
// FORBIDDEN
|
|
243
|
-
export class UserService extends Context.Tag("UserService")<
|
|
244
|
-
UserService,
|
|
245
|
-
{ findById: (id: UserId) => Effect.Effect<User, UserNotFoundError> }
|
|
246
|
-
>() {
|
|
247
|
-
static Default = Layer.effect(this, Effect.gen(function* () { ... }))
|
|
248
|
-
}
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
**Why:** Requires manual layer creation, no built-in accessors, more boilerplate.
|
|
252
|
-
|
|
253
|
-
**Correct:**
|
|
254
|
-
```typescript
|
|
255
|
-
export class UserService extends Effect.Service<UserService>()("UserService", {
|
|
256
|
-
accessors: true,
|
|
257
|
-
dependencies: [...],
|
|
258
|
-
effect: Effect.gen(function* () { ... }),
|
|
259
|
-
}) {}
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
`Context.Tag` remains valid for externally supplied infrastructure. The forbidden part is hand-rolling business services with tags when `Effect.Service` should own the capability and its layer contract.
|
|
263
|
-
|
|
264
|
-
## FORBIDDEN: Module Mocks for Effect Services
|
|
265
|
-
|
|
266
|
-
```typescript
|
|
267
|
-
// FORBIDDEN
|
|
268
|
-
vi.mock("../repositories/user", () => ({
|
|
269
|
-
UserRepo: {
|
|
270
|
-
findById: vi.fn(),
|
|
271
|
-
},
|
|
272
|
-
}))
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
**Why:** Path-based mocks hide dependencies from Effect's environment, bypass layer composition, and can drift from the service shape.
|
|
276
|
-
|
|
277
|
-
**Correct:**
|
|
278
|
-
```typescript
|
|
279
|
-
const UserRepoTest = Layer.succeed(
|
|
280
|
-
UserRepo,
|
|
281
|
-
UserRepo.of({
|
|
282
|
-
findById: (id) => Effect.succeed(Option.some(makeUser({ id }))),
|
|
283
|
-
}),
|
|
284
|
-
)
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
## FORBIDDEN: Ignoring Errors with orDie
|
|
288
|
-
|
|
289
|
-
```typescript
|
|
290
|
-
// FORBIDDEN (in most cases)
|
|
291
|
-
yield* someEffect.pipe(Effect.orDie)
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
**Why:** Converts recoverable errors to defects (unrecoverable), loses error information.
|
|
295
|
-
|
|
296
|
-
**Acceptable exceptions:**
|
|
297
|
-
- Truly unrecoverable situations (invalid program state)
|
|
298
|
-
- After exhausting all recovery options
|
|
299
|
-
- In test setup code
|
|
300
|
-
|
|
301
|
-
**Correct:**
|
|
302
|
-
```typescript
|
|
303
|
-
// Handle errors explicitly
|
|
304
|
-
yield* someEffect.pipe(
|
|
305
|
-
Effect.catchTag("RecoverableError", (err) =>
|
|
306
|
-
Effect.fail(new DomainError({ message: err.message }))
|
|
307
|
-
),
|
|
308
|
-
)
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
## FORBIDDEN: mapError Instead of catchTag
|
|
312
|
-
|
|
313
|
-
```typescript
|
|
314
|
-
// FORBIDDEN
|
|
315
|
-
yield* effect.pipe(
|
|
316
|
-
Effect.mapError((err) => new GenericError({ message: String(err) }))
|
|
317
|
-
)
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
**Why:** Loses error type information, can't discriminate between error types.
|
|
321
|
-
|
|
322
|
-
**Correct:**
|
|
323
|
-
```typescript
|
|
324
|
-
yield* effect.pipe(
|
|
325
|
-
Effect.catchTag("SpecificError", (err) =>
|
|
326
|
-
Effect.fail(new MappedError({ message: err.message }))
|
|
327
|
-
),
|
|
328
|
-
)
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
## FORBIDDEN: Mixing Effect and Promise Chains
|
|
332
|
-
|
|
333
|
-
```typescript
|
|
334
|
-
// FORBIDDEN
|
|
335
|
-
const result = await someEffect.pipe(
|
|
336
|
-
Effect.runPromise,
|
|
337
|
-
).then(data => {
|
|
338
|
-
// Mixing Promise chain with Effect
|
|
339
|
-
return Effect.runPromise(anotherEffect(data))
|
|
340
|
-
})
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
**Why:** Loses Effect composition benefits, error handling becomes inconsistent.
|
|
344
|
-
|
|
345
|
-
**Correct:**
|
|
346
|
-
```typescript
|
|
347
|
-
const program = Effect.gen(function* () {
|
|
348
|
-
const data = yield* someEffect
|
|
349
|
-
return yield* anotherEffect(data)
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
const result = await Effect.runPromise(program)
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
## FORBIDDEN: Mutable State Without Ref
|
|
356
|
-
|
|
357
|
-
```typescript
|
|
358
|
-
// FORBIDDEN
|
|
359
|
-
let counter = 0
|
|
360
|
-
const increment = Effect.sync(() => { counter++ })
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
**Why:** Race conditions, not testable, not composable, breaks referential transparency.
|
|
364
|
-
|
|
365
|
-
**Correct:**
|
|
366
|
-
```typescript
|
|
367
|
-
const program = Effect.gen(function* () {
|
|
368
|
-
const counter = yield* Ref.make(0)
|
|
369
|
-
yield* Ref.update(counter, (n) => n + 1)
|
|
370
|
-
return yield* Ref.get(counter)
|
|
371
|
-
})
|
|
372
|
-
```
|
|
373
|
-
|
|
374
|
-
## FORBIDDEN: Using Date.now() or new Date() Directly
|
|
375
|
-
|
|
376
|
-
```typescript
|
|
377
|
-
// FORBIDDEN
|
|
378
|
-
const now = new Date()
|
|
379
|
-
const timestamp = Date.now()
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
**Why:** Not testable, introduces non-determinism, hard to mock in tests.
|
|
383
|
-
|
|
384
|
-
**Correct:**
|
|
385
|
-
```typescript
|
|
386
|
-
import { Clock } from "effect"
|
|
387
|
-
|
|
388
|
-
const now = yield* Clock.currentTimeMillis
|
|
389
|
-
const date = yield* Clock.currentTimeZone.pipe(
|
|
390
|
-
Effect.map((tz) => new Date())
|
|
391
|
-
)
|
|
392
|
-
```
|