guardian-framework 0.1.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/LICENSE +21 -0
- package/README.md +463 -0
- package/dist/cli.js +12958 -0
- package/dist/exports.js +12765 -0
- package/package.json +61 -0
- package/templates/languages/go-patterns.md +411 -0
- package/templates/languages/java-patterns.md +545 -0
- package/templates/languages/python-patterns.md +312 -0
- package/templates/languages/rust-patterns.md +232 -0
- package/templates/languages/typescript-patterns.md +313 -0
- package/templates/pi/INDEX.md +437 -0
- package/templates/pi/agent/AGENTS.md +166 -0
- package/templates/pi/agents/architecture-coordinator.md +40 -0
- package/templates/pi/agents/architecture-validator.md +36 -0
- package/templates/pi/agents/bootstrap-implementer.md +37 -0
- package/templates/pi/agents/issue-factory.md +31 -0
- package/templates/pi/agents/operations-validator.md +32 -0
- package/templates/pi/agents/security-validator.md +33 -0
- package/templates/pi/architecture/CHANGELOG.md +78 -0
- package/templates/pi/architecture/decisions/ADR-template.md +76 -0
- package/templates/pi/architecture/diagrams/system-overview.md +159 -0
- package/templates/pi/architecture/modules/module-template.md +152 -0
- package/templates/pi/context/checklists.md +91 -0
- package/templates/pi/context/domain-workflow.md +180 -0
- package/templates/pi/context/output-formats.md +135 -0
- package/templates/pi/context/patterns-base.md +47 -0
- package/templates/pi/context/patterns.md +38 -0
- package/templates/pi/context/project.md +88 -0
- package/templates/pi/domain/exploration.md +93 -0
- package/templates/pi/domain/ubiquitous-language.md +24 -0
- package/templates/pi/extensions/architect-lib/generators.ts +528 -0
- package/templates/pi/extensions/architect-lib/helpers.ts +344 -0
- package/templates/pi/extensions/architect-lib/types.ts +117 -0
- package/templates/pi/extensions/architect.ts +1425 -0
- package/templates/pi/extensions/ask-user-question.ts +579 -0
- package/templates/pi/extensions/bash-guard.ts +556 -0
- package/templates/pi/extensions/config-reload.ts +115 -0
- package/templates/pi/extensions/coordinator.ts +304 -0
- package/templates/pi/extensions/curator.ts +543 -0
- package/templates/pi/extensions/domain-explorer.ts +990 -0
- package/templates/pi/extensions/filechanges.ts +656 -0
- package/templates/pi/extensions/goal-loop.ts +717 -0
- package/templates/pi/extensions/hooks.ts +452 -0
- package/templates/pi/extensions/kanban.ts +547 -0
- package/templates/pi/extensions/pipeline.ts +1246 -0
- package/templates/pi/extensions/plan-mode.ts +209 -0
- package/templates/pi/extensions/project-scaffolder.ts +284 -0
- package/templates/pi/extensions/read-only-mode.ts +192 -0
- package/templates/pi/extensions/redaction.ts +128 -0
- package/templates/pi/extensions/session-persistence.ts +174 -0
- package/templates/pi/extensions/slash-commands.ts +229 -0
- package/templates/pi/extensions/snippets.ts +201 -0
- package/templates/pi/extensions/validation-runner.ts +100 -0
- package/templates/pi/github/agents/architecture-coordinator.agent.md +27 -0
- package/templates/pi/github/agents/architecture-validator.agent.md +20 -0
- package/templates/pi/github/agents/bootstrap-implementer.agent.md +20 -0
- package/templates/pi/github/agents/epic-planner.agent.md +70 -0
- package/templates/pi/github/agents/issue-factory.agent.md +20 -0
- package/templates/pi/github/agents/operations-validator.agent.md +20 -0
- package/templates/pi/github/agents/security-validator.agent.md +20 -0
- package/templates/pi/github/copilot/settings.json +16 -0
- package/templates/pi/github/copilot-instructions.md +155 -0
- package/templates/pi/github/instructions/architecture.instructions.md +71 -0
- package/templates/pi/github/instructions/validation.instructions.md +69 -0
- package/templates/pi/github/workflows/01-planning-workflow.md +75 -0
- package/templates/pi/github/workflows/02-issue-generation-workflow.md +69 -0
- package/templates/pi/github/workflows/03-implementation-workflow.md +80 -0
- package/templates/pi/github/workflows/04-validation-workflow.md +68 -0
- package/templates/pi/preflight_report.json +99 -0
- package/templates/pi/prompts/blueprint-update.md +262 -0
- package/templates/pi/prompts/blueprint-validate.md +218 -0
- package/templates/pi/prompts/bug-fix.md +50 -0
- package/templates/pi/prompts/ci-blueprint.md +131 -0
- package/templates/pi/prompts/context-refresh.md +258 -0
- package/templates/pi/prompts/epic-plan.md +356 -0
- package/templates/pi/prompts/epic-template.md +186 -0
- package/templates/pi/prompts/feature-development.md +131 -0
- package/templates/pi/prompts/git-issues.md +243 -0
- package/templates/pi/prompts/hotfix.md +71 -0
- package/templates/pi/prompts/issue-closeout.md +342 -0
- package/templates/pi/prompts/issue-draft.md +218 -0
- package/templates/pi/prompts/issue-implementation-series.md +173 -0
- package/templates/pi/prompts/issue-merge.md +372 -0
- package/templates/pi/prompts/issue-template-set.md +392 -0
- package/templates/pi/prompts/issue-template.md +207 -0
- package/templates/pi/prompts/pattern-extract.md +269 -0
- package/templates/pi/prompts/plan-to-issues.md +430 -0
- package/templates/pi/prompts/refactoring.md +82 -0
- package/templates/pi/prompts/scope-analyzer.md +254 -0
- package/templates/pi/prompts/sync-check.md +230 -0
- package/templates/pi/scripts/categorize-issues.sh +171 -0
- package/templates/pi/scripts/ci/check_architecture_conformance.sh +748 -0
- package/templates/pi/scripts/ci/check_planning_packet.py +228 -0
- package/templates/pi/scripts/ci/run_hardening_stages.sh +264 -0
- package/templates/pi/scripts/ci/run_preflight.sh +649 -0
- package/templates/pi/scripts/ci/run_stage.sh +193 -0
- package/templates/pi/scripts/ci/stage_docs_policy.sh +82 -0
- package/templates/pi/scripts/ci/stage_integration.sh +3 -0
- package/templates/pi/scripts/ci/stage_lint.sh +130 -0
- package/templates/pi/scripts/ci/stage_migration_verify.sh +3 -0
- package/templates/pi/scripts/ci/stage_package_build.sh +3 -0
- package/templates/pi/scripts/ci/stage_release_readiness.sh +3 -0
- package/templates/pi/scripts/ci/stage_remaining.sh +242 -0
- package/templates/pi/scripts/ci/stage_security.sh +3 -0
- package/templates/pi/scripts/ci/stage_static_analysis.sh +114 -0
- package/templates/pi/scripts/ci/stage_unit.sh +119 -0
- package/templates/pi/scripts/ci/validate_agent_output.py +181 -0
- package/templates/pi/scripts/ci/validate_agent_output.sh +243 -0
- package/templates/pi/scripts/create-feature-branch.sh +136 -0
- package/templates/pi/scripts/create-mr.sh +117 -0
- package/templates/pi/scripts/fetch-issues.sh +131 -0
- package/templates/pi/scripts/generate-architecture.sh +161 -0
- package/templates/pi/scripts/git/close-epic.sh +69 -0
- package/templates/pi/scripts/git/close-issue.sh +35 -0
- package/templates/pi/scripts/git/create-tracking-issue.sh +174 -0
- package/templates/pi/scripts/git/link-issue-to-epic.sh +51 -0
- package/templates/pi/scripts/git/update-tracking-issue.sh +66 -0
- package/templates/pi/scripts/languages/go/validate-architecture.sh +139 -0
- package/templates/pi/scripts/languages/go/validate-canonical.sh +129 -0
- package/templates/pi/scripts/languages/go/validate-ci.sh +132 -0
- package/templates/pi/scripts/languages/go/validate-integration.sh +156 -0
- package/templates/pi/scripts/languages/go/validate-operations.sh +146 -0
- package/templates/pi/scripts/languages/go/validate-security.sh +135 -0
- package/templates/pi/scripts/languages/go/validate-tests.sh +125 -0
- package/templates/pi/scripts/languages/java/validate-annotations.sh +185 -0
- package/templates/pi/scripts/languages/java/validate-architecture.sh +159 -0
- package/templates/pi/scripts/languages/java/validate-canonical.sh +114 -0
- package/templates/pi/scripts/languages/java/validate-ci.sh +269 -0
- package/templates/pi/scripts/languages/java/validate-integration.sh +149 -0
- package/templates/pi/scripts/languages/java/validate-operations.sh +142 -0
- package/templates/pi/scripts/languages/java/validate-security.sh +174 -0
- package/templates/pi/scripts/languages/java/validate-spring-architecture.sh +227 -0
- package/templates/pi/scripts/languages/java/validate-tests.sh +159 -0
- package/templates/pi/scripts/languages/python/validate-architecture.sh +99 -0
- package/templates/pi/scripts/languages/python/validate-canonical.sh +124 -0
- package/templates/pi/scripts/languages/python/validate-ci.sh +130 -0
- package/templates/pi/scripts/languages/python/validate-integration.sh +119 -0
- package/templates/pi/scripts/languages/python/validate-operations.sh +107 -0
- package/templates/pi/scripts/languages/python/validate-security.sh +68 -0
- package/templates/pi/scripts/languages/python/validate-tests.sh +102 -0
- package/templates/pi/scripts/languages/rust/validate-architecture.sh +188 -0
- package/templates/pi/scripts/languages/rust/validate-canonical.sh +146 -0
- package/templates/pi/scripts/languages/rust/validate-ci.sh +147 -0
- package/templates/pi/scripts/languages/rust/validate-integration.sh +149 -0
- package/templates/pi/scripts/languages/rust/validate-operations.sh +154 -0
- package/templates/pi/scripts/languages/rust/validate-security.sh +153 -0
- package/templates/pi/scripts/languages/rust/validate-tests.sh +150 -0
- package/templates/pi/scripts/languages/typescript/validate-architecture.sh +157 -0
- package/templates/pi/scripts/languages/typescript/validate-canonical.sh +135 -0
- package/templates/pi/scripts/languages/typescript/validate-ci.sh +244 -0
- package/templates/pi/scripts/languages/typescript/validate-integration.sh +166 -0
- package/templates/pi/scripts/languages/typescript/validate-operations.sh +162 -0
- package/templates/pi/scripts/languages/typescript/validate-security.sh +169 -0
- package/templates/pi/scripts/languages/typescript/validate-tests.sh +158 -0
- package/templates/pi/scripts/merge-mr.sh +95 -0
- package/templates/pi/scripts/mr-validation.sh +228 -0
- package/templates/pi/scripts/validate-architecture-readiness.sh +153 -0
- package/templates/pi/scripts/validate-architecture.sh +22 -0
- package/templates/pi/scripts/validate-canonical.sh +22 -0
- package/templates/pi/scripts/validate-ci.sh +37 -0
- package/templates/pi/scripts/validate-integration.sh +22 -0
- package/templates/pi/scripts/validate-operations.sh +22 -0
- package/templates/pi/scripts/validate-security.sh +22 -0
- package/templates/pi/scripts/validate-tests.sh +22 -0
- package/templates/pi/scripts/validate-ubiquitous-language.sh +291 -0
- package/templates/pi/scripts/validation-cache.sh +139 -0
- package/templates/pi/skills/agents/architecture-coordinator.md +178 -0
- package/templates/pi/skills/agents/architecture-generator.md +79 -0
- package/templates/pi/skills/agents/architecture-validator.md +74 -0
- package/templates/pi/skills/agents/ci-mr-validator.md +46 -0
- package/templates/pi/skills/agents/code-developer.md +76 -0
- package/templates/pi/skills/agents/commit.md +46 -0
- package/templates/pi/skills/agents/curator.md +71 -0
- package/templates/pi/skills/agents/debug.md +59 -0
- package/templates/pi/skills/agents/documentation-maintainer.md +36 -0
- package/templates/pi/skills/agents/goal-loop.md +125 -0
- package/templates/pi/skills/agents/hooks.md +122 -0
- package/templates/pi/skills/agents/integration-validator.md +35 -0
- package/templates/pi/skills/agents/issue-creator.md +75 -0
- package/templates/pi/skills/agents/issue-factory.md +143 -0
- package/templates/pi/skills/agents/kanban.md +85 -0
- package/templates/pi/skills/agents/land.md +59 -0
- package/templates/pi/skills/agents/operations-validator.md +43 -0
- package/templates/pi/skills/agents/pipeline.md +113 -0
- package/templates/pi/skills/agents/plan-mode.md +77 -0
- package/templates/pi/skills/agents/pull.md +40 -0
- package/templates/pi/skills/agents/push.md +41 -0
- package/templates/pi/skills/agents/security-validator.md +85 -0
- package/templates/pi/skills/agents/session-persistence.md +119 -0
- package/templates/pi/skills/agents/slash-commands.md +117 -0
- package/templates/pi/skills/agents/snippets.md +99 -0
- package/templates/pi/skills/agents/subagent-registry.md +78 -0
- package/templates/pi/skills/agents/test-validator.md +42 -0
- package/templates/pi/skills/validators/architecture-validator.md +43 -0
- package/templates/pi/skills/validators/ci-validator.md +27 -0
- package/templates/pi/skills/validators/context-compaction.md +73 -0
- package/templates/pi/skills/validators/integration-validator.md +38 -0
- package/templates/pi/skills/validators/model-registry.md +96 -0
- package/templates/pi/skills/validators/operations-validator.md +34 -0
- package/templates/pi/skills/validators/security-guards.md +72 -0
- package/templates/pi/skills/validators/security-validator.md +41 -0
- package/templates/pi/skills/validators/system-prompt-tiers.md +69 -0
- package/templates/pi/skills/validators/test-validator.md +33 -0
- package/templates/pi/types.ts +62 -0
- package/templates/pi/validators/README.md +93 -0
- package/templates/pi/validators/default.toml +209 -0
- package/templates/pi/validators/spring.toml +142 -0
- package/templates/pi/workpad.md +53 -0
- package/templates/project/java/Dockerfile +14 -0
- package/templates/project/java/README.md +40 -0
- package/templates/project/java/pom.xml +132 -0
- package/templates/project/typescript/Dockerfile +15 -0
- package/templates/project/typescript/README.md +29 -0
- package/templates/project/typescript/package.json +23 -0
- package/templates/project/typescript/tsconfig.json +21 -0
- package/templates/workflow.md +123 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
# TypeScript/JavaScript Code Patterns
|
|
2
|
+
|
|
3
|
+
> **Purpose:** Reusable TypeScript patterns for Guardian projects.
|
|
4
|
+
> **Generic:** Adapt for your framework (Node.js, Bun, etc.).
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Error Handling
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
// Use custom error classes
|
|
12
|
+
class ValidationError extends Error {
|
|
13
|
+
constructor(message: string, public field: string) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = 'ValidationError';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class NetworkError extends Error {
|
|
20
|
+
constructor(message: string, public statusCode?: number) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = 'NetworkError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Result type pattern (never throw in library)
|
|
27
|
+
type Result<T, E = Error> =
|
|
28
|
+
| { ok: true; value: T }
|
|
29
|
+
| { ok: false; error: E };
|
|
30
|
+
|
|
31
|
+
function parseConfig(input: string): Result<Config, ValidationError> {
|
|
32
|
+
try {
|
|
33
|
+
const config = JSON.parse(input);
|
|
34
|
+
return { ok: true, value: config };
|
|
35
|
+
} catch (e) {
|
|
36
|
+
return { ok: false, error: new ValidationError('Invalid JSON', 'config') };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Tracing / Logging
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
// Structured logging
|
|
47
|
+
interface LogEntry {
|
|
48
|
+
level: 'debug' | 'info' | 'warn' | 'error';
|
|
49
|
+
message: string;
|
|
50
|
+
timestamp: Date;
|
|
51
|
+
context?: Record<string, unknown>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const logger = {
|
|
55
|
+
info: (message: string, context?: Record<string, unknown>) => {
|
|
56
|
+
console.log(JSON.stringify({
|
|
57
|
+
level: 'info',
|
|
58
|
+
message,
|
|
59
|
+
timestamp: new Date(),
|
|
60
|
+
context
|
|
61
|
+
}));
|
|
62
|
+
},
|
|
63
|
+
error: (message: string, error?: Error, context?: Record<string, unknown>) => {
|
|
64
|
+
console.error(JSON.stringify({
|
|
65
|
+
level: 'error',
|
|
66
|
+
message,
|
|
67
|
+
timestamp: new Date(),
|
|
68
|
+
error: error?.message,
|
|
69
|
+
stack: error?.stack,
|
|
70
|
+
context
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// Usage
|
|
76
|
+
logger.info('Processing request', { userId, requestId });
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Cancellation / Cleanup
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
// AbortController pattern
|
|
85
|
+
async function fetchWithTimeout(
|
|
86
|
+
url: string,
|
|
87
|
+
timeout: number,
|
|
88
|
+
signal?: AbortSignal
|
|
89
|
+
): Promise<Response> {
|
|
90
|
+
const abortController = new AbortController();
|
|
91
|
+
|
|
92
|
+
// Link external signal
|
|
93
|
+
if (signal) {
|
|
94
|
+
signal.addEventListener('abort', () => abortController.abort());
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Timeout abort
|
|
98
|
+
const timeoutId = setTimeout(() => abortController.abort(), timeout);
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
const response = await fetch(url, { signal: abortController.signal });
|
|
102
|
+
clearTimeout(timeoutId);
|
|
103
|
+
return response;
|
|
104
|
+
} catch (e) {
|
|
105
|
+
clearTimeout(timeoutId);
|
|
106
|
+
if (e.name === 'AbortError') {
|
|
107
|
+
throw new Error('Request cancelled');
|
|
108
|
+
}
|
|
109
|
+
throw e;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Atomic Writes
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
// Write-rename pattern (Node.js/Bun)
|
|
120
|
+
import { writeFileSync, renameSync } from 'fs';
|
|
121
|
+
import { join } from 'path';
|
|
122
|
+
|
|
123
|
+
function atomicWrite(filePath: string, content: string): void {
|
|
124
|
+
const tempPath = join(filePath + '.tmp');
|
|
125
|
+
|
|
126
|
+
// Write to temp file
|
|
127
|
+
writeFileSync(tempPath, content, 'utf-8');
|
|
128
|
+
|
|
129
|
+
// Atomic rename
|
|
130
|
+
renameSync(tempPath, filePath);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Async version (Bun)
|
|
134
|
+
async function atomicWriteAsync(filePath: string, content: string): Promise<void> {
|
|
135
|
+
const tempPath = filePath + '.tmp';
|
|
136
|
+
await Bun.write(tempPath, content);
|
|
137
|
+
await Bun.file(tempPath).rename(filePath);
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Async Patterns
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
// Promise patterns
|
|
147
|
+
async function parallelTasks(): Promise<void> {
|
|
148
|
+
// Run in parallel
|
|
149
|
+
const [a, b, c] = await Promise.all([
|
|
150
|
+
taskA(),
|
|
151
|
+
taskB(),
|
|
152
|
+
taskC()
|
|
153
|
+
]);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Sequential with error handling
|
|
157
|
+
async function sequentialTasks(): Promise<void> {
|
|
158
|
+
for (const task of tasks) {
|
|
159
|
+
await task();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Concurrent limit
|
|
164
|
+
async function concurrentLimit(tasks: Task[], limit: number): Promise<void> {
|
|
165
|
+
const executing = new Set<Promise<void>>();
|
|
166
|
+
|
|
167
|
+
for (const task of tasks) {
|
|
168
|
+
const p = task().then(() => executing.delete(p));
|
|
169
|
+
executing.add(p);
|
|
170
|
+
|
|
171
|
+
if (executing.size >= limit) {
|
|
172
|
+
await Promise.race(executing);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
await Promise.all(executing);
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## Testing
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
// Vitest (Bun-compatible)
|
|
186
|
+
import { describe, it, expect } from 'vitest';
|
|
187
|
+
|
|
188
|
+
describe('MyModule', () => {
|
|
189
|
+
it('should parse correctly', () => {
|
|
190
|
+
const result = parse('input');
|
|
191
|
+
expect(result.ok).toBe(true);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('should handle errors', async () => {
|
|
195
|
+
const result = await riskyOperation();
|
|
196
|
+
expect(result).rejects.toThrow();
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// Mock patterns
|
|
201
|
+
vi.mock('./dependency', () => ({
|
|
202
|
+
fetch: vi.fn().mockResolvedValue({ data: 'mock' })
|
|
203
|
+
}));
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Anti-Patterns (NEVER DO)
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
// ❌ Throwing in library code
|
|
212
|
+
function parse(input: string): Config {
|
|
213
|
+
if (!input) throw new Error('No input'); // BAD
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// ✅ Return Result type
|
|
217
|
+
function parse(input: string): Result<Config, ValidationError> {
|
|
218
|
+
if (!input) return { ok: false, error: new ValidationError('No input') };
|
|
219
|
+
return { ok: true, value: JSON.parse(input) };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// ❌ Unhandled promise rejection
|
|
223
|
+
async function bad() {
|
|
224
|
+
fetch('/api').then(r => r.json()); // BAD - no catch
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// ✅ Always handle errors
|
|
228
|
+
async function good() {
|
|
229
|
+
try {
|
|
230
|
+
const response = await fetch('/api');
|
|
231
|
+
return await response.json();
|
|
232
|
+
} catch (e) {
|
|
233
|
+
logger.error('Fetch failed', e);
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// ❌ Callback hell
|
|
239
|
+
function bad(callback: (err, result) => void) {
|
|
240
|
+
step1((err1, r1) => {
|
|
241
|
+
step2(r1, (err2, r2) => {
|
|
242
|
+
step3(r2, callback); // BAD
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// ✅ Use async/await
|
|
248
|
+
async function good() {
|
|
249
|
+
const r1 = await step1();
|
|
250
|
+
const r2 = await step2(r1);
|
|
251
|
+
return await step3(r2);
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Build Commands
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
# Build (Bun)
|
|
261
|
+
bun build ./src/index.ts --outdir ./dist
|
|
262
|
+
|
|
263
|
+
# Build (npm/ts)
|
|
264
|
+
npm run build
|
|
265
|
+
|
|
266
|
+
# Test (Bun)
|
|
267
|
+
bun test
|
|
268
|
+
|
|
269
|
+
# Test (Vitest)
|
|
270
|
+
vitest run
|
|
271
|
+
|
|
272
|
+
# Lint
|
|
273
|
+
biome check . # Bun/Biome
|
|
274
|
+
eslint . # npm
|
|
275
|
+
|
|
276
|
+
# Format
|
|
277
|
+
biome format . --write # Bun/Biome
|
|
278
|
+
prettier --write . # npm
|
|
279
|
+
|
|
280
|
+
# Type check
|
|
281
|
+
tsc --noEmit
|
|
282
|
+
|
|
283
|
+
# Security audit
|
|
284
|
+
bun audit # Bun
|
|
285
|
+
npm audit # npm
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Dependencies
|
|
291
|
+
|
|
292
|
+
```json
|
|
293
|
+
// package.json (Bun)
|
|
294
|
+
{
|
|
295
|
+
"dependencies": {
|
|
296
|
+
"@clack/prompts": "^0.7.0"
|
|
297
|
+
},
|
|
298
|
+
"devDependencies": {
|
|
299
|
+
"@types/bun": "latest",
|
|
300
|
+
"vitest": "^1.0.0"
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// package.json (npm)
|
|
305
|
+
{
|
|
306
|
+
"dependencies": {},
|
|
307
|
+
"devDependencies": {
|
|
308
|
+
"typescript": "^5.0.0",
|
|
309
|
+
"vitest": "^1.0.0",
|
|
310
|
+
"@types/node": "^20.0.0"
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
```
|