@akanjs/cli 3.0.0-alpha.70 → 3.0.0-alpha.71
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/.build-stamp +1 -1
- package/{agent.command-964bf8qg.js → agent.command-xdvw642m.js} +5 -5
- package/{application.command-n45n18sc.js → application.command-g3f7xj25.js} +27 -4
- package/buildBatch.proc.js +1 -1
- package/{capacitorApp-vnvnvdhf.js → capacitorApp-b0ppke3m.js} +2 -2
- package/{cloud.command-kx1bh5yq.js → cloud.command-0hmsv44q.js} +7 -7
- package/commandManifest.json +1 -1
- package/{context.command-g1a65x6j.js → context.command-x92afrnf.js} +12 -12
- package/{guideline.command-xphyhvwh.js → guideline.command-hpq08q66.js} +2 -2
- package/guidelines/conventions/conventions.instruction.md +255 -436
- package/guidelines/framework/framework.generate.json +3 -2
- package/guidelines/framework/framework.instruction.md +0 -9
- package/guidelines/mcpRule/mcpRule.instruction.md +5 -8
- package/guidelines/queryRule/queryRule.generate.json +31 -0
- package/guidelines/queryRule/queryRule.instruction.md +143 -0
- package/guidelines/runtimeRule/runtimeRule.generate.json +25 -0
- package/guidelines/runtimeRule/runtimeRule.instruction.md +176 -0
- package/guidelines/transportRule/transportRule.generate.json +31 -0
- package/guidelines/transportRule/transportRule.instruction.md +60 -0
- package/guidelines/workspaceOnboarding/workspaceOnboarding.instruction.md +17 -392
- package/guidelines/workspaceRecipes/workspaceRecipes.generate.json +33 -0
- package/guidelines/workspaceRecipes/workspaceRecipes.instruction.md +402 -0
- package/incrementalBuilder.proc.js +1 -1
- package/{index-nkwmnqwn.js → index-5f4gnt4c.js} +1 -0
- package/{index-va15r8h5.js → index-6d5r8q6k.js} +2 -2
- package/{index-4rw4qhe6.js → index-737aj4fm.js} +3 -3
- package/{index-ytaqtc04.js → index-8besc14m.js} +1 -1
- package/{index-hee7egtm.js → index-cbfp5wyp.js} +1 -1
- package/{index-mkn5qagt.js → index-cp00yns2.js} +70 -4
- package/{index-nj3w0r34.js → index-ety6takb.js} +3 -3
- package/{index-e31ghfp5.js → index-gvq17wqn.js} +1 -1
- package/{index-8gybxemv.js → index-hs70d8ed.js} +5 -5
- package/{index-0ngvvgry.js → index-jybbmwed.js} +2 -2
- package/{index-bqqts262.js → index-m5gfc86a.js} +1 -1
- package/{index-qt4nfr0n.js → index-nq3avsf6.js} +10 -10
- package/{index-yg3hxk2k.js → index-p27h7535.js} +4 -4
- package/{index-fahkq20v.js → index-pehn44hr.js} +3 -3
- package/{index-v5fdxdre.js → index-r691v756.js} +2 -2
- package/{index-p681w089.js → index-sqsfv8wg.js} +2 -2
- package/{index-rbnpe8cp.js → index-wbbswwqt.js} +17 -21
- package/{index-rb65xnw9.js → index-wybbcgxn.js} +4 -4
- package/index.js +18 -18
- package/{library.command-rfpd27yv.js → library.command-8vgrdtwy.js} +3 -3
- package/{localRegistry.command-pyxfe0fs.js → localRegistry.command-0gtqj0r0.js} +6 -6
- package/{module.command-qhaxad0p.js → module.command-rama4zya.js} +5 -5
- package/{package.command-2k22q9nt.js → package.command-6jxapdsg.js} +3 -3
- package/package.json +2 -2
- package/{page.command-ymk9dqh4.js → page.command-hxy7x525.js} +3 -3
- package/{primitive.command-9k45zpc1.js → primitive.command-4bf6xcc3.js} +6 -6
- package/{quality.command-bf6vkxe5.js → quality.command-h5edwegz.js} +2 -2
- package/{repair.command-egvvm6xf.js → repair.command-rgqf6px6.js} +5 -5
- package/{scalar.command-bt1facyj.js → scalar.command-6krkz6tw.js} +4 -4
- package/templates/workspaceRoot/AGENTS.md.template +4 -0
- package/{workflow.command-v1n3wg7v.js → workflow.command-dwhwrqhd.js} +9 -9
- package/{workspace.command-yvvqvhzz.js → workspace.command-f5h11gjn.js} +18 -18
|
@@ -202,340 +202,23 @@ final fallback when no CLI command covers the change.
|
|
|
202
202
|
|
|
203
203
|
## Workflow Recipes
|
|
204
204
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
title: field(String),
|
|
223
|
-
priority: field(TaskPriority, { default: "medium" }), // NEW FIELD
|
|
224
|
-
})) {}
|
|
225
|
-
|
|
226
|
-
// If the new field should appear in list views, also add it to LightTask:
|
|
227
|
-
export class LightTask extends via(TaskObject, ["title", "priority", "status", "due"] as const, () => ({})) {}
|
|
228
|
-
|
|
229
|
-
// 2. apps/<app>/lib/<model>/<model>.dictionary.ts
|
|
230
|
-
// Add i18n labels for the new field (and its enum values if any).
|
|
231
|
-
// Labels are [en, ko] pairs, and nearly every one also carries a .desc([en, ko]).
|
|
232
|
-
.model<Task>((t) => ({
|
|
233
|
-
priority: t(["Priority", "우선순위"]).desc(["How urgent the task is", "할 일의 긴급도"]),
|
|
234
|
-
}))
|
|
235
|
-
.enum<TaskPriority>("taskPriority", (t) => ({
|
|
236
|
-
low: t(["Low", "낮음"]),
|
|
237
|
-
medium: t(["Medium", "보통"]),
|
|
238
|
-
high: t(["High", "높음"]),
|
|
239
|
-
}))
|
|
240
|
-
|
|
241
|
-
// 3. apps/<app>/lib/<model>/<Model>.Template.tsx
|
|
242
|
-
// Add a form field using st.do.setXxxOnYyy (auto-generated setter)
|
|
243
|
-
const form = st.use.taskForm();
|
|
244
|
-
<Field.ToggleSelect
|
|
245
|
-
label={l("task.priority")}
|
|
246
|
-
items={cnst.TaskPriority}
|
|
247
|
-
value={form.priority}
|
|
248
|
-
onChange={st.do.setPriorityOnTask}
|
|
249
|
-
/>
|
|
250
|
-
|
|
251
|
-
// 4. apps/<app>/lib/<model>/<Model>.Unit.tsx
|
|
252
|
-
// Display the new field in card/list views
|
|
253
|
-
<Badge variant={task.priority === "high" ? "error" : task.priority === "medium" ? "warning" : "default"}>
|
|
254
|
-
{task.priority}
|
|
255
|
-
</Badge>
|
|
256
|
-
|
|
257
|
-
// 5. Regenerate barrels
|
|
258
|
-
// akan sync <name>
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
---
|
|
262
|
-
|
|
263
|
-
### Recipe 2: Injecting a Dependency into a Service
|
|
264
|
-
|
|
265
|
-
Three patterns: injecting an **external adapter** (`use<>()`), another **module's service** (`service<>()`),
|
|
266
|
-
or a **predefined framework adapter** (`plug()`). A field named `<refName>Service` resolves to the service
|
|
267
|
-
registered under `<refName>` — the `Service`/`Signal` suffix is required and stripped to derive the lookup key.
|
|
268
|
-
|
|
269
|
-
> **For a new adapter you own, prefer the `adapt()` shape in pattern C over the `option.ts` registration in
|
|
270
|
-
> pattern A.** An `adapt()` class self-registers and is injected with `plug(TheClass)`, so it never touches
|
|
271
|
-
> `option.ts`. Pattern A is the legacy constructor-style shape: recognise it, keep it working, and migrate one
|
|
272
|
-
> only when you are already changing it.
|
|
273
|
-
|
|
274
|
-
> `apps/<app>/lib/option.ts` is a **user-owned** file scaffolded once — edit it to register adapters/DI. Unlike the
|
|
275
|
-
> barrels (`cnst.ts`, `db.ts`, `srv.ts`, …) it is **not** overwritten by `akan sync`, so your `.use(...)` registrations
|
|
276
|
-
> are safe.
|
|
277
|
-
|
|
278
|
-
**A. Adapter injection via `use<>()` (for external clients / global singletons)**
|
|
279
|
-
|
|
280
|
-
```typescript
|
|
281
|
-
// 1. Create the adapter class in apps/<app>/srvkit/
|
|
282
|
-
// apps/<app>/srvkit/EmailClient.ts
|
|
283
|
-
export class EmailClient {
|
|
284
|
-
constructor(readonly apiKey: string) {}
|
|
285
|
-
async send(opts: { to: string; subject: string; body: string }) { /* ... */ }
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// 2. Register in apps/<app>/lib/option.ts
|
|
289
|
-
export const option = new AkanOption()
|
|
290
|
-
.use((options) => ({
|
|
291
|
-
emailClient: new EmailClient(options.mailerApiKey),
|
|
292
|
-
}));
|
|
293
|
-
|
|
294
|
-
// 3. Inject via use<>() in <model>.service.ts
|
|
295
|
-
export class TaskService extends serve(db.task, ({ use }) => ({
|
|
296
|
-
emailClient: use<EmailClient>(),
|
|
297
|
-
})) {
|
|
298
|
-
async _postCreate(task: cnst.Task) {
|
|
299
|
-
await this.emailClient.send({ to: "...", subject: "Task Created", body: `Task "${task.title}" created.` });
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
**B. Cross-module service injection via `service<>()` (for other Akan services)**
|
|
305
|
-
|
|
306
|
-
```typescript
|
|
307
|
-
// In <model>.service.ts — inject another module's service
|
|
308
|
-
import * as srv from "../srv";
|
|
309
|
-
|
|
310
|
-
export class TaskService extends serve(db.task, ({ service }) => ({
|
|
311
|
-
notiService: service<srv.NotiService>(),
|
|
312
|
-
})) {
|
|
313
|
-
async _postCreate(task: cnst.Task) {
|
|
314
|
-
await this.notiService.send("info", `Task "${task.title}" created`);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
**C. Predefined framework adapter injection via `plug()` (storage, cache, queue, schedule, …)**
|
|
320
|
-
|
|
321
|
-
Akan ships predefined adapter roles from `akanjs/service`: `StorageAdaptorRole`, `CacheAdaptorRole`,
|
|
322
|
-
`QueueAdaptorRole`, `ScheduleAdaptorRole`, `DatabaseAdaptorRole`, `WebsocketAdaptorRole`,
|
|
323
|
-
`LoggingAdaptorRole`, `CompressAdaptorRole`. `plug()` injects the concrete adapter bound to that role (the
|
|
324
|
-
default `StorageAdaptor` binding is `BlobStorage`). `plug()` also accepts a concrete adapter class directly.
|
|
325
|
-
|
|
326
|
-
```typescript
|
|
327
|
-
// In <model>.service.ts — inject the framework storage adapter by role
|
|
328
|
-
import { plug, serve, StorageAdaptorRole } from "akanjs/service";
|
|
329
|
-
|
|
330
|
-
export class TaskService extends serve(db.task, ({ plug }) => ({
|
|
331
|
-
storage: plug(StorageAdaptorRole),
|
|
332
|
-
})) {
|
|
333
|
-
async attach(taskId: string, path: string, localPath: string) {
|
|
334
|
-
// BlobStorage returns a URL under blobStorage.urlPrefix (default "/api/localFile/getBlob").
|
|
335
|
-
return await this.storage.uploadDataFromLocal({ path, localPath });
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
For a custom adapter class (not a predefined role), pass the class itself, e.g. `ipfsApi: plug(IpfsApi)`.
|
|
341
|
-
Injecting a file/image field is usually simpler than calling
|
|
342
|
-
storage directly: declare `image: field(File).optional()` (or `images: field([File])`) on the model and let the
|
|
343
|
-
store's generated `upload<Field>On<Model>(fileList)` action handle the upload. Add `{ cascade: "removeRef" }` to that
|
|
344
|
-
field when the file belongs to the model alone, and removing the model removes the file and its stored object.
|
|
345
|
-
|
|
346
|
-
---
|
|
347
|
-
|
|
348
|
-
### Recipe 3: Creating and Using a Slice
|
|
349
|
-
|
|
350
|
-
A Slice is a named, filtered data view. Add file entries and connect from a page.
|
|
351
|
-
|
|
352
|
-
> **Silent failure — a slice `exec` must return a query descriptor, never an executed list.**
|
|
353
|
-
> Return `this.taskService.queryByStatuses(...)` (the `query<Filter>` builder), **not**
|
|
354
|
-
> `this.taskService.listByStatuses(...)` / `listBy...(...)` (which returns a `Promise<Doc[]>`).
|
|
355
|
-
> Returning an array type-checks but throws at runtime during insight aggregation with the opaque
|
|
356
|
-
> `Error: Unknown document field path: 0`. If you see that error, your slice is returning a list, not a query.
|
|
357
|
-
|
|
358
|
-
```typescript
|
|
359
|
-
// 1. apps/<app>/lib/<model>/<model>.signal.ts — Define the slice
|
|
360
|
-
export class TaskSlice extends slice(srv.task, { guards: { root: Admin, get: SignedIn, cru: SignedIn } }, (init) => ({
|
|
361
|
-
inTodo: init({ guards: [SignedIn] })
|
|
362
|
-
.search("statuses", [cnst.TaskStatus])
|
|
363
|
-
.exec(function (statuses?) {
|
|
364
|
-
// ✅ query<Filter> — a query descriptor. ❌ listByStatuses(...) returns an array and fails at runtime.
|
|
365
|
-
return this.taskService.queryByStatuses(statuses ?? ["todo", "inProgress"]);
|
|
366
|
-
}),
|
|
367
|
-
})) {}
|
|
368
|
-
|
|
369
|
-
// 2. apps/<app>/lib/<model>/<model>.document.ts — Add query filter for slice
|
|
370
|
-
export class TaskFilter extends from(cnst.Task, (filter) => ({
|
|
371
|
-
query: {
|
|
372
|
-
byStatuses: filter()
|
|
373
|
-
.arg("statuses", [cnst.TaskStatus])
|
|
374
|
-
.query((statuses) => ({ status: { $in: statuses } })),
|
|
375
|
-
},
|
|
376
|
-
})) {}
|
|
377
|
-
|
|
378
|
-
// 3. apps/<app>/lib/<model>/<model>.dictionary.ts — Slice labels
|
|
379
|
-
.slice<TaskSlice>((fn) => ({
|
|
380
|
-
inTodo: fn(["Tasks In Todo", "할 일"]).arg((t) => ({
|
|
381
|
-
statuses: t(["Statuses", "상태"]),
|
|
382
|
-
})),
|
|
383
|
-
}))
|
|
384
|
-
|
|
385
|
-
// 4. In page — Init the slice in an async Page and hand the init to a Zone.
|
|
386
|
-
export default async function Page() {
|
|
387
|
-
const [{ taskInitInTodo }] = await Promise.all([fetch.initTaskInTodo()]);
|
|
388
|
-
return <Task.Zone.Card init={taskInitInTodo} sliceName="taskInTodo" />;
|
|
389
|
-
}
|
|
390
|
-
```
|
|
391
|
-
|
|
392
|
-
The slice name in code uses camelCase (`inTodo`). In dictionary and components it becomes `"taskInTodo"`.
|
|
393
|
-
|
|
394
|
-
---
|
|
395
|
-
|
|
396
|
-
### Recipe 4: Creating a Mutation Endpoint (with Status Workflow)
|
|
397
|
-
|
|
398
|
-
**Files to edit (in order):** `document.ts` → `service.ts` → `signal.ts` → `dictionary.ts` → `store.ts` → `Util.tsx`
|
|
399
|
-
|
|
400
|
-
```typescript
|
|
401
|
-
// 1. <model>.document.ts — Document chain method with state validation
|
|
402
|
-
export class TaskDocument extends by(cnst.Task) {
|
|
403
|
-
start() {
|
|
404
|
-
if (this.status !== "todo") throw new Err("task.error.cannotStartFromNonTodo");
|
|
405
|
-
this.status = "inProgress";
|
|
406
|
-
return this; // Return this for chaining: task.start().save()
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
// 2. <model>.service.ts — Service method wrapping document
|
|
411
|
-
async startTask(taskId: string) {
|
|
412
|
-
const task = await this.getTask(taskId);
|
|
413
|
-
return task.start().save();
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// 3. <model>.signal.ts — Mutation endpoint
|
|
417
|
-
export class TaskEndpoint extends endpoint(srv.task, ({ mutation }) => ({
|
|
418
|
-
startTask: mutation(cnst.Task, { guards: [SignedIn] })
|
|
419
|
-
.param("taskId", ID)
|
|
420
|
-
.exec(async function (taskId) {
|
|
421
|
-
return await this.taskService.startTask(taskId);
|
|
422
|
-
}),
|
|
423
|
-
})) {}
|
|
424
|
-
|
|
425
|
-
// 4. <model>.dictionary.ts — Endpoint + error labels
|
|
426
|
-
.endpoint<TaskEndpoint>((fn) => ({
|
|
427
|
-
startTask: fn(["Start Task", "작업시작"])
|
|
428
|
-
.arg((t) => ({ taskId: t(["Task ID", "할 일 ID"]) })),
|
|
429
|
-
}))
|
|
430
|
-
.error({
|
|
431
|
-
cannotStartFromNonTodo: ["Task can only start from todo status", "할 일 상태에서만 시작 가능"],
|
|
432
|
-
})
|
|
433
|
-
|
|
434
|
-
// 5. <model>.store.ts — Client-side action with toast feedback
|
|
435
|
-
async startTask(taskId: string) {
|
|
436
|
-
msg.loading("task.startTaskLoading", { key: "startTask" });
|
|
437
|
-
const task = await fetch.startTask(taskId);
|
|
438
|
-
this.setTask(task); // Auto-generated: updates task state in store
|
|
439
|
-
msg.success("task.startTaskSuccess", { key: "startTask" });
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
// 6. <Model>.Util.tsx — Reusable button component
|
|
443
|
-
export const Start = ({ taskId }: { taskId: string }) => (
|
|
444
|
-
<button className={buttonRecipe({ variant: "primary", size: "xs" })} onClick={() => st.do.startTask(taskId)}>
|
|
445
|
-
Start
|
|
446
|
-
</button>
|
|
447
|
-
);
|
|
448
|
-
```
|
|
449
|
-
|
|
450
|
-
---
|
|
451
|
-
|
|
452
|
-
### Recipe 5: Internal Triggers — Interval & Cron
|
|
453
|
-
|
|
454
|
-
Server-side background jobs. Defined in `internal()` signal, implemented in service.
|
|
455
|
-
|
|
456
|
-
```typescript
|
|
457
|
-
// 1. <model>.signal.ts — Define triggers
|
|
458
|
-
export class TaskInternal extends internal(srv.task, ({ interval, cron }) => ({
|
|
459
|
-
cleanupStaleTasks: interval(10000).exec(async function () {
|
|
460
|
-
await this.taskService.cleanupStaleTasks();
|
|
461
|
-
}),
|
|
462
|
-
|
|
463
|
-
dailyDigest: cron("0 0 * * *").exec(async function () {
|
|
464
|
-
await this.taskService.sendDailyDigest();
|
|
465
|
-
}),
|
|
466
|
-
})) {}
|
|
467
|
-
|
|
468
|
-
// 2. <model>.service.ts — Implement the logic
|
|
469
|
-
async cleanupStaleTasks() {
|
|
470
|
-
const weekAgo = dayjs().subtract(7, "day").toDate();
|
|
471
|
-
const stale = await this.taskModel.listDueBefore(weekAgo);
|
|
472
|
-
for (const task of stale) {
|
|
473
|
-
await task.remove();
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
```
|
|
477
|
-
|
|
478
|
-
**Available trigger types:**
|
|
479
|
-
- `interval(ms)` — runs repeatedly at the given interval
|
|
480
|
-
- `cron("min hour dom month dow")` — runs on a schedule
|
|
481
|
-
- `initialize()` — runs once on service startup
|
|
482
|
-
- `process(Return).msg(Type)` — message queue consumer
|
|
483
|
-
|
|
484
|
-
---
|
|
485
|
-
|
|
486
|
-
### Recipe 6: Creating an Insight (Aggregation / Dashboard Stats)
|
|
487
|
-
|
|
488
|
-
Insights display aggregated statistics across model data.
|
|
489
|
-
|
|
490
|
-
```typescript
|
|
491
|
-
// 1. <model>.constant.ts — Insight class with accumulate rules
|
|
492
|
-
export class TaskInsight extends via(Task, (field) => ({
|
|
493
|
-
totalCount: field(Int, { default: 0, accumulate: {} }),
|
|
494
|
-
completedCount: field(Int, { default: 0, accumulate: { status: "completed" } }),
|
|
495
|
-
})) {}
|
|
496
|
-
|
|
497
|
-
// 2. <model>.dictionary.ts — Insight field labels
|
|
498
|
-
.insight<TaskInsight>((t) => ({
|
|
499
|
-
totalCount: t(["Total Tasks", "전체 할 일"]),
|
|
500
|
-
completedCount: t(["Completed", "완료됨"]),
|
|
501
|
-
}))
|
|
502
|
-
|
|
503
|
-
// 3. <Model>.View.tsx — Display component consuming an Insight model
|
|
504
|
-
export const Stats = ({ taskInsight }: { taskInsight: cnst.TaskInsight }) => (
|
|
505
|
-
<div className="grid grid-cols-2 gap-4">
|
|
506
|
-
<div className="rounded-lg border border-border bg-card p-4">
|
|
507
|
-
<div className="text-muted-foreground text-sm">{l("task.totalCount")}</div>
|
|
508
|
-
<div className="font-bold text-2xl text-primary">{taskInsight.totalCount}</div>
|
|
509
|
-
</div>
|
|
510
|
-
<div className="rounded-lg border border-border bg-card p-4">
|
|
511
|
-
<div className="text-muted-foreground text-sm">{l("task.completedCount")}</div>
|
|
512
|
-
<div className="font-bold text-2xl text-success">{taskInsight.completedCount}</div>
|
|
513
|
-
</div>
|
|
514
|
-
</div>
|
|
515
|
-
);
|
|
516
|
-
|
|
517
|
-
// 4. <Model>.Zone.tsx — Mount in page via Load.Insight bound to a slice
|
|
518
|
-
export const Insight = ({ sliceName }: { sliceName: string }) => {
|
|
519
|
-
const insight = st.slice[sliceName].use.taskInsight();
|
|
520
|
-
if (!insight) return null;
|
|
521
|
-
return <Task.View.Stats taskInsight={insight} />;
|
|
522
|
-
};
|
|
523
|
-
```
|
|
524
|
-
|
|
525
|
-
---
|
|
526
|
-
|
|
527
|
-
### Data Flow Summary
|
|
528
|
-
|
|
529
|
-
For each business question, follow this chain:
|
|
530
|
-
|
|
531
|
-
| Question | File Pattern |
|
|
532
|
-
|----------|-------------|
|
|
533
|
-
| What fields does it have? | `constant.ts` — `via()` layers: Input → Object → Light → Model → Insight |
|
|
534
|
-
| How is it stored/searched? | `document.ts` — `from()` filters + `by()` document methods + `into()` model |
|
|
535
|
-
| What business rule should run? | `service.ts` — `serve()` with DI (`use`, `service`, `plug`, `env`, `memory`) |
|
|
536
|
-
| What should a page call? | `signal.ts` — `internal()` (jobs), `endpoint()` (APIs), `slice()` (data views) |
|
|
537
|
-
| What client state is shared? | `store.ts` — `store()` with auto-generated form/insight state + custom actions |
|
|
538
|
-
| What should users see? | `View.tsx` + `Zone.tsx` (detail/container), `Template.tsx` (forms), `Unit.tsx` (cards), `Util.tsx` (buttons) |
|
|
205
|
+
Six worked recipes carry the full code for the most frequent Akan changes, together with the reference of what
|
|
206
|
+
`akan sync` generates at each layer. They are **not** inlined here — fetch them when you are about to do one:
|
|
207
|
+
`get_guideline` with `workspaceRecipes`, or `akan guideline show workspaceRecipes`.
|
|
208
|
+
|
|
209
|
+
| Recipe | Covers |
|
|
210
|
+
|---|---|
|
|
211
|
+
| 1. Adding a field to a model | the five `constant.ts` classes, the dictionary entry, the store form, `akan sync` |
|
|
212
|
+
| 2. Injecting a dependency into a service | `service<srv.XService>()`, `plug(Adapter)`, `env(...)`, `use<T>()` |
|
|
213
|
+
| 3. Creating and using a slice | `slice()` guards, the generated `init<Model><Suffix>`, `Load.Units` hydration |
|
|
214
|
+
| 4. Creating a mutation endpoint | the document chain method, the service call, the signal `guards`, the store action |
|
|
215
|
+
| 5. Internal triggers | `internal()` with interval and cron |
|
|
216
|
+
| 6. Creating an insight | the `XInsight` class, the aggregation, the dashboard tile |
|
|
217
|
+
| Data Flow Summary | how a value travels page → store → signal → service → document → DB |
|
|
218
|
+
| Auto-Generated API Reference | what signal, service, store, and document each generate — never hand-write these |
|
|
219
|
+
|
|
220
|
+
The rules those recipes obey are in this file; the recipes only show the code. When you edit a file, read the
|
|
221
|
+
existing content first and change only the relevant sections — never rewrite a whole file.
|
|
539
222
|
|
|
540
223
|
## Modeling & Query Gotchas
|
|
541
224
|
|
|
@@ -578,61 +261,3 @@ core framework. The core framework gives you the composition points below; wire
|
|
|
578
261
|
- **SSR auth-gated pages: guard at the layout.** Check the session in the `_layout.tsx` loader and redirect when it is
|
|
579
262
|
absent, so nested pages never render for signed-out users.
|
|
580
263
|
|
|
581
|
-
## Auto-Generated API Reference
|
|
582
|
-
|
|
583
|
-
akan sync automatically generates APIs across all layers. Only write custom logic — never hand-write what the framework generates.
|
|
584
|
-
|
|
585
|
-
### Signal — Endpoint Auto-Generation
|
|
586
|
-
|
|
587
|
-
| Auto-Generated | Signature | Description |
|
|
588
|
-
|---------------|-----------|-------------|
|
|
589
|
-
| `view[Model](id)` | `fetch.viewTask(id)` | Fetch single model for detail view |
|
|
590
|
-
| `edit[Model](id)` | `fetch.editTask(id)` | Fetch model for edit view |
|
|
591
|
-
| `merge[Model](id, data)` | `fetch.mergeTask(data)` | Create (no id) or update (with id) model |
|
|
592
|
-
| `[model]List[Suffix](args, skip, limit, sort)` | `fetch.taskListInTodo(args)` | Paginated list from slice filter |
|
|
593
|
-
| `[model]Insight[Suffix](args)` | `fetch.taskInsightInTodo(args)` | Aggregated insight from slice query |
|
|
594
|
-
| `init[Model][Suffix](args)` | `fetch.initTaskInTodo(args)` | Initialize slice with list + insight |
|
|
595
|
-
|
|
596
|
-
**Rule**: Only define `query()`, `mutation()`, `message()`, `pubsub()` endpoints manually when the endpoint needs custom business logic. Standard CRUD is already auto-generated.
|
|
597
|
-
|
|
598
|
-
### Service — CRUD & Query Auto-Generation
|
|
599
|
-
|
|
600
|
-
| Auto-Generated | Description |
|
|
601
|
-
|---------------|-------------|
|
|
602
|
-
| `this.<model>Model` | Auto-injected model adaptor |
|
|
603
|
-
| `get<Model>(id)`, `load<Model>(id)` | Single document lookup |
|
|
604
|
-
| `create<Model>(data)`, `update<Model>(id, data)`, `remove<Model>(id)` | CRUD operations — named after the model, e.g. `createTask`/`updateTask`/`removeTask` (there is no literal `createModel`) |
|
|
605
|
-
| `list<Query>(args)`, `find<Query>(args)`, `pick<Query>(args)` | Filter-based queries |
|
|
606
|
-
| `exists<Query>(args)`, `count<Query>(args)`, `insight<Query>(args)` | Filter-based helpers |
|
|
607
|
-
| `_preCreate`, `_postCreate`, `_preUpdate`, `_postUpdate`, `_preRemove`, `_postRemove` | Lifecycle hooks (override to add logic) |
|
|
608
|
-
|
|
609
|
-
**Rule**: Use `_preCreate`/`_postCreate` lifecycle hooks for side effects (e.g., push workHistory entries). Write custom service methods only for multi-model orchestration.
|
|
610
|
-
|
|
611
|
-
### Store — State & Action Auto-Generation
|
|
612
|
-
|
|
613
|
-
| Auto-Generated | Description |
|
|
614
|
-
|---------------|-------------|
|
|
615
|
-
| `[model]` (cached full model), `[model]Loading`, `[model]Form`, `[model]Modal` | Base model states |
|
|
616
|
-
| `create[Model](data)`, `update[Model](id, data)`, `remove[Model](id)` | CRUD actions |
|
|
617
|
-
| `new[Model](partial)`, `edit[Model](model)`, `view[Model](model)` | Form/view state actions |
|
|
618
|
-
| `[slice]List`, `[slice]InitList`, `[slice]Insight`, `[slice]Selection` | Slice states |
|
|
619
|
-
| `init[Slice](args)`, `refresh[Slice]()`, `setPageOf[Slice](page)` | Slice actions |
|
|
620
|
-
| `set[Field]On[Model](value)` | Auto-setters for each model field |
|
|
621
|
-
|
|
622
|
-
**Rule**: Write custom store actions only for toast messages (`msg.loading`/`msg.success`) or multi-step workflows. State fields and CRUD actions are already auto-generated.
|
|
623
|
-
|
|
624
|
-
### Document — Filter Query Auto-Generation
|
|
625
|
-
|
|
626
|
-
| Auto-Generated (from Filter definition) | Description |
|
|
627
|
-
|----------------------------------------|-------------|
|
|
628
|
-
| `list[Query](args)`, `listIds[Query](args)` | List documents matching filter |
|
|
629
|
-
| `find[Query](args)`, `findId[Query](args)` | Find one (null if not found) |
|
|
630
|
-
| `pick[Query](args)`, `pickId[Query](args)` | Find one (throw if not found) |
|
|
631
|
-
| `exists[Query](args)`, `count[Query](args)` | Existence check and count |
|
|
632
|
-
| `insight[Query](args)`, `query[Query](args)` | Insight and raw query |
|
|
633
|
-
| `remove[Query](args)`, `removeOne[Query](args)` | Query-level soft remove — all matches, or the newest one (`createdAt` desc, not caller-chosen) |
|
|
634
|
-
| `update[Query](args).set(patch)`, `updateOne[Query](args).set(patch)` | Query-level update — the patch lands on a terminal `.set()`, because a filter's trailing args may be optional |
|
|
635
|
-
|
|
636
|
-
**Rule**: Define `Filter` with `.query()` conditions in `document.ts`. akan sync auto-generates all 14 query helper methods per filter. Write `Document` chain methods only for state transitions with validation.
|
|
637
|
-
|
|
638
|
-
**The four query-level writes fire no hooks**, so no `_pre`/`_postRemove` and no cascade run — same as `updateManyByQuery`. Reach for them when the model carries no removal side effect; otherwise remove documents one at a time. A filter keyed after its own model (filter `chat` on model `chat`) is rejected at boot, because `removeChat`/`updateChat` would otherwise shadow the generated single-document CRUD.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": "Workspace Recipes",
|
|
3
|
+
"description": "Worked step-by-step recipes for common Akan changes, plus the auto-generated signal/service/store/document API reference",
|
|
4
|
+
"group": "core",
|
|
5
|
+
"codegenPriority": 5,
|
|
6
|
+
"deprecated": false,
|
|
7
|
+
"scans": [
|
|
8
|
+
{
|
|
9
|
+
"type": "example",
|
|
10
|
+
"description": "Module files a recipe walks through",
|
|
11
|
+
"path": "{apps,libs}/*/lib/*/*.{constant,document,service,signal,store}.ts",
|
|
12
|
+
"sample": 5
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"update": {
|
|
16
|
+
"filePath": "./workspaceRecipes.instruction.md",
|
|
17
|
+
"contents": [
|
|
18
|
+
"add a field",
|
|
19
|
+
"inject a dependency",
|
|
20
|
+
"create a slice",
|
|
21
|
+
"create a mutation",
|
|
22
|
+
"internal triggers",
|
|
23
|
+
"insights",
|
|
24
|
+
"auto-generated API reference"
|
|
25
|
+
],
|
|
26
|
+
"rules": [
|
|
27
|
+
"Use current Akan APIs only",
|
|
28
|
+
"Every recipe names the files to edit and the order to edit them in",
|
|
29
|
+
"Keep the <%= appName %> placeholder so the rendered guide names this workspace's app",
|
|
30
|
+
"Never duplicate a rule that workspaceOnboarding already states — link to it instead"
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
}
|