@crossdelta/platform-sdk 0.10.0 → 0.11.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/README.md +40 -3
- package/bin/cli.js +170 -42436
- package/bin/docs/generators/README.md +29 -20
- package/bin/docs/generators/code-style.md +96 -0
- package/bin/docs/generators/hono-bun.md +31 -45
- package/bin/docs/generators/hono-node.md +33 -57
- package/bin/docs/generators/nest.md +169 -107
- package/bin/docs/generators/service.md +133 -528
- package/bin/docs/generators/testing.md +97 -0
- package/bin/templates/nest-microservice/biome.json.hbs +1 -8
- package/bin/templates/workspace/biome.json.hbs +2 -1
- package/bin/templates/workspace/packages/contracts/package.json.hbs +1 -1
- package/package.json +128 -113
- package/bin/docs/generators/nest.md.new +0 -351
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Testing Guidelines
|
|
2
|
+
|
|
3
|
+
## 🚨 CRITICAL: bun:test Only
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
// ✅ CORRECT
|
|
7
|
+
import { describe, expect, it } from 'bun:test'
|
|
8
|
+
|
|
9
|
+
// ❌ WRONG - do NOT use
|
|
10
|
+
jest.mock(...) // Jest doesn't work
|
|
11
|
+
jest.unstable_mockModule() // Jest doesn't work
|
|
12
|
+
vi.mock(...) // Vitest doesn't work
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## What to Test
|
|
18
|
+
|
|
19
|
+
- Test ONLY use-cases (not handlers)
|
|
20
|
+
- No mocking - use dependency injection
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { describe, expect, it } from 'bun:test'
|
|
24
|
+
import { processOrder } from './process-order.use-case'
|
|
25
|
+
|
|
26
|
+
describe('processOrder', () => {
|
|
27
|
+
it('processes order', async () => {
|
|
28
|
+
const store = new Map()
|
|
29
|
+
await processOrder({ orderId: '123', total: 100 }, store)
|
|
30
|
+
expect(store.has('123')).toBe(true)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('throws on missing data', async () => {
|
|
34
|
+
await expect(processOrder(null as any, new Map())).rejects.toThrow()
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## External Services & Config
|
|
42
|
+
|
|
43
|
+
Use dependency injection, not mocking:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
// ✅ Use-case accepts dependencies
|
|
47
|
+
export const sendPush = async (
|
|
48
|
+
data: PushData,
|
|
49
|
+
config: { instanceId: string }
|
|
50
|
+
) => {
|
|
51
|
+
if (!config.instanceId) throw new Error('Missing instanceId')
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ✅ Test with fake/config
|
|
55
|
+
it('throws on missing config', async () => {
|
|
56
|
+
await expect(sendPush({}, { instanceId: '' })).rejects.toThrow()
|
|
57
|
+
})
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## ❌ WRONG patterns (NEVER use these)
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
// process.env manipulation
|
|
66
|
+
beforeEach(() => { process.env.X = 'test' })
|
|
67
|
+
afterEach(() => { process.env = env })
|
|
68
|
+
|
|
69
|
+
// @ts-ignore for mocking
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
svc.beams = new FakeBeams()
|
|
72
|
+
|
|
73
|
+
// Jest/Vitest mocking
|
|
74
|
+
jest.mock(...)
|
|
75
|
+
vi.mock(...)
|
|
76
|
+
|
|
77
|
+
// Dynamic imports for error testing
|
|
78
|
+
await expect(import('./module')).rejects.toThrow()
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## NestJS Services
|
|
84
|
+
|
|
85
|
+
For NestJS: extract business logic into pure functions, test those:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
// ✅ Extract testable logic from service
|
|
89
|
+
export const validateConfig = (config: { id: string }) => {
|
|
90
|
+
if (!config.id) throw new Error('Missing id')
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ✅ Test the extracted function
|
|
94
|
+
it('validates config', () => {
|
|
95
|
+
expect(() => validateConfig({ id: '' })).toThrow()
|
|
96
|
+
})
|
|
97
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crossdelta/platform-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Platform toolkit for event-driven microservices — keeping code and infrastructure in lockstep.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -49,123 +49,138 @@
|
|
|
49
49
|
"email": "mail@hoevelmanns.io"
|
|
50
50
|
},
|
|
51
51
|
"generatorConfig": {
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
"tsconfig.json",
|
|
59
|
-
"Dockerfile"
|
|
60
|
-
]
|
|
52
|
+
"docs": {
|
|
53
|
+
"base": ["service.md", "code-style.md", "testing.md"],
|
|
54
|
+
"frameworks": {
|
|
55
|
+
"hono": {
|
|
56
|
+
"bun": "hono-bun.md",
|
|
57
|
+
"node": "hono-node.md"
|
|
61
58
|
},
|
|
62
|
-
"nest":
|
|
63
|
-
"commandType": "nest-micro",
|
|
64
|
-
"entryPoint": "src/main.ts",
|
|
65
|
-
"skipFiles": [
|
|
66
|
-
"package.json",
|
|
67
|
-
"tsconfig.json",
|
|
68
|
-
"Dockerfile"
|
|
69
|
-
]
|
|
70
|
-
}
|
|
59
|
+
"nest": "nest.md"
|
|
71
60
|
}
|
|
72
61
|
},
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
"lint": "biome lint --fix",
|
|
83
|
-
"test": "bun test",
|
|
84
|
-
"test:watch": "bun test --watch"
|
|
85
|
-
},
|
|
86
|
-
"schematics": "./dist/schematics/collection.json",
|
|
87
|
-
"esbuild": {
|
|
88
|
-
"external": [
|
|
89
|
-
"@crossdelta/infrastructure",
|
|
90
|
-
"@faker-js/faker",
|
|
91
|
-
"ai",
|
|
92
|
-
"@ai-sdk/openai",
|
|
93
|
-
"@ai-sdk/anthropic",
|
|
94
|
-
"vite",
|
|
95
|
-
"handlebars",
|
|
96
|
-
"zx",
|
|
97
|
-
"listr2",
|
|
98
|
-
"execa",
|
|
99
|
-
"globby",
|
|
100
|
-
"fs-extra",
|
|
101
|
-
"chalk",
|
|
102
|
-
"ora",
|
|
103
|
-
"jiti",
|
|
104
|
-
"zod"
|
|
105
|
-
]
|
|
106
|
-
},
|
|
107
|
-
"dependencies": {
|
|
108
|
-
"@ai-sdk/anthropic": "^2.0.53",
|
|
109
|
-
"@ai-sdk/openai": "^2.0.79",
|
|
110
|
-
"@angular-devkit/core": "^21.0.0",
|
|
111
|
-
"@faker-js/faker": "^9.8.0",
|
|
112
|
-
"@inquirer/prompts": "^7.5.0",
|
|
113
|
-
"@listr2/prompt-adapter-enquirer": "^2.0.15",
|
|
114
|
-
"ai": "^5.0.108",
|
|
115
|
-
"chalk": "^5.4.1",
|
|
116
|
-
"chokidar": "^5.0.0",
|
|
117
|
-
"cli-table3": "^0.6.5",
|
|
118
|
-
"commander": "^13.1.0",
|
|
119
|
-
"dotenv": "^17.2.3",
|
|
120
|
-
"enquirer": "^2.4.1",
|
|
121
|
-
"execa": "^9.5.2",
|
|
122
|
-
"fs-extra": "^11.3.0",
|
|
123
|
-
"globby": "^14.1.0",
|
|
124
|
-
"handlebars": "^4.7.8",
|
|
125
|
-
"jiti": "^2.6.1",
|
|
126
|
-
"listr2": "^8.3.2",
|
|
127
|
-
"ora": "^8.2.0",
|
|
128
|
-
"os": "^0.1.2",
|
|
129
|
-
"package-up": "^5.0.0",
|
|
130
|
-
"rimraf": "^6.1.2",
|
|
131
|
-
"terminal-link": "^4.0.0",
|
|
132
|
-
"ts-morph": "^27.0.0",
|
|
133
|
-
"vite": "^6.3.4",
|
|
134
|
-
"zod": "^3.24.3",
|
|
135
|
-
"zx": "^8.5.3"
|
|
136
|
-
},
|
|
137
|
-
"peerDependencies": {
|
|
138
|
-
"@crossdelta/cloudevents": "*",
|
|
139
|
-
"@crossdelta/infrastructure": "*",
|
|
140
|
-
"@nestjs/schematics": "^11.0.5",
|
|
141
|
-
"turbo": "^2.0.0"
|
|
142
|
-
},
|
|
143
|
-
"peerDependenciesMeta": {
|
|
144
|
-
"@crossdelta/cloudevents": {
|
|
145
|
-
"optional": true
|
|
146
|
-
},
|
|
147
|
-
"@crossdelta/infrastructure": {
|
|
148
|
-
"optional": true
|
|
62
|
+
"serviceTypes": {
|
|
63
|
+
"hono": {
|
|
64
|
+
"commandType": "hono-micro",
|
|
65
|
+
"entryPoint": "src/index.ts",
|
|
66
|
+
"skipFiles": [
|
|
67
|
+
"package.json",
|
|
68
|
+
"tsconfig.json",
|
|
69
|
+
"Dockerfile"
|
|
70
|
+
]
|
|
149
71
|
},
|
|
150
|
-
"
|
|
151
|
-
"
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
72
|
+
"nest": {
|
|
73
|
+
"commandType": "nest-micro",
|
|
74
|
+
"entryPoint": "src/main.ts",
|
|
75
|
+
"skipFiles": [
|
|
76
|
+
"package.json",
|
|
77
|
+
"tsconfig.json",
|
|
78
|
+
"Dockerfile"
|
|
79
|
+
]
|
|
155
80
|
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"scripts": {
|
|
84
|
+
"start:dev": "node esbuild.config.mjs --watch",
|
|
85
|
+
"build:cli": "node esbuild.config.mjs",
|
|
86
|
+
"build:cli:copy": "cp cli/integration.collection.json bin/integration.collection.json && rm -rf bin/templates && mkdir -p bin/templates && cp -r cli/src/commands/create/workspace/templates bin/templates/workspace && cp -r cli/src/commands/create/hono-microservice/templates bin/templates/hono-microservice && cp -r cli/src/commands/create/nest-microservice/templates bin/templates/nest-microservice && mkdir -p bin/docs/generators && cp -r docs/generators/* bin/docs/generators/",
|
|
87
|
+
"build:schematics:transpile": "tsc --project tsconfig.schematics.json",
|
|
88
|
+
"build:schematics:copy": "cp -R schematics/* dist/schematics && find dist/schematics -name '*.ts' -delete",
|
|
89
|
+
"build:schematics": "npm run build:schematics:transpile && npm run build:schematics:copy",
|
|
90
|
+
"build": "npm run build:cli && npm run build:schematics && npm run build:cli:copy",
|
|
91
|
+
"prepublishOnly": "npm run build",
|
|
92
|
+
"lint": "biome lint --fix",
|
|
93
|
+
"test": "bun test",
|
|
94
|
+
"test:watch": "bun test --watch"
|
|
95
|
+
},
|
|
96
|
+
"schematics": "./dist/schematics/collection.json",
|
|
97
|
+
"esbuild": {
|
|
98
|
+
"external": [
|
|
99
|
+
"@crossdelta/infrastructure",
|
|
100
|
+
"@faker-js/faker",
|
|
101
|
+
"@inquirer/prompts",
|
|
102
|
+
"ai",
|
|
103
|
+
"@ai-sdk/openai",
|
|
104
|
+
"@ai-sdk/anthropic",
|
|
105
|
+
"vite",
|
|
106
|
+
"handlebars",
|
|
107
|
+
"zx",
|
|
108
|
+
"listr2",
|
|
109
|
+
"enquirer",
|
|
110
|
+
"execa",
|
|
111
|
+
"globby",
|
|
112
|
+
"fs-extra",
|
|
113
|
+
"chalk",
|
|
114
|
+
"ora",
|
|
115
|
+
"jiti",
|
|
116
|
+
"zod",
|
|
117
|
+
"ts-morph",
|
|
118
|
+
"commander",
|
|
119
|
+
"chokidar"
|
|
120
|
+
]
|
|
121
|
+
},
|
|
122
|
+
"dependencies": {
|
|
123
|
+
"@ai-sdk/anthropic": "^2.0.53",
|
|
124
|
+
"@ai-sdk/openai": "^2.0.79",
|
|
125
|
+
"@angular-devkit/core": "^21.0.0",
|
|
126
|
+
"@faker-js/faker": "^9.8.0",
|
|
127
|
+
"@inquirer/prompts": "^7.5.0",
|
|
128
|
+
"@listr2/prompt-adapter-enquirer": "^2.0.15",
|
|
129
|
+
"ai": "^5.0.108",
|
|
130
|
+
"chalk": "^5.4.1",
|
|
131
|
+
"chokidar": "^5.0.0",
|
|
132
|
+
"cli-table3": "^0.6.5",
|
|
133
|
+
"commander": "^13.1.0",
|
|
134
|
+
"dotenv": "^17.2.3",
|
|
135
|
+
"enquirer": "^2.4.1",
|
|
136
|
+
"execa": "^9.5.2",
|
|
137
|
+
"fs-extra": "^11.3.0",
|
|
138
|
+
"globby": "^14.1.0",
|
|
139
|
+
"handlebars": "^4.7.8",
|
|
140
|
+
"jiti": "^2.6.1",
|
|
141
|
+
"listr2": "^8.3.2",
|
|
142
|
+
"ora": "^8.2.0",
|
|
143
|
+
"os": "^0.1.2",
|
|
144
|
+
"package-up": "^5.0.0",
|
|
145
|
+
"rimraf": "^6.1.2",
|
|
146
|
+
"terminal-link": "^4.0.0",
|
|
147
|
+
"ts-morph": "^27.0.0",
|
|
148
|
+
"vite": "^6.3.4",
|
|
149
|
+
"zod": "^3.24.3",
|
|
150
|
+
"zx": "^8.5.3"
|
|
151
|
+
},
|
|
152
|
+
"peerDependencies": {
|
|
153
|
+
"@crossdelta/cloudevents": "*",
|
|
154
|
+
"@crossdelta/infrastructure": "*",
|
|
155
|
+
"@nestjs/schematics": "^11.0.5",
|
|
156
|
+
"turbo": "^2.0.0"
|
|
157
|
+
},
|
|
158
|
+
"peerDependenciesMeta": {
|
|
159
|
+
"@crossdelta/cloudevents": {
|
|
160
|
+
"optional": true
|
|
161
|
+
},
|
|
162
|
+
"@crossdelta/infrastructure": {
|
|
163
|
+
"optional": true
|
|
156
164
|
},
|
|
157
|
-
"
|
|
158
|
-
"
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
"
|
|
162
|
-
"@nestjs/schematics": "^11.0.9",
|
|
163
|
-
"@types/fs-extra": "^11.0.4",
|
|
164
|
-
"bun-types": "^1.3.4",
|
|
165
|
-
"comment-json": "^4.4.1",
|
|
166
|
-
"esbuild": "^0.25.3",
|
|
167
|
-
"eslint": "^9.25.1",
|
|
168
|
-
"typescript": "^5.8.3",
|
|
169
|
-
"typescript-eslint": "^8.31.1"
|
|
165
|
+
"@nestjs/schematics": {
|
|
166
|
+
"optional": true
|
|
167
|
+
},
|
|
168
|
+
"turbo": {
|
|
169
|
+
"optional": true
|
|
170
170
|
}
|
|
171
|
+
},
|
|
172
|
+
"devDependencies": {
|
|
173
|
+
"@angular-devkit/core": "^21.0.0",
|
|
174
|
+
"@angular-devkit/schematics": "^21.0.0",
|
|
175
|
+
"@angular-devkit/schematics-cli": "^19.2.10",
|
|
176
|
+
"@eslint/js": "^9.22.0",
|
|
177
|
+
"@nestjs/schematics": "^11.0.9",
|
|
178
|
+
"@types/fs-extra": "^11.0.4",
|
|
179
|
+
"bun-types": "^1.3.4",
|
|
180
|
+
"comment-json": "^4.4.1",
|
|
181
|
+
"esbuild": "^0.25.3",
|
|
182
|
+
"eslint": "^9.25.1",
|
|
183
|
+
"typescript": "^5.8.3",
|
|
184
|
+
"typescript-eslint": "^8.31.1"
|
|
185
|
+
}
|
|
171
186
|
}
|