@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
package/dist/skills/frameworks/effect/effect-best-practices/references/rpc-cluster-patterns.md
DELETED
|
@@ -1,418 +0,0 @@
|
|
|
1
|
-
# RPC & Cluster Patterns
|
|
2
|
-
|
|
3
|
-
## RpcGroup for API Organization
|
|
4
|
-
|
|
5
|
-
**Use `RpcGroup.make`** to organize related RPC endpoints:
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
import { Rpc, RpcGroup } from "@effect/rpc"
|
|
9
|
-
import { Schema } from "effect"
|
|
10
|
-
|
|
11
|
-
// Group related operations
|
|
12
|
-
export const UserRpc = RpcGroup.make("User", {
|
|
13
|
-
// Queries (read operations)
|
|
14
|
-
findById: Rpc.query({
|
|
15
|
-
input: UserId,
|
|
16
|
-
output: User,
|
|
17
|
-
error: UserNotFoundError,
|
|
18
|
-
}),
|
|
19
|
-
|
|
20
|
-
list: Rpc.query({
|
|
21
|
-
input: Schema.Struct({
|
|
22
|
-
organizationId: OrganizationId,
|
|
23
|
-
limit: Schema.optionalWith(Schema.Number, { default: () => 50 }),
|
|
24
|
-
offset: Schema.optionalWith(Schema.Number, { default: () => 0 }),
|
|
25
|
-
}),
|
|
26
|
-
output: Schema.Array(User),
|
|
27
|
-
error: Schema.Never,
|
|
28
|
-
}),
|
|
29
|
-
|
|
30
|
-
// Mutations (write operations)
|
|
31
|
-
create: Rpc.mutation({
|
|
32
|
-
input: CreateUserInput,
|
|
33
|
-
output: User,
|
|
34
|
-
error: Schema.Union(UserCreateError, ValidationError),
|
|
35
|
-
}),
|
|
36
|
-
|
|
37
|
-
update: Rpc.mutation({
|
|
38
|
-
input: Schema.Struct({
|
|
39
|
-
id: UserId,
|
|
40
|
-
data: UpdateUserInput,
|
|
41
|
-
}),
|
|
42
|
-
output: User,
|
|
43
|
-
error: Schema.Union(UserNotFoundError, ValidationError),
|
|
44
|
-
}),
|
|
45
|
-
|
|
46
|
-
delete: Rpc.mutation({
|
|
47
|
-
input: UserId,
|
|
48
|
-
output: Schema.Void,
|
|
49
|
-
error: UserNotFoundError,
|
|
50
|
-
}),
|
|
51
|
-
})
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Query vs Mutation
|
|
55
|
-
|
|
56
|
-
- **Rpc.query** - Read operations, idempotent, cacheable
|
|
57
|
-
- **Rpc.mutation** - Write operations, may have side effects
|
|
58
|
-
|
|
59
|
-
```typescript
|
|
60
|
-
// Query - safe to retry, can be cached
|
|
61
|
-
findById: Rpc.query({ ... }),
|
|
62
|
-
search: Rpc.query({ ... }),
|
|
63
|
-
list: Rpc.query({ ... }),
|
|
64
|
-
|
|
65
|
-
// Mutation - may modify state
|
|
66
|
-
create: Rpc.mutation({ ... }),
|
|
67
|
-
update: Rpc.mutation({ ... }),
|
|
68
|
-
delete: Rpc.mutation({ ... }),
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## Error Unions in RPC
|
|
72
|
-
|
|
73
|
-
**Always use explicit error unions** for RPC error types:
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
// Explicit union of possible errors
|
|
77
|
-
create: Rpc.mutation({
|
|
78
|
-
input: CreateOrderInput,
|
|
79
|
-
output: Order,
|
|
80
|
-
error: Schema.Union(
|
|
81
|
-
ValidationError,
|
|
82
|
-
InsufficientInventoryError,
|
|
83
|
-
PaymentFailedError,
|
|
84
|
-
UserNotFoundError,
|
|
85
|
-
),
|
|
86
|
-
}),
|
|
87
|
-
|
|
88
|
-
// NOT - generic error type
|
|
89
|
-
create: Rpc.mutation({
|
|
90
|
-
input: CreateOrderInput,
|
|
91
|
-
output: Order,
|
|
92
|
-
error: GenericError, // WRONG - loses type information
|
|
93
|
-
}),
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
## RPC Middleware for Authentication
|
|
97
|
-
|
|
98
|
-
```typescript
|
|
99
|
-
import { RpcMiddleware, Rpc } from "@effect/rpc"
|
|
100
|
-
import { Effect, Layer } from "effect"
|
|
101
|
-
|
|
102
|
-
// Context type for authenticated user
|
|
103
|
-
export class CurrentUser extends Context.Tag("CurrentUser")<
|
|
104
|
-
CurrentUser,
|
|
105
|
-
{ id: UserId; role: UserRole; organizationId: OrganizationId }
|
|
106
|
-
>() {}
|
|
107
|
-
|
|
108
|
-
// Auth middleware - extracts and validates auth
|
|
109
|
-
export class AuthMiddleware extends RpcMiddleware.Tag<AuthMiddleware>()(
|
|
110
|
-
"AuthMiddleware",
|
|
111
|
-
{
|
|
112
|
-
provides: CurrentUser,
|
|
113
|
-
failure: UnauthorizedError,
|
|
114
|
-
}
|
|
115
|
-
) {}
|
|
116
|
-
|
|
117
|
-
// Middleware implementation
|
|
118
|
-
export const AuthMiddlewareLive = Layer.effect(
|
|
119
|
-
AuthMiddleware,
|
|
120
|
-
Effect.gen(function* () {
|
|
121
|
-
const authService = yield* AuthService
|
|
122
|
-
|
|
123
|
-
return AuthMiddleware.of({
|
|
124
|
-
execute: (request) =>
|
|
125
|
-
Effect.gen(function* () {
|
|
126
|
-
const token = request.headers.get("authorization")?.replace("Bearer ", "")
|
|
127
|
-
|
|
128
|
-
if (!token) {
|
|
129
|
-
return yield* Effect.fail(new UnauthorizedError({ message: "Missing token" }))
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const user = yield* authService.validateToken(token).pipe(
|
|
133
|
-
Effect.catchTag("TokenExpiredError", () =>
|
|
134
|
-
Effect.fail(new UnauthorizedError({ message: "Token expired" }))
|
|
135
|
-
),
|
|
136
|
-
Effect.catchTag("TokenInvalidError", () =>
|
|
137
|
-
Effect.fail(new UnauthorizedError({ message: "Invalid token" }))
|
|
138
|
-
),
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
return user
|
|
142
|
-
}),
|
|
143
|
-
})
|
|
144
|
-
})
|
|
145
|
-
)
|
|
146
|
-
|
|
147
|
-
// Protected RPC using middleware
|
|
148
|
-
export const ProtectedUserRpc = UserRpc.middleware(AuthMiddleware)
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
## Workflow Definition
|
|
152
|
-
|
|
153
|
-
**Use `Workflow.make`** with explicit idempotency keys:
|
|
154
|
-
|
|
155
|
-
```typescript
|
|
156
|
-
import { Workflow } from "@effect/cluster"
|
|
157
|
-
import { Schema } from "effect"
|
|
158
|
-
|
|
159
|
-
export const OrderFulfillmentWorkflow = Workflow.make({
|
|
160
|
-
name: "OrderFulfillmentWorkflow",
|
|
161
|
-
payload: {
|
|
162
|
-
id: OrderId, // Execution ID
|
|
163
|
-
orderId: OrderId,
|
|
164
|
-
userId: UserId,
|
|
165
|
-
items: Schema.Array(OrderItem),
|
|
166
|
-
shippingAddress: ShippingAddress,
|
|
167
|
-
},
|
|
168
|
-
// Idempotency key prevents duplicate processing
|
|
169
|
-
idempotencyKey: ({ orderId }) => orderId,
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
export const NotificationWorkflow = Workflow.make({
|
|
173
|
-
name: "NotificationWorkflow",
|
|
174
|
-
payload: {
|
|
175
|
-
id: Schema.String, // Unique execution ID
|
|
176
|
-
messageId: MessageId,
|
|
177
|
-
channelId: ChannelId,
|
|
178
|
-
authorId: UserId,
|
|
179
|
-
},
|
|
180
|
-
idempotencyKey: ({ messageId }) => messageId,
|
|
181
|
-
})
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
### Workflow Implementation
|
|
185
|
-
|
|
186
|
-
```typescript
|
|
187
|
-
import { Activity } from "@effect/workflow"
|
|
188
|
-
import { Effect } from "effect"
|
|
189
|
-
|
|
190
|
-
export const OrderFulfillmentWorkflowLayer = OrderFulfillmentWorkflow.toLayer(
|
|
191
|
-
Effect.fn("OrderFulfillmentWorkflow")(function* (payload) {
|
|
192
|
-
// Step 1: Reserve inventory
|
|
193
|
-
const reservation = yield* Activity.make({
|
|
194
|
-
name: "ReserveInventory",
|
|
195
|
-
success: InventoryReservation,
|
|
196
|
-
error: Schema.Union(InsufficientInventoryError, DatabaseError),
|
|
197
|
-
execute: Effect.gen(function* () {
|
|
198
|
-
const inventory = yield* InventoryService
|
|
199
|
-
return yield* inventory.reserve(payload.items)
|
|
200
|
-
}),
|
|
201
|
-
})
|
|
202
|
-
|
|
203
|
-
// Step 2: Process payment
|
|
204
|
-
const payment = yield* Activity.make({
|
|
205
|
-
name: "ProcessPayment",
|
|
206
|
-
success: PaymentResult,
|
|
207
|
-
error: Schema.Union(PaymentFailedError, PaymentTimeoutError),
|
|
208
|
-
execute: Effect.gen(function* () {
|
|
209
|
-
const payments = yield* PaymentService
|
|
210
|
-
return yield* payments.charge(payload.userId, payload.items)
|
|
211
|
-
}),
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
// Step 3: Create shipment
|
|
215
|
-
const shipment = yield* Activity.make({
|
|
216
|
-
name: "CreateShipment",
|
|
217
|
-
success: Shipment,
|
|
218
|
-
error: Schema.Union(ShippingError, AddressInvalidError),
|
|
219
|
-
execute: Effect.gen(function* () {
|
|
220
|
-
const shipping = yield* ShippingService
|
|
221
|
-
return yield* shipping.createShipment({
|
|
222
|
-
items: payload.items,
|
|
223
|
-
address: payload.shippingAddress,
|
|
224
|
-
reservationId: reservation.id,
|
|
225
|
-
})
|
|
226
|
-
}),
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
// Step 4: Send confirmation
|
|
230
|
-
yield* Activity.make({
|
|
231
|
-
name: "SendConfirmation",
|
|
232
|
-
success: Schema.Void,
|
|
233
|
-
error: NotificationError,
|
|
234
|
-
execute: Effect.gen(function* () {
|
|
235
|
-
const notifications = yield* NotificationService
|
|
236
|
-
yield* notifications.sendOrderConfirmation({
|
|
237
|
-
userId: payload.userId,
|
|
238
|
-
orderId: payload.orderId,
|
|
239
|
-
trackingNumber: shipment.trackingNumber,
|
|
240
|
-
})
|
|
241
|
-
}),
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
return { shipment, payment }
|
|
245
|
-
})
|
|
246
|
-
)
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
## Activity Patterns
|
|
250
|
-
|
|
251
|
-
**Always include `success` and `error` schemas** in Activity.make:
|
|
252
|
-
|
|
253
|
-
```typescript
|
|
254
|
-
// CORRECT - schemas specified
|
|
255
|
-
yield* Activity.make({
|
|
256
|
-
name: "SendEmail",
|
|
257
|
-
success: EmailSentResult,
|
|
258
|
-
error: Schema.Union(EmailDeliveryError, EmailTemplateError),
|
|
259
|
-
execute: Effect.gen(function* () {
|
|
260
|
-
// Implementation
|
|
261
|
-
return { messageId: "msg-123", sentAt: new Date() }
|
|
262
|
-
}),
|
|
263
|
-
})
|
|
264
|
-
|
|
265
|
-
// WRONG - missing schemas
|
|
266
|
-
yield* Activity.make({
|
|
267
|
-
name: "SendEmail",
|
|
268
|
-
execute: Effect.gen(function* () {
|
|
269
|
-
// This will not serialize properly across workflow restarts
|
|
270
|
-
}),
|
|
271
|
-
})
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
### Activity Error Handling with Retryable
|
|
275
|
-
|
|
276
|
-
```typescript
|
|
277
|
-
export class ExternalApiError extends Schema.TaggedError<ExternalApiError>()(
|
|
278
|
-
"ExternalApiError",
|
|
279
|
-
{
|
|
280
|
-
message: Schema.String,
|
|
281
|
-
statusCode: Schema.Number,
|
|
282
|
-
retryable: Schema.Boolean,
|
|
283
|
-
},
|
|
284
|
-
) {
|
|
285
|
-
static fromResponse(response: Response): ExternalApiError {
|
|
286
|
-
return new ExternalApiError({
|
|
287
|
-
message: `API error: ${response.statusText}`,
|
|
288
|
-
statusCode: response.status,
|
|
289
|
-
retryable: response.status >= 500, // 5xx errors are retryable
|
|
290
|
-
})
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
yield* Activity.make({
|
|
295
|
-
name: "CallExternalApi",
|
|
296
|
-
success: ApiResponse,
|
|
297
|
-
error: ExternalApiError,
|
|
298
|
-
execute: Effect.gen(function* () {
|
|
299
|
-
const response = yield* fetch(url)
|
|
300
|
-
if (!response.ok) {
|
|
301
|
-
return yield* Effect.fail(ExternalApiError.fromResponse(response))
|
|
302
|
-
}
|
|
303
|
-
return yield* response.json()
|
|
304
|
-
}),
|
|
305
|
-
})
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
## ClusterCron for Scheduled Jobs
|
|
309
|
-
|
|
310
|
-
```typescript
|
|
311
|
-
import { ClusterCron } from "@effect/cluster"
|
|
312
|
-
|
|
313
|
-
export const DailyReportCron = ClusterCron.make({
|
|
314
|
-
name: "DailyReportCron",
|
|
315
|
-
// Cron expression: every day at 6 AM UTC
|
|
316
|
-
schedule: "0 6 * * *",
|
|
317
|
-
})
|
|
318
|
-
|
|
319
|
-
// Implementation
|
|
320
|
-
export const DailyReportCronLayer = DailyReportCron.toLayer(
|
|
321
|
-
Effect.fn("DailyReportCron")(function* () {
|
|
322
|
-
yield* Effect.log("Starting daily report generation")
|
|
323
|
-
|
|
324
|
-
const reports = yield* ReportService
|
|
325
|
-
yield* reports.generateDailyReport()
|
|
326
|
-
|
|
327
|
-
yield* Effect.log("Daily report generation complete")
|
|
328
|
-
})
|
|
329
|
-
)
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
## Triggering Workflows
|
|
333
|
-
|
|
334
|
-
### From HTTP Handler
|
|
335
|
-
|
|
336
|
-
```typescript
|
|
337
|
-
import { HttpApi, HttpApiEndpoint } from "@effect/platform"
|
|
338
|
-
|
|
339
|
-
const createOrder = HttpApiEndpoint.post("createOrder", "/orders")
|
|
340
|
-
.setPayload(CreateOrderInput)
|
|
341
|
-
.addSuccess(Order)
|
|
342
|
-
.addError(ValidationError)
|
|
343
|
-
|
|
344
|
-
// Handler triggers workflow
|
|
345
|
-
const createOrderHandler = Effect.gen(function* () {
|
|
346
|
-
const input = yield* HttpApi.payload
|
|
347
|
-
const workflowClient = yield* WorkflowClient
|
|
348
|
-
|
|
349
|
-
// Create order in database
|
|
350
|
-
const order = yield* OrderService.create(input)
|
|
351
|
-
|
|
352
|
-
// Trigger async fulfillment workflow
|
|
353
|
-
yield* workflowClient.workflows.OrderFulfillmentWorkflow.execute({
|
|
354
|
-
id: order.id,
|
|
355
|
-
orderId: order.id,
|
|
356
|
-
userId: input.userId,
|
|
357
|
-
items: input.items,
|
|
358
|
-
shippingAddress: input.shippingAddress,
|
|
359
|
-
})
|
|
360
|
-
|
|
361
|
-
return order
|
|
362
|
-
})
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
### From Backend Service
|
|
366
|
-
|
|
367
|
-
```typescript
|
|
368
|
-
export class MessageService extends Effect.Service<MessageService>()("MessageService", {
|
|
369
|
-
accessors: true,
|
|
370
|
-
dependencies: [MessageRepo.Default, WorkflowClient.Default],
|
|
371
|
-
effect: Effect.gen(function* () {
|
|
372
|
-
const repo = yield* MessageRepo
|
|
373
|
-
const workflows = yield* WorkflowClient
|
|
374
|
-
|
|
375
|
-
const create = Effect.fn("MessageService.create")(function* (input: CreateMessageInput) {
|
|
376
|
-
const message = yield* repo.create(input)
|
|
377
|
-
|
|
378
|
-
// Trigger notification workflow
|
|
379
|
-
yield* workflows.workflows.NotificationWorkflow.execute({
|
|
380
|
-
id: message.id,
|
|
381
|
-
messageId: message.id,
|
|
382
|
-
channelId: message.channelId,
|
|
383
|
-
authorId: message.authorId,
|
|
384
|
-
})
|
|
385
|
-
|
|
386
|
-
return message
|
|
387
|
-
})
|
|
388
|
-
|
|
389
|
-
return { create }
|
|
390
|
-
}),
|
|
391
|
-
}) {}
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
## Workflow HTTP API
|
|
395
|
-
|
|
396
|
-
```typescript
|
|
397
|
-
// Expose workflow execution via HTTP
|
|
398
|
-
const executeWorkflow = HttpApiEndpoint.post("executeWorkflow", "/workflows/:name/execute")
|
|
399
|
-
.setPath(Schema.Struct({ name: Schema.String }))
|
|
400
|
-
.setPayload(Schema.Unknown)
|
|
401
|
-
.addSuccess(Schema.Struct({ executionId: Schema.String }))
|
|
402
|
-
.addError(WorkflowNotFoundError)
|
|
403
|
-
|
|
404
|
-
// Handler
|
|
405
|
-
const executeWorkflowHandler = Effect.gen(function* () {
|
|
406
|
-
const { name } = yield* HttpApi.path
|
|
407
|
-
const payload = yield* HttpApi.payload
|
|
408
|
-
const client = yield* WorkflowClient
|
|
409
|
-
|
|
410
|
-
const workflow = client.workflows[name]
|
|
411
|
-
if (!workflow) {
|
|
412
|
-
return yield* Effect.fail(new WorkflowNotFoundError({ name }))
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
const result = yield* workflow.execute(payload)
|
|
416
|
-
return { executionId: payload.id }
|
|
417
|
-
})
|
|
418
|
-
```
|