sonamu 0.10.7 → 0.10.9

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.
Files changed (79) hide show
  1. package/dist/api/decorators.d.ts.map +1 -1
  2. package/dist/api/decorators.js +5 -12
  3. package/dist/bin/cli.js +10 -253
  4. package/dist/database/base-model.d.ts +1 -0
  5. package/dist/database/base-model.d.ts.map +1 -1
  6. package/dist/database/base-model.js +14 -8
  7. package/dist/database/db.d.ts +2 -1
  8. package/dist/database/db.d.ts.map +1 -1
  9. package/dist/database/db.js +13 -3
  10. package/dist/database/puri-wrapper.d.ts.map +1 -1
  11. package/dist/database/puri-wrapper.js +4 -11
  12. package/dist/database/transaction-context.d.ts +8 -3
  13. package/dist/database/transaction-context.d.ts.map +1 -1
  14. package/dist/database/transaction-context.js +12 -7
  15. package/dist/migration/code-generation.js +2 -2
  16. package/dist/naite/naite-reporter.d.ts +8 -3
  17. package/dist/naite/naite-reporter.d.ts.map +1 -1
  18. package/dist/naite/naite-reporter.js +9 -4
  19. package/dist/ui-web/assets/{index-D0MHYbxl.js → index-CJf8uJYf.js} +47 -41
  20. package/dist/ui-web/assets/index-GMMIVGja.css +1 -0
  21. package/dist/ui-web/index.html +2 -2
  22. package/package.json +3 -3
  23. package/src/api/decorators.ts +11 -22
  24. package/src/bin/cli.ts +12 -375
  25. package/src/database/__tests__/transaction-scope.test.ts +227 -0
  26. package/src/database/base-model.ts +31 -6
  27. package/src/database/db.ts +17 -2
  28. package/src/database/puri-wrapper.ts +5 -22
  29. package/src/database/transaction-context.ts +14 -6
  30. package/src/migration/code-generation.ts +1 -1
  31. package/src/naite/naite-reporter.ts +8 -3
  32. package/dist/ui-web/assets/index-Dx_JX4aQ.css +0 -1
  33. package/src/skills/AGENTS.md +0 -108
  34. package/src/skills/sonamu/SKILL.md +0 -75
  35. package/src/skills/sonamu-ai-agents/SKILL.md +0 -205
  36. package/src/skills/sonamu-api/SKILL.md +0 -480
  37. package/src/skills/sonamu-auth/SKILL.md +0 -327
  38. package/src/skills/sonamu-auth/references/plugins.md +0 -310
  39. package/src/skills/sonamu-auth/references/user-id-migration-followups.md +0 -192
  40. package/src/skills/sonamu-auth/references/user-id-migration.md +0 -455
  41. package/src/skills/sonamu-config/SKILL.md +0 -203
  42. package/src/skills/sonamu-config/references/database.md +0 -452
  43. package/src/skills/sonamu-config/references/environments.md +0 -178
  44. package/src/skills/sonamu-config/references/server-options.md +0 -400
  45. package/src/skills/sonamu-entity/SKILL.md +0 -180
  46. package/src/skills/sonamu-entity/references/creation-workflow.md +0 -581
  47. package/src/skills/sonamu-entity/references/design-guides.md +0 -243
  48. package/src/skills/sonamu-entity/references/field-types.md +0 -170
  49. package/src/skills/sonamu-entity/references/relations-detail.md +0 -245
  50. package/src/skills/sonamu-entity/references/relations.md +0 -463
  51. package/src/skills/sonamu-entity/references/subset.md +0 -156
  52. package/src/skills/sonamu-fixture/SKILL.md +0 -180
  53. package/src/skills/sonamu-fixture/references/cli-usage.md +0 -439
  54. package/src/skills/sonamu-fixture/references/cone.md +0 -298
  55. package/src/skills/sonamu-frontend/SKILL.md +0 -142
  56. package/src/skills/sonamu-frontend/references/components.md +0 -323
  57. package/src/skills/sonamu-frontend/references/examples.md +0 -64
  58. package/src/skills/sonamu-frontend/references/hooks.md +0 -273
  59. package/src/skills/sonamu-frontend/references/runtime.md +0 -165
  60. package/src/skills/sonamu-frontend/references/scaffolding.md +0 -439
  61. package/src/skills/sonamu-i18n/SKILL.md +0 -287
  62. package/src/skills/sonamu-migration/SKILL.md +0 -316
  63. package/src/skills/sonamu-naite/SKILL.md +0 -266
  64. package/src/skills/sonamu-query/SKILL.md +0 -48
  65. package/src/skills/sonamu-query/references/model-patterns.md +0 -390
  66. package/src/skills/sonamu-query/references/model.md +0 -366
  67. package/src/skills/sonamu-query/references/puri.md +0 -413
  68. package/src/skills/sonamu-query/references/search.md +0 -238
  69. package/src/skills/sonamu-query/references/upsert.md +0 -324
  70. package/src/skills/sonamu-tasks/SKILL.md +0 -236
  71. package/src/skills/sonamu-testing/SKILL.md +0 -251
  72. package/src/skills/sonamu-testing/references/devrunner.md +0 -405
  73. package/src/skills/sonamu-testing/references/helpers.md +0 -185
  74. package/src/skills/sonamu-testing/references/patterns.md +0 -263
  75. package/src/skills/sonamu-testing/references/pitfalls.md +0 -588
  76. package/src/skills/sonamu-testing/references/quick-start.md +0 -285
  77. package/src/skills/sonamu-testing/references/type-safety.md +0 -172
  78. package/src/skills/sonamu-testing/references/writing-plan.md +0 -375
  79. package/src/skills/sonamu-vector/SKILL.md +0 -222
@@ -1,298 +0,0 @@
1
- # Cone Metadata
2
-
3
- ## Role of Cone
4
-
5
- | Purpose | Description |
6
- | ---------------------- | --------------------------------------------------------------------- |
7
- | **Fixture generation** | LLM generates contextually appropriate test data based on `cone.note` |
8
- | **Scaffolding** | Uses cone information to generate model and view templates |
9
- | **Documentation** | Metadata describing Entity structure and the meaning of each field |
10
-
11
- ---
12
-
13
- ## Cone Field Types
14
-
15
- ### Entity cone
16
-
17
- | Field | Type | Description |
18
- | ------ | -------- | -------------------------------------------------------------- |
19
- | `note` | string | Entity purpose, business context, and fixture generation guide |
20
- | `tags` | string[] | Classification tags |
21
-
22
- ### Prop cone
23
-
24
- | Field | Type | Description |
25
- | ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------- |
26
- | `note` | string | **Highest priority.** Business meaning of the field, concrete examples, value ranges, format constraints. Input the LLM reads to generate data |
27
- | `fixtureGenerator` | string | **Fallback.** faker.js expression. Fallback when no API key is available |
28
- | `fixtureDefault` | any | Fixed default value |
29
- | `fixtureStrategy` | string | `"sequence"` — used when a DB sequence auto-assigns the id. Never use on string PK. |
30
- | `dataSource` | object | Strategy for fetching reference data for relation props |
31
-
32
- ### Subset cone
33
-
34
- | Field | Type | Description |
35
- | ------ | ------ | ---------------------------------------------------- |
36
- | `note` | string | Subset purpose, included fields, and when it is used |
37
-
38
- ### Enum cone
39
-
40
- | Field | Type | Description |
41
- | -------- | ------ | -------------------------------------- |
42
- | `note` | string | Meaning and usage context of the enum |
43
- | `values` | object | `{ note: string }` for each enum value |
44
-
45
- ---
46
-
47
- ## Priority During Fixture Generation
48
-
49
- When the `--use-llm` flag is used:
50
-
51
- ```
52
- 1. override value (passed at generate() call time)
53
- 2. cone.note + LLM ← highest priority when API key is present
54
- 3. fixtureGenerator (faker.js expression) ← fallback when LLM fails
55
- 4. fixtureDefault (fixed default value)
56
- 5. type-based default (auto-generated)
57
- ```
58
-
59
- **CRITICAL: If `cone.note` is empty, the LLM generates data without context, resulting in poor quality. Always verify that cone.note exists before running fixture generation.**
60
-
61
- ---
62
-
63
- ## CLI Commands
64
-
65
- ### 1. cone gen — Generate cone with LLM (recommended)
66
-
67
- Passes the domain rules (`contract/**/*.contract.md`) and Entity structure to the LLM to generate contextually appropriate cone.
68
-
69
- **Requires ANTHROPIC_API_KEY** (`.env` or `sonamu.config.ts`'s `secret.anthropic_api_key`)
70
-
71
- ```bash
72
- # Single Entity
73
- pnpm sonamu cone gen Post
74
-
75
- # All Entities
76
- pnpm sonamu cone gen --all
77
-
78
- # Regenerate all existing cones (overwrite)
79
- pnpm sonamu cone gen Post --regenerate
80
-
81
- # Regenerate all Entities
82
- pnpm sonamu cone gen --all --regenerate
83
-
84
- # Specify locale
85
- pnpm sonamu cone gen Post --locale en
86
- ```
87
-
88
- #### Options
89
-
90
- | Option | Description |
91
- | ----------------------- | ------------------------------------------------------------------------------------ |
92
- | `--all` | Generate cone for all Entities |
93
- | `--regenerate` | Overwrite existing cone (default: only generate for fields with no note) |
94
- | `--locale <ko\|en\|ja>` | Generation language (default: `i18n.defaultLocale` from `sonamu.config.ts`, or `ko`) |
95
-
96
- #### How it works
97
-
98
- - **Default mode**: `onlyEmpty` — only generates for props where cone.note is empty; existing notes are preserved
99
- - **`--regenerate` mode**: full regeneration, overwrites existing cone
100
-
101
- #### Information referenced by the LLM
102
-
103
- 1. Entity JSON structure (props, subsets, enums, relations)
104
- 2. Domain rule files (`contract/**/*.contract.md`)
105
- 3. Existing cone metadata (in preserve mode)
106
-
107
- ### 2. stub entity — Auto-generate cone when creating an Entity
108
-
109
- ```bash
110
- # Default: auto-generate template cone (no API key required)
111
- pnpm sonamu stub entity Post
112
-
113
- # Generate cone with LLM
114
- pnpm sonamu stub entity Post --ai
115
-
116
- # Skip cone generation
117
- pnpm sonamu stub entity Post --no-cones
118
- ```
119
-
120
- #### Template cone vs LLM cone
121
-
122
- | Item | Template cone | LLM cone |
123
- | ------- | -------------------------------- | ------------------------ |
124
- | API key | Not required | Required |
125
- | Quality | Defaults based on faker-mappings | Reflects project context |
126
- | Speed | Immediate | Takes a few seconds |
127
- | Upgrade | Can be upgraded with `cone gen` | — |
128
-
129
- ---
130
-
131
- ## Key Cone Patterns
132
-
133
- ### General field
134
-
135
- ```json
136
- {
137
- "name": "title",
138
- "type": "string",
139
- "cone": {
140
- "note": "Post title. A Korean title roughly 20–50 characters long",
141
- "fixtureGenerator": "faker.lorem.sentence()"
142
- }
143
- }
144
- ```
145
-
146
- ### Relation field (BelongsToOne)
147
-
148
- ```json
149
- {
150
- "name": "author",
151
- "type": "relation",
152
- "with": "User",
153
- "relationType": "BelongsToOne",
154
- "cone": {
155
- "note": "Post author. References existing User data",
156
- "dataSource": {
157
- "strategy": "recent",
158
- "config": { "limit": 5 }
159
- }
160
- }
161
- }
162
- ```
163
-
164
- ### Correlated fields (name + name_en, etc.)
165
-
166
- Do not set `fixtureGenerator` on correlated fields. The LLM generates them together per row to ensure consistency.
167
-
168
- ```json
169
- {
170
- "name": "name",
171
- "cone": { "note": "Korean name (e.g. 김민수)" }
172
- },
173
- {
174
- "name": "name_en",
175
- "cone": { "note": "Romanized form of name (e.g. Kim Minsu). Must refer to the same person as name" }
176
- }
177
- ```
178
-
179
- ### String PK
180
-
181
- Never set `fixtureStrategy: "sequence"` or `fixtureGenerator` on an id prop with `type: "string"`.
182
- fixture-generator automatically generates `alphanumeric(32)`.
183
-
184
- ```json
185
- {
186
- "name": "id",
187
- "type": "string",
188
- "cone": {
189
- "note": "Random alphanumeric string ID (32 chars, [a-zA-Z0-9]). Generated by better-auth via generateId()"
190
- }
191
- }
192
- ```
193
-
194
- ### Enum field
195
-
196
- ```json
197
- {
198
- "name": "status",
199
- "type": "enum",
200
- "cone": {
201
- "note": "Post status. One of draft/published/archived"
202
- }
203
- }
204
- ```
205
-
206
- ---
207
-
208
- ## dataSource Strategies
209
-
210
- Specifies how reference data is fetched for relation props.
211
-
212
- | Strategy | Description |
213
- | -------- | -------------------------------- |
214
- | `recent` | Most recent data (by created_at) |
215
- | `sample` | Uniform sampling |
216
- | `random` | Random sampling |
217
- | `ids` | Specific IDs |
218
- | `query` | Custom query |
219
- | `file` | Load from file |
220
-
221
- ```json
222
- "dataSource": {
223
- "strategy": "recent",
224
- "config": { "limit": 5 }
225
- }
226
- ```
227
-
228
- ### DataExplorer Options Detail
229
-
230
- **Source:** `modules/sonamu/src/testing/data-explorer.ts`
231
-
232
- | Option | Type | Default | Description |
233
- | ---------- | ------------------ | ------- | ------------------------------------------------------ |
234
- | `strategy` | string | — | Fetch strategy (see table above) |
235
- | `limit` | number | — | Maximum number of records to fetch |
236
- | `where` | object \| function | — | WHERE condition (object or Knex QueryBuilder function) |
237
- | `orderBy` | string | — | Sort criteria |
238
- | `ids` | number[] | — | Specific ID list for `ids` strategy |
239
- | `filePath` | string | — | File path for `file` strategy |
240
- | `useCache` | boolean | `false` | Whether to use caching |
241
- | `cacheTtl` | number | `300` | Cache TTL (in seconds) |
242
-
243
- **Example using a where condition:**
244
-
245
- ```json
246
- "dataSource": {
247
- "strategy": "sample",
248
- "config": {
249
- "limit": 5,
250
- "where": { "status": "active" }
251
- }
252
- }
253
- ```
254
-
255
- ### Relation Traversal Options (ExploreWithRelationsOptions)
256
-
257
- Used in `fixture gen` to fetch related data alongside the target data.
258
-
259
- | Option | Type | Default | Description |
260
- | ------------------ | ------- | ------- | ------------------------------------- |
261
- | `includeRelations` | boolean | `true` | Whether to include related data |
262
- | `maxDepth` | number | `2` | Maximum depth for recursive traversal |
263
-
264
- ---
265
-
266
- ## Practical Tips
267
-
268
- ### Writing effective cone.note
269
-
270
- **note is the primary input for fixture data generation.** The LLM reads note to produce contextually appropriate data, so it must contain specific, domain-specialized content.
271
-
272
- - **Be specific**: "Korean phone number in 010-XXXX-XXXX format" rather than "string"
273
- - **Include business context**: "Employee salary. Range: 30,000,000–150,000,000 KRW"
274
- - **Include concrete examples**: "e.g. AI-based drug discovery platform development, eco-friendly energy storage system development"
275
- - **State value ranges explicitly**: "Between 50,000,000 (50,000) and 5,000,000,000 (5,000,000)"
276
- - **Describe correlated fields**: "name_en must be the romanized form of name"
277
- - **Specify length/format constraints**: "Korean self-introduction, 20–100 characters"
278
-
279
- ### Improving LLM cone generation quality
280
-
281
- 1. Record domain rules and decision rationale in detail in `contract/{domain}/{domain}.contract.md`
282
- 2. Run `cone gen` — the LLM uses `contract/**/*.contract.md` as context
283
-
284
- ### When to regenerate cone
285
-
286
- - After adding a new prop to an Entity
287
- - After a business requirement change
288
- - When fixture data quality is poor
289
- - Running without `--regenerate` preserves existing notes and only fills in empty ones
290
-
291
- ---
292
-
293
- ## References
294
-
295
- - **Fixture CLI**: this skill — fixture gen/fetch/explore commands
296
- - **Testing**: `sonamu-testing` — writing tests and using fixtures
297
- - **Source code**: `modules/sonamu/src/cone/cone-generator.ts`
298
- - **Template cone**: `modules/sonamu/src/entity/entity-template-cone.ts`
@@ -1,142 +0,0 @@
1
- ---
2
- name: sonamu-frontend
3
- description: Builds the Sonamu web frontend against generated services. Use when calling a generated Service, wiring a TanStack Query hook, building a form or list view, or when a scaffolded view fails to compile. Covers useTypeForm, useListParams, useSelection, IdAsyncSelect, FileInput, EnumSelect, SonamuProvider, and sonamu scaffold.
4
- ---
5
-
6
- # Frontend Service
7
-
8
- ## Quick Reference
9
-
10
- ### Hooks
11
-
12
- | Hook | Purpose | Key Return Values |
13
- | --------------- | --------------------------------- | ------------------------------------------------ |
14
- | `useTypeForm` | Form state management (Zod-based) | form, setForm, register, submit, addError, reset |
15
- | `useListParams` | URL-synced list parameters | listParams, setListParams, register |
16
- | `useSelection` | Checkbox multi-selection | selectedKeys, toggle, selectAll, deselectAll |
17
- | `useModal` | Modal state management | open, modal |
18
- | `useToast` | Toast notifications | toast |
19
-
20
- ### Components
21
-
22
- | Component | Purpose | Key Props |
23
- | ------------- | ---------------- | --------------------------------------------------- |
24
- | `Input` | Text input | value, onValueChange |
25
- | `Textarea` | Multi-line input | value, onValueChange |
26
- | `Checkbox` | Checkbox | value (boolean), onValueChange, label |
27
- | `Select` | Single select | items, value, onValueChange, placeholder, clearable |
28
- | `MultiSelect` | Multi-select | options, value (array), onValueChange, maxCount |
29
- | `EnumSelect` | Enum select | enum, labels, value, onValueChange |
30
- | `FileInput` | File upload | uploadMode, viewMode, multiple, maxFiles |
31
-
32
- ### Service (Auto-generated)
33
-
34
- | Method | Purpose | Example |
35
- | ----------------- | -------------------- | ----------------------------------- |
36
- | `get{Entity}` | Fetch single record | `UserService.getUser("A", 123)` |
37
- | `get{Entities}` | Fetch list | `UserService.getUsers("P", params)` |
38
- | `save` | Save (create/update) | `UserService.save([data])` |
39
- | `del` | Delete | `UserService.del([1, 2, 3])` |
40
- | `use{Entity}` | Single fetch hook | `UserService.useUser("A", id)` |
41
- | `use{Entities}` | List fetch hook | `UserService.useUsers("P", params)` |
42
- | `useSaveMutation` | Save mutation | `UserService.useSaveMutation()` |
43
-
44
- ### Utilities
45
-
46
- | Function | Purpose | Example |
47
- | ------------------ | ------------------------ | ------------------------------------------------- |
48
- | `dateF` | Date formatting | `dateF(new Date())` → `"2024-01-15"` |
49
- | `datetimeF` | Datetime formatting | `datetimeF(new Date())` → `"2024-01-15 10:30:00"` |
50
- | `numF` | Number formatting | `numF(1234567)` → `"1,234,567"` |
51
- | `hidden` | Conditional hidden class | `hidden(true)` → `"hidden"` |
52
- | `arrayableToArray` | Convert to array | `arrayableToArray("a")` → `["a"]` |
53
-
54
- ### Configuration
55
-
56
- | Item | Description | Required |
57
- | ---------------- | -------------------------------------------------- | ------------------------------------------ |
58
- | `SonamuProvider` | Global configuration Provider (uploader, auth, SD) | Required (uploader required for FileInput) |
59
- | `uploader` | File upload function | Required when using FileInput |
60
- | `auth` | Authentication state and functions | Optional |
61
- | `SD` | Internationalization function | Optional |
62
-
63
- ---
64
-
65
- # Frontend Service
66
-
67
- ## Basic Usage
68
-
69
- ```typescript
70
- import { UserService } from "@/services/services.generated";
71
-
72
- // Single fetch (Subset required) - get{Entity} form
73
- const user = await UserService.getUser("A", 123);
74
-
75
- // List fetch - get{Entities} form
76
- const { rows, total } = await UserService.getUsers("P", { num: 20, page: 1 });
77
-
78
- // Save
79
- const [userId] = await UserService.save([{ email: "new@test.com", username: "newuser" }]);
80
-
81
- // Delete
82
- const count = await UserService.del([1, 2, 3]);
83
- ```
84
-
85
- ## TanStack Query Hook
86
-
87
- ### useQuery
88
-
89
- ```typescript
90
- function UserProfile({ userId }: { userId: number }) {
91
- // use{Entity} form (single), use{Entities} form (list)
92
- const { data: user, isLoading, error } = UserService.useUser("A", userId);
93
-
94
- if (isLoading) return <div>Loading...</div>;
95
- if (error) return <div>Error: {error.message}</div>;
96
-
97
- return <h1>{user?.username}</h1>;
98
- }
99
- ```
100
-
101
- ### useMutation
102
-
103
- ```typescript
104
- function EditProfile() {
105
- const saveMutation = UserService.useSaveMutation();
106
-
107
- async function handleSubmit(data: UserSaveParams) {
108
- saveMutation.mutate({ spa: [data] }, {
109
- onSuccess: ([userId]) => console.log("Saved:", userId),
110
- onError: (error) => console.error("Failed:", error),
111
- });
112
- }
113
-
114
- return <button disabled={saveMutation.isPending}>Save</button>;
115
- }
116
- ```
117
-
118
- ### Conditional Fetching
119
-
120
- ```typescript
121
- const { data } = UserService.useUser("A", userId!, {
122
- enabled: userId !== null,
123
- });
124
- ```
125
-
126
- ### Cache Invalidation
127
-
128
- ```typescript
129
- const queryClient = useQueryClient();
130
- queryClient.invalidateQueries({ queryKey: ["User", "findById", "A", userId] });
131
- ```
132
-
133
-
134
- ## Reference Map
135
-
136
- | Need | Read |
137
- | --- | --- |
138
- | useTypeForm, useListParams, useSelection | `references/hooks.md` |
139
- | IdAsyncSelect, FileInput, Select, EnumSelect | `references/components.md` |
140
- | SonamuProvider, utilities, error handling, SSR, initial setup, rules | `references/runtime.md` |
141
- | Full worked component implementations | `references/examples.md` |
142
- | Scaffold commands, pre/post checklists, scaffolding errors | `references/scaffolding.md` |