sonamu 0.8.24 → 0.8.26

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 (88) hide show
  1. package/dist/api/__tests__/config.test.js +189 -0
  2. package/dist/api/config.d.ts.map +1 -1
  3. package/dist/api/config.js +7 -2
  4. package/dist/api/sonamu.d.ts.map +1 -1
  5. package/dist/api/sonamu.js +14 -10
  6. package/dist/auth/index.d.ts +1 -0
  7. package/dist/auth/index.d.ts.map +1 -1
  8. package/dist/auth/index.js +2 -1
  9. package/dist/auth/knex-adapter.d.ts +23 -0
  10. package/dist/auth/knex-adapter.d.ts.map +1 -0
  11. package/dist/auth/knex-adapter.js +163 -0
  12. package/dist/auth/plugins/wrappers/admin.d.ts +2 -2
  13. package/dist/bin/__tests__/ts-loader-register.test.js +45 -0
  14. package/dist/bin/cli.js +47 -9
  15. package/dist/bin/ts-loader-register.js +3 -29
  16. package/dist/bin/ts-loader-registration.d.ts +2 -0
  17. package/dist/bin/ts-loader-registration.d.ts.map +1 -0
  18. package/dist/bin/ts-loader-registration.js +42 -0
  19. package/dist/cone/cone-generator.js +3 -3
  20. package/dist/database/puri-subset.test-d.js +9 -1
  21. package/dist/database/puri-subset.types.d.ts +1 -1
  22. package/dist/database/puri-subset.types.d.ts.map +1 -1
  23. package/dist/database/puri-subset.types.js +1 -1
  24. package/dist/testing/fixture-generator.js +5 -5
  25. package/dist/ui/ai-client.js +2 -2
  26. package/dist/ui/api.d.ts.map +1 -1
  27. package/dist/ui/api.js +14 -14
  28. package/dist/ui/cdd-service.d.ts +15 -18
  29. package/dist/ui/cdd-service.d.ts.map +1 -1
  30. package/dist/ui/cdd-service.js +246 -222
  31. package/dist/ui/cdd-types.d.ts +41 -68
  32. package/dist/ui/cdd-types.d.ts.map +1 -1
  33. package/dist/ui/cdd-types.js +2 -2
  34. package/dist/ui-web/assets/index-CKo0Z2Iu.css +1 -0
  35. package/dist/ui-web/assets/{index-CxiydzeC.js → index-DK-2aacv.js} +83 -83
  36. package/dist/ui-web/index.html +2 -2
  37. package/package.json +6 -2
  38. package/src/api/__tests__/config.test.ts +225 -0
  39. package/src/api/config.ts +10 -4
  40. package/src/api/sonamu.ts +16 -13
  41. package/src/auth/index.ts +1 -0
  42. package/src/auth/knex-adapter.ts +208 -0
  43. package/src/bin/__tests__/ts-loader-register.test.ts +62 -0
  44. package/src/bin/cli.ts +52 -9
  45. package/src/bin/ts-loader-register.ts +2 -32
  46. package/src/bin/ts-loader-registration.ts +55 -0
  47. package/src/cone/cone-generator.ts +2 -2
  48. package/src/database/puri-subset.test-d.ts +102 -0
  49. package/src/database/puri-subset.types.ts +1 -1
  50. package/src/skills/commands/sonamu-skills.md +20 -0
  51. package/src/skills/sonamu/SKILL.md +179 -137
  52. package/src/skills/sonamu/ai-agents.md +69 -69
  53. package/src/skills/sonamu/api.md +147 -147
  54. package/src/skills/sonamu/auth-migration.md +220 -220
  55. package/src/skills/sonamu/auth-plugins.md +83 -83
  56. package/src/skills/sonamu/auth.md +106 -106
  57. package/src/skills/sonamu/cdd.md +65 -200
  58. package/src/skills/sonamu/cone.md +138 -138
  59. package/src/skills/sonamu/config.md +191 -191
  60. package/src/skills/sonamu/create-sonamu.md +66 -66
  61. package/src/skills/sonamu/database.md +158 -158
  62. package/src/skills/sonamu/entity-basic.md +292 -293
  63. package/src/skills/sonamu/entity-relations.md +246 -246
  64. package/src/skills/sonamu/entity-validation-checklist.md +124 -124
  65. package/src/skills/sonamu/fixture-cli.md +231 -231
  66. package/src/skills/sonamu/framework-change.md +37 -37
  67. package/src/skills/sonamu/frontend.md +223 -223
  68. package/src/skills/sonamu/i18n.md +82 -82
  69. package/src/skills/sonamu/migration.md +77 -77
  70. package/src/skills/sonamu/model.md +222 -222
  71. package/src/skills/sonamu/naite.md +86 -86
  72. package/src/skills/sonamu/project-init.md +228 -228
  73. package/src/skills/sonamu/puri.md +122 -122
  74. package/src/skills/sonamu/scaffolding.md +154 -154
  75. package/src/skills/sonamu/skill-contribution.md +124 -124
  76. package/src/skills/sonamu/subset.md +46 -46
  77. package/src/skills/sonamu/tasks.md +82 -82
  78. package/src/skills/sonamu/testing-devrunner.md +147 -147
  79. package/src/skills/sonamu/testing.md +673 -673
  80. package/src/skills/sonamu/upsert.md +79 -79
  81. package/src/skills/sonamu/vector.md +67 -67
  82. package/src/testing/fixture-generator.ts +4 -4
  83. package/src/ui/ai-client.ts +1 -1
  84. package/src/ui/api.ts +18 -17
  85. package/src/ui/cdd-service.ts +264 -254
  86. package/src/ui/cdd-types.ts +40 -75
  87. package/dist/ui-web/assets/index-BrQKU3j9.css +0 -1
  88. package/src/skills/sonamu/workflow.md +0 -317
@@ -1,33 +1,33 @@
1
1
  ---
2
2
  name: sonamu-tasks
3
- description: Sonamu Tasks 워크플로우 시스템. 백그라운드 작업, 스케줄링, durable step 실행. Use when implementing background workflows, scheduled tasks, or multi-step async processes.
3
+ description: Sonamu Tasks workflow system. Background jobs, scheduling, durable step execution. Use when implementing background workflows, scheduled tasks, or multi-step async processes.
4
4
  ---
5
5
 
6
- # Tasks (워크플로우 시스템)
6
+ # Tasks (Workflow System)
7
7
 
8
- PostgreSQL 기반 durable workflow engine. `@sonamu-kit/tasks` 패키지를 사용한다.
8
+ PostgreSQL-based durable workflow engine. Uses the `@sonamu-kit/tasks` package.
9
9
 
10
- **소스코드:**
11
- - 데코레이터: `modules/sonamu/src/tasks/decorator.ts`
10
+ **Source code:**
11
+ - Decorator: `modules/sonamu/src/tasks/decorator.ts`
12
12
  - StepWrapper: `modules/sonamu/src/tasks/step-wrapper.ts`
13
13
  - WorkflowManager: `modules/sonamu/src/tasks/workflow-manager.ts`
14
14
  - @sonamu-kit/tasks: `modules/tasks/`
15
15
 
16
- ## 워크플로우 정의
16
+ ## Workflow Definition
17
17
 
18
- `workflow()` 함수로 정의한다. export하면 syncer 자동 수집하여 WorkflowManager에 등록한다.
18
+ Define with the `workflow()` function. When exported, the syncer automatically collects and registers it with WorkflowManager.
19
19
 
20
20
  ```typescript
21
21
  import { workflow } from "sonamu";
22
22
 
23
- // 방법 1: 데코레이터 + 함수 분리
23
+ // Method 1: decorator + function separated
24
24
  export const myTask = workflow({
25
25
  version: "1",
26
26
  })(async ({ input, step, logger, version }) => {
27
27
  // ...
28
28
  });
29
29
 
30
- // 방법 2: 데코레이터 + 함수 인라인
30
+ // Method 2: decorator + function inlined
31
31
  export const myTask = workflow({
32
32
  version: "1",
33
33
  }, async ({ input, step, logger, version }) => {
@@ -37,28 +37,28 @@ export const myTask = workflow({
37
37
 
38
38
  ### DefineWorkflowOptions
39
39
 
40
- | 옵션 | 타입 | 필수 | 설명 |
40
+ | Option | Type | Required | Description |
41
41
  |------|------|------|------|
42
- | `version` | `string` | Y | 워크플로우 버전 (변경 기존 실행과 구분) |
43
- | `name` | `string` | N | 워크플로우 이름 (기본: 함수명을 underscore 변환) |
44
- | `schema` | `StandardSchemaV1` | N | input 검증 스키마 (Zod ) |
45
- | `schedules` | `Schedule[]` | N | cron 스케줄 배열 |
46
- | `retryPolicy` | `RetryPolicy` | N | 재시도 정책 |
42
+ | `version` | `string` | Y | Workflow version (distinguishes from existing runs when changed) |
43
+ | `name` | `string` | N | Workflow name (default: function name converted to underscore case) |
44
+ | `schema` | `StandardSchemaV1` | N | Input validation schema (Zod, etc.) |
45
+ | `schedules` | `Schedule[]` | N | Array of cron schedules |
46
+ | `retryPolicy` | `RetryPolicy` | N | Retry policy |
47
47
 
48
- ### 워크플로우 함수 파라미터
48
+ ### Workflow Function Parameters
49
49
 
50
- | 파라미터 | 타입 | 설명 |
50
+ | Parameter | Type | Description |
51
51
  |---------|------|------|
52
- | `input` | `Input` | 워크플로우 실행 전달된 입력값 |
53
- | `step` | `StepWrapper` | Step 정의/실행 도구 |
54
- | `logger` | `Logger` | @logtape/logtape 로거 |
55
- | `version` | `string \| null` | 현재 워크플로우 버전 |
52
+ | `input` | `Input` | Input value passed when the workflow runs |
53
+ | `step` | `StepWrapper` | Tool for defining/executing steps |
54
+ | `logger` | `Logger` | @logtape/logtape logger |
55
+ | `version` | `string \| null` | Current workflow version |
56
56
 
57
57
  ## Step
58
58
 
59
- 워크플로우 내의 원자적 실행 단위. 실패 해당 Step부터 재시도된다.
59
+ An atomic unit of execution within a workflow. On failure, retry begins from that step.
60
60
 
61
- ### step.define — 인라인 함수
61
+ ### step.define — Inline Function
62
62
 
63
63
  ```typescript
64
64
  const result = await step.define({ name: "fetch-data" }, async () => {
@@ -67,73 +67,73 @@ const result = await step.define({ name: "fetch-data" }, async () => {
67
67
  }).run();
68
68
  ```
69
69
 
70
- ### step.get — 기존 메서드 래핑
70
+ ### step.get — Wrapping an Existing Method
71
71
 
72
72
  ```typescript
73
- // Model 메서드를 Step으로 감싸기
73
+ // Wrap a Model method as a Step
74
74
  const result = await step.get(MyModel, "processData").run(inputData);
75
75
 
76
- // 커스텀 이름 지정
76
+ // Specify a custom name
77
77
  const result = await step.get({ name: "custom_step" }, MyService, "execute").run(params);
78
78
  ```
79
79
 
80
- `step.get`의 오버로드:
81
- - `step.get(object, methodName)` — Step 이름은 methodName underscore 변환
82
- - `step.get({ name }, object, methodName)` — Step 이름 직접 지정
80
+ Overloads for `step.get`:
81
+ - `step.get(object, methodName)` — Step name is the methodName converted to underscore case
82
+ - `step.get({ name }, object, methodName)` — Step name specified directly
83
83
 
84
- ### step.sleep — Durable 대기
84
+ ### step.sleep — Durable Wait
85
85
 
86
86
  ```typescript
87
87
  await step.sleep("wait-before-retry", "30m");
88
88
  await step.sleep("daily-delay", "1d");
89
89
  ```
90
90
 
91
- 서버가 재시작되어도 대기 시간이 유지된다.
91
+ The wait time is preserved even if the server restarts.
92
92
 
93
- **DurationString 형식:** `{숫자}{단위}` — 예: `"5s"`, `"30m"`, `"2h"`, `"7d"`, `"1w"`, `"1y"`
93
+ **DurationString format:** `{number}{unit}` — e.g. `"5s"`, `"30m"`, `"2h"`, `"7d"`, `"1w"`, `"1y"`
94
94
 
95
- ## 스케줄링 (cron)
95
+ ## Scheduling (cron)
96
96
 
97
97
  ```typescript
98
98
  export const dailyReport = workflow({
99
99
  version: "1",
100
100
  schedules: [{
101
- expression: "0 9 * * *", // 매일 오전 9시
102
- name: "daily-report", // 선택 (기본: 워크플로우명[expression])
103
- input: () => ({ date: new Date().toISOString() }), // 선택
101
+ expression: "0 9 * * *", // every day at 9am
102
+ name: "daily-report", // optional (default: workflowName[expression])
103
+ input: () => ({ date: new Date().toISOString() }), // optional
104
104
  }],
105
105
  }, async ({ input, step }) => {
106
106
  // ...
107
107
  });
108
108
  ```
109
109
 
110
- | 필드 | 타입 | 필수 | 설명 |
110
+ | Field | Type | Required | Description |
111
111
  |------|------|------|------|
112
- | `expression` | `string` | Y | cron 표현식 |
113
- | `name` | `string` | N | 스케줄 이름 (기본: `워크플로우명[expression]`) |
114
- | `input` | `Executable<Input>` | N | 실행 전달할 입력값 (함수 또는 ) |
112
+ | `expression` | `string` | Y | cron expression |
113
+ | `name` | `string` | N | Schedule name (default: `workflowName[expression]`) |
114
+ | `input` | `Executable<Input>` | N | Input value to pass on execution (function or value) |
115
115
 
116
- 타임존은 `sonamu.config.ts`의 `api.timezone` 설정을 따른다.
116
+ The timezone follows the `api.timezone` setting in `sonamu.config.ts`.
117
117
 
118
- ## 재시도 정책
118
+ ## Retry Policy
119
119
 
120
- ### 정적 정책 (기본)
120
+ ### Static Policy (Default)
121
121
 
122
122
  ```typescript
123
123
  export const reliableTask = workflow({
124
124
  version: "1",
125
125
  retryPolicy: {
126
- maxAttempts: 5, // 최대 재시도 횟수 (기본: 5)
127
- initialIntervalMs: 1000, // 재시도 대기 (기본: 1000ms)
128
- backoffCoefficient: 2, // 대기 시간 배수 (기본: 2)
129
- maximumIntervalMs: 60000, // 최대 대기 시간
126
+ maxAttempts: 5, // maximum retry attempts (default: 5)
127
+ initialIntervalMs: 1000, // first retry wait time (default: 1000ms)
128
+ backoffCoefficient: 2, // wait time multiplier (default: 2)
129
+ maximumIntervalMs: 60000, // maximum wait time
130
130
  },
131
131
  }, async ({ step }) => {
132
132
  // ...
133
133
  });
134
134
  ```
135
135
 
136
- ### 동적 정책
136
+ ### Dynamic Policy
137
137
 
138
138
  ```typescript
139
139
  retryPolicy: {
@@ -145,77 +145,77 @@ retryPolicy: {
145
145
  }
146
146
  ```
147
147
 
148
- ## sonamu.config.ts 설정
148
+ ## sonamu.config.ts Configuration
149
149
 
150
150
  ```typescript
151
151
  export default defineConfig({
152
152
  tasks: {
153
153
  enableWorker: true,
154
154
  workerOptions: {
155
- concurrency: 4, // 동시 실행 (기본: CPU 코어 - 1)
156
- usePubSub: true, // DB pub/sub 사용 (기본: true)
157
- listenDelay: 500, // pub/sub 수신 실행 지연 ms (기본: 500)
155
+ concurrency: 4, // concurrent execution count (default: CPU cores - 1)
156
+ usePubSub: true, // use DB pub/sub (default: true)
157
+ listenDelay: 500, // execution delay after pub/sub receive in ms (default: 500)
158
158
  },
159
159
  contextProvider: (defaultContext) => {
160
- // 워크플로우 내에서 사용할 Context 구성
160
+ // build Context to use within workflows
161
161
  return { ...defaultContext };
162
162
  },
163
163
  },
164
164
  });
165
165
  ```
166
166
 
167
- | 옵션 | 타입 | 설명 |
167
+ | Option | Type | Description |
168
168
  |------|------|------|
169
- | `enableWorker` | `boolean` | Worker 활성화 여부 (daemon 모드에서만 사용) |
170
- | `workerOptions.concurrency` | `number` | 동시 실행 태스크 |
171
- | `workerOptions.usePubSub` | `boolean` | PostgreSQL pub/sub 사용 |
172
- | `workerOptions.listenDelay` | `number` | pub/sub 수신 후 실행 지연 (ms) |
173
- | `contextProvider` | `(ctx) => Context` | 워크플로우 실행 Context 생성 함수 |
169
+ | `enableWorker` | `boolean` | Whether to enable Worker (use only in daemon mode) |
170
+ | `workerOptions.concurrency` | `number` | Number of concurrently executing tasks |
171
+ | `workerOptions.usePubSub` | `boolean` | Use PostgreSQL pub/sub |
172
+ | `workerOptions.listenDelay` | `number` | Execution delay after pub/sub receive (ms) |
173
+ | `contextProvider` | `(ctx) => Context` | Context creation function when workflow runs |
174
174
 
175
- ## 수동 실행
175
+ ## Manual Execution
176
176
 
177
177
  ```typescript
178
178
  import { Sonamu } from "sonamu";
179
179
 
180
- // WorkflowManager를 통해 실행
180
+ // Run via WorkflowManager
181
181
  const handle = await Sonamu.workflowManager.run(
182
182
  { name: "my-task", version: "1" },
183
183
  { target: "manual" }
184
184
  );
185
185
 
186
- // 결과 대기
186
+ // Wait for result
187
187
  const result = await handle.result();
188
188
  ```
189
189
 
190
- ## 파일 배치
190
+ ## File Placement
191
191
 
192
192
  ```
193
193
  packages/api/src/application/
194
194
  ├── {domain}/
195
195
  │ ├── {domain}.model.ts
196
196
  │ ├── {domain}.types.ts
197
- │ └── {domain}.workflow.ts ← 워크플로우 파일
197
+ │ └── {domain}.workflow.ts ← workflow file
198
198
  ```
199
199
 
200
- 워크플로우 파일에서 `workflow()`로 정의하고 export하면 syncer 자동 수집한다.
200
+ Define with `workflow()` and export in the workflow file; the syncer will collect it automatically.
201
201
 
202
- ## 아키텍처
202
+ ## Architecture
203
203
 
204
204
  ```
205
- Dev Server 시작
206
- → WorkflowManager 초기화 (BackendPostgres)
207
- → Worker 시작 (enableWorker: true일 때)
208
- → syncer .workflow.ts 파일 수집
209
- → WorkflowManager.synchronize()로 등록
210
- → cron 스케줄 자동 시작
211
-
212
- HMR
213
- 변경된 파일의 워크플로우 재등록 (synchronize)
214
-
215
- 실행 흐름
216
- → run() 호출DB에 워크플로우 실행 레코드 생성
217
- → Worker pub/sub으로 수신 Step 순차 실행
218
- Step 완료 DB 체크포인트 저장
219
- 실패 retryPolicy에 따라 해당 Step부터 재시도
220
- 서버 재시작 미완료 워크플로우를 DB에서 복구하여 계속 실행
205
+ Dev Server startup
206
+ → WorkflowManager initialization (BackendPostgres)
207
+ → Worker startup (when enableWorker: true)
208
+ → syncer collects .workflow.ts files
209
+ registers via WorkflowManager.synchronize()
210
+ → cron schedules start automatically
211
+
212
+ On HMR
213
+ re-register workflows from changed files (synchronize)
214
+
215
+ Execution flow
216
+ → run() calledworkflow execution record created in DB
217
+ → Worker receives via pub/sub → steps executed sequentially
218
+ checkpoint saved to DB on each step completion
219
+ on failure: retry from that step according to retryPolicy
220
+ on server restart: incomplete workflows recovered from DB and continue
221
221
  ```