@crossdelta/platform-sdk 0.13.1 → 0.13.2
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/package.json +1 -1
- package/bin/cli.js +0 -312
- package/bin/docs/generators/README.md +0 -56
- package/bin/docs/generators/code-style.md +0 -96
- package/bin/docs/generators/hono-bun.md +0 -181
- package/bin/docs/generators/hono-node.md +0 -194
- package/bin/docs/generators/nest.md +0 -358
- package/bin/docs/generators/service.md +0 -564
- package/bin/docs/generators/testing.md +0 -97
- package/bin/integration.collection.json +0 -18
- package/bin/templates/hono-microservice/Dockerfile.hbs +0 -16
- package/bin/templates/hono-microservice/biome.json.hbs +0 -3
- package/bin/templates/hono-microservice/src/index.ts.hbs +0 -18
- package/bin/templates/hono-microservice/tsconfig.json.hbs +0 -14
- package/bin/templates/nest-microservice/Dockerfile.hbs +0 -37
- package/bin/templates/nest-microservice/biome.json.hbs +0 -3
- package/bin/templates/nest-microservice/src/app.context.ts.hbs +0 -17
- package/bin/templates/nest-microservice/src/events/events.module.ts.hbs +0 -8
- package/bin/templates/nest-microservice/src/events/events.service.ts.hbs +0 -22
- package/bin/templates/nest-microservice/src/main.ts.hbs +0 -34
- package/bin/templates/workspace/.github/README.md +0 -70
- package/bin/templates/workspace/.github/actions/check-image-tag-exists/action.yml +0 -27
- package/bin/templates/workspace/.github/actions/check-image-tag-exists/index.js +0 -179
- package/bin/templates/workspace/.github/actions/check-path-changes/action.yml +0 -21
- package/bin/templates/workspace/.github/actions/check-path-changes/index.js +0 -192
- package/bin/templates/workspace/.github/actions/detect-skipped-services/action.yml +0 -38
- package/bin/templates/workspace/.github/actions/generate-scope-matrix/action.yml +0 -17
- package/bin/templates/workspace/.github/actions/generate-scope-matrix/index.js +0 -355
- package/bin/templates/workspace/.github/actions/prepare-build-context/action.yml +0 -49
- package/bin/templates/workspace/.github/actions/resolve-scope-tags/action.yml +0 -31
- package/bin/templates/workspace/.github/actions/resolve-scope-tags/index.js +0 -398
- package/bin/templates/workspace/.github/actions/setup-bun-install/action.yml.hbs +0 -57
- package/bin/templates/workspace/.github/copilot-chat-configuration.json +0 -49
- package/bin/templates/workspace/.github/copilot-instructions.md.hbs +0 -72
- package/bin/templates/workspace/.github/dependabot.yml +0 -18
- package/bin/templates/workspace/.github/workflows/build-and-deploy.yml.hbs +0 -228
- package/bin/templates/workspace/.github/workflows/lint-and-tests.yml.hbs +0 -32
- package/bin/templates/workspace/.github/workflows/publish-packages.yml +0 -154
- package/bin/templates/workspace/apps/.gitkeep +0 -0
- package/bin/templates/workspace/biome.json.hbs +0 -62
- package/bin/templates/workspace/bunfig.toml.hbs +0 -5
- package/bin/templates/workspace/docs/.gitkeep +0 -0
- package/bin/templates/workspace/editorconfig.hbs +0 -9
- package/bin/templates/workspace/gitignore.hbs +0 -15
- package/bin/templates/workspace/infra/Pulumi.dev.yaml.hbs +0 -5
- package/bin/templates/workspace/infra/Pulumi.yaml.hbs +0 -6
- package/bin/templates/workspace/infra/index.ts.hbs +0 -56
- package/bin/templates/workspace/infra/package.json.hbs +0 -21
- package/bin/templates/workspace/infra/services/.gitkeep +0 -0
- package/bin/templates/workspace/infra/tsconfig.json.hbs +0 -15
- package/bin/templates/workspace/npmrc.hbs +0 -2
- package/bin/templates/workspace/package.json.hbs +0 -51
- package/bin/templates/workspace/packages/.gitkeep +0 -0
- package/bin/templates/workspace/packages/contracts/README.md.hbs +0 -166
- package/bin/templates/workspace/packages/contracts/package.json.hbs +0 -22
- package/bin/templates/workspace/packages/contracts/src/events/index.ts +0 -16
- package/bin/templates/workspace/packages/contracts/src/index.ts +0 -10
- package/bin/templates/workspace/packages/contracts/src/stream-policies.ts.hbs +0 -40
- package/bin/templates/workspace/packages/contracts/tsconfig.json.hbs +0 -7
- package/bin/templates/workspace/pnpm-workspace.yaml.hbs +0 -5
- package/bin/templates/workspace/turbo.json +0 -37
- package/bin/templates/workspace/turbo.json.hbs +0 -29
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
# {{scope}}/contracts
|
|
2
|
-
|
|
3
|
-
Shared event contracts for cross-service event consumption.
|
|
4
|
-
|
|
5
|
-
## Purpose
|
|
6
|
-
|
|
7
|
-
This package contains **shared event definitions** (contracts) for events that are consumed by multiple services. When an event is used by more than one service, define it here to ensure type consistency across the platform.
|
|
8
|
-
|
|
9
|
-
## Structure
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
src/
|
|
13
|
-
├── events/ # Event contracts grouped by domain
|
|
14
|
-
│ ├── orders/ # Orders domain
|
|
15
|
-
│ │ ├── created.ts # orders.created event
|
|
16
|
-
│ │ ├── updated.ts # orders.updated event
|
|
17
|
-
│ │ └── index.ts # Re-exports
|
|
18
|
-
│ ├── customers/ # Customers domain
|
|
19
|
-
│ │ ├── updated.ts # customers.updated event
|
|
20
|
-
│ │ └── index.ts # Re-exports
|
|
21
|
-
│ └── index.ts # Re-exports all domains
|
|
22
|
-
├── stream-policies.ts # NATS JetStream retention policies
|
|
23
|
-
└── index.ts # Main export file
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
**Contract files contain:**
|
|
27
|
-
- Zod schema definition
|
|
28
|
-
- Contract object (type + schema + **channel metadata**)
|
|
29
|
-
- TypeScript type inference
|
|
30
|
-
|
|
31
|
-
**Channel metadata** defines which NATS JetStream stream the event belongs to. This enables infrastructure-as-code workflows where streams are auto-created in dev (`pf dev`) and materialized via Pulumi in production.
|
|
32
|
-
|
|
33
|
-
## Adding New Events
|
|
34
|
-
|
|
35
|
-
### Using the CLI (Recommended)
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
pf event add products.created --fields "productId:string,name:string,price:number"
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
This will create `src/events/products/created.ts` with proper domain structure.
|
|
42
|
-
|
|
43
|
-
### Manual Creation
|
|
44
|
-
|
|
45
|
-
See [Adding Events](#manual-creation) section below.
|
|
46
|
-
|
|
47
|
-
## Usage
|
|
48
|
-
|
|
49
|
-
### In Event Handlers (Consumers)
|
|
50
|
-
|
|
51
|
-
```ts
|
|
52
|
-
import { handleEvent } from '@crossdelta/cloudevents'
|
|
53
|
-
import { OrdersCreatedContract, type OrdersCreatedData } from '{{scope}}/contracts'
|
|
54
|
-
|
|
55
|
-
export default handleEvent(OrdersCreatedContract, async (data: OrdersCreatedData) => {
|
|
56
|
-
// data is fully typed from contract
|
|
57
|
-
console.log(data.orderId, data.customerId)
|
|
58
|
-
})
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### In Publishers (REST APIs)
|
|
62
|
-
|
|
63
|
-
```ts
|
|
64
|
-
import { publish } from '@crossdelta/cloudevents'
|
|
65
|
-
import { OrdersCreatedContract } from '{{scope}}/contracts'
|
|
66
|
-
|
|
67
|
-
// Type-safe publishing with contract
|
|
68
|
-
await publish(OrdersCreatedContract, {
|
|
69
|
-
orderId: 'order-123',
|
|
70
|
-
customerId: 'cust-456',
|
|
71
|
-
total: 99.99,
|
|
72
|
-
items: [...]
|
|
73
|
-
})
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
### In Use-Cases
|
|
77
|
-
|
|
78
|
-
```ts
|
|
79
|
-
import type { OrdersCreatedData } from '{{scope}}/contracts'
|
|
80
|
-
|
|
81
|
-
export const processOrder = async (data: OrdersCreatedData) => {
|
|
82
|
-
// Use typed event data
|
|
83
|
-
}
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
## Adding New Contracts
|
|
87
|
-
|
|
88
|
-
Contracts are **auto-generated** when you create event handlers:
|
|
89
|
-
|
|
90
|
-
```bash
|
|
91
|
-
# 1. Create service with event handler
|
|
92
|
-
pf new hono-micro notifications --ai -d "Sends emails on orders.created events"
|
|
93
|
-
|
|
94
|
-
# 2. Add event (creates contract, mock, handler)
|
|
95
|
-
pf event add orders.created --service services/notifications
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
This creates:
|
|
99
|
-
- `packages/contracts/src/events/orders-created.ts` (contract)
|
|
100
|
-
- `packages/contracts/src/events/orders-created.mock.json` (mock)
|
|
101
|
-
- Updates `packages/contracts/src/index.ts` (exports)
|
|
102
|
-
|
|
103
|
-
### Manual Contract Creation
|
|
104
|
-
|
|
105
|
-
```ts
|
|
106
|
-
// packages/contracts/src/events/orders/created.ts
|
|
107
|
-
import { createContract } from '@crossdelta/cloudevents'
|
|
108
|
-
import { z } from 'zod'
|
|
109
|
-
|
|
110
|
-
export const OrdersCreatedSchema = z.object({
|
|
111
|
-
orderId: z.string(),
|
|
112
|
-
customerId: z.string(),
|
|
113
|
-
total: z.number(),
|
|
114
|
-
items: z.array(z.object({
|
|
115
|
-
productId: z.string(),
|
|
116
|
-
quantity: z.number(),
|
|
117
|
-
price: z.number(),
|
|
118
|
-
})),
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
export const OrdersCreatedContract = createContract({
|
|
122
|
-
type: 'orders.created',
|
|
123
|
-
channel: { stream: 'ORDERS' }, // Stream routing metadata
|
|
124
|
-
schema: OrdersCreatedSchema,
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
export type OrdersCreatedData = z.infer<typeof OrdersCreatedContract.schema>
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
**Channel Metadata:**
|
|
131
|
-
- `stream` - NATS JetStream stream name (e.g., `ORDERS`)
|
|
132
|
-
- `subject` - Optional, defaults to event type (e.g., `orders.created`)
|
|
133
|
-
|
|
134
|
-
**Stream Materialization:**
|
|
135
|
-
1. **Development**: `pf dev` scans contracts and auto-creates ephemeral streams from channel metadata
|
|
136
|
-
2. **Production**: Pulumi collects streams from contracts and materializes with retention policies
|
|
137
|
-
|
|
138
|
-
See [`infra/streams/README.md`](../../infra/streams/README.md) for details.
|
|
139
|
-
|
|
140
|
-
## Testing with Mocks
|
|
141
|
-
|
|
142
|
-
```bash
|
|
143
|
-
# List all available events
|
|
144
|
-
pf event list
|
|
145
|
-
|
|
146
|
-
# Publish mock event
|
|
147
|
-
pf event publish orders.created
|
|
148
|
-
|
|
149
|
-
# Publish with custom data
|
|
150
|
-
pf event publish orders.created --data '{"orderId":"test-123"}'
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
## Guidelines
|
|
154
|
-
|
|
155
|
-
- ✅ Use contracts for **shared events** (multi-consumer)
|
|
156
|
-
- ✅ Export both contract and inferred type
|
|
157
|
-
- ✅ Keep contracts minimal and focused
|
|
158
|
-
- ✅ Generate mocks for all contracts
|
|
159
|
-
- ❌ Don't put business logic in contracts
|
|
160
|
-
- ❌ Don't include event handlers in this package
|
|
161
|
-
|
|
162
|
-
**Naming conventions:**
|
|
163
|
-
- Contracts: `OrdersCreatedContract` (plural namespace)
|
|
164
|
-
- Types: `OrdersCreatedData`
|
|
165
|
-
- Files: `orders-created.ts`
|
|
166
|
-
- Event types: `orders.created` (plural namespace, dot notation)
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "{{scope}}/contracts",
|
|
3
|
-
"private": true,
|
|
4
|
-
"type": "module",
|
|
5
|
-
"main": "./src/index.ts",
|
|
6
|
-
"types": "./src/index.ts",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": {
|
|
9
|
-
"types": "./src/index.ts",
|
|
10
|
-
"default": "./src/index.ts"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
"dependencies": {
|
|
14
|
-
"@crossdelta/cloudevents": "^0.5.3",
|
|
15
|
-
"@crossdelta/infrastructure": "^0.5.1",
|
|
16
|
-
"zod": "^4.0.0"
|
|
17
|
-
},
|
|
18
|
-
"devDependencies": {
|
|
19
|
-
"@biomejs/biome": "^1.9.4",
|
|
20
|
-
"typescript": "^5.7.2"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Event Contracts Index
|
|
3
|
-
*
|
|
4
|
-
* Re-exports all event contracts for convenient importing.
|
|
5
|
-
* Services can import from '{{scope}}/contracts' instead of deep imports.
|
|
6
|
-
*
|
|
7
|
-
* Structure:
|
|
8
|
-
* - events/<domain>/<event>.ts - Individual event contracts
|
|
9
|
-
* - events/<domain>/index.ts - Domain-specific exports
|
|
10
|
-
* - This file: Re-exports all domains
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
// Add your event domains here as you create them:
|
|
14
|
-
// export * from './orders'
|
|
15
|
-
// export * from './customers'
|
|
16
|
-
// export * from './products'
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Export your event contracts and schemas here
|
|
2
|
-
// Use the CLI to generate contracts:
|
|
3
|
-
//
|
|
4
|
-
// pf event add orders.created --fields "orderId:string,total:number"
|
|
5
|
-
//
|
|
6
|
-
// This will create: src/events/orders/created.ts
|
|
7
|
-
// Then uncomment the exports below:
|
|
8
|
-
|
|
9
|
-
// export * from './events'
|
|
10
|
-
// export * from './stream-policies'
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* {{workspaceName}} Stream Policies
|
|
3
|
-
*
|
|
4
|
-
* Business rules for NATS JetStream stream configuration.
|
|
5
|
-
* Defines retention, replication, and storage policies per stream.
|
|
6
|
-
*
|
|
7
|
-
* Architecture:
|
|
8
|
-
* - This file: Business rules (data)
|
|
9
|
-
* - @crossdelta/infrastructure: Deployment logic
|
|
10
|
-
* - infra/streams: Connects business rules + deployment logic
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import type { StreamPolicy } from '@crossdelta/infrastructure'
|
|
14
|
-
|
|
15
|
-
// Time constants for readability
|
|
16
|
-
const DAYS = 24 * 60 * 60 * 1000
|
|
17
|
-
const MB = 1024 * 1024
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Stream-specific policies
|
|
21
|
-
* Add entries here as you create new streams via event contracts
|
|
22
|
-
*/
|
|
23
|
-
export const STREAM_POLICIES: Record<string, Partial<StreamPolicy>> = {
|
|
24
|
-
// Example:
|
|
25
|
-
// ORDERS: {
|
|
26
|
-
// maxAge: 14 * DAYS,
|
|
27
|
-
// replicas: 3,
|
|
28
|
-
// },
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Default stream policy
|
|
33
|
-
* Applied to all streams without specific overrides
|
|
34
|
-
*/
|
|
35
|
-
export const DEFAULT_POLICY: Partial<StreamPolicy> = {
|
|
36
|
-
maxAge: 7 * DAYS, // 7 days default retention
|
|
37
|
-
storage: 'file', // Persistent storage
|
|
38
|
-
replicas: 1, // Single replica for non-critical streams
|
|
39
|
-
maxMsgSize: 1 * MB, // 1MB max message size
|
|
40
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://turborepo.org/schema.json",
|
|
3
|
-
"tasks": {
|
|
4
|
-
"start:dev": {
|
|
5
|
-
"cache": false,
|
|
6
|
-
"persistent": true
|
|
7
|
-
},
|
|
8
|
-
"sync-templates": {
|
|
9
|
-
"cache": false
|
|
10
|
-
},
|
|
11
|
-
"sync-templates:check": {
|
|
12
|
-
"cache": false
|
|
13
|
-
},
|
|
14
|
-
"pulumi": {},
|
|
15
|
-
"build": {
|
|
16
|
-
"cache": false
|
|
17
|
-
},
|
|
18
|
-
"test": {
|
|
19
|
-
"cache": false
|
|
20
|
-
},
|
|
21
|
-
"format": {
|
|
22
|
-
"cache": false
|
|
23
|
-
},
|
|
24
|
-
"lint": {
|
|
25
|
-
"cache": false
|
|
26
|
-
},
|
|
27
|
-
"preview": {
|
|
28
|
-
"cache": false,
|
|
29
|
-
"persistent": true
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"ui": "tui",
|
|
33
|
-
"concurrency": "50",
|
|
34
|
-
"globalPassThroughEnv": [
|
|
35
|
-
"*"
|
|
36
|
-
]
|
|
37
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://turborepo.org/schema.json",
|
|
3
|
-
"tasks": {
|
|
4
|
-
"start:dev": {
|
|
5
|
-
"cache": false,
|
|
6
|
-
"persistent": true
|
|
7
|
-
},
|
|
8
|
-
"pulumi": {},
|
|
9
|
-
"build": {
|
|
10
|
-
"cache": false
|
|
11
|
-
},
|
|
12
|
-
"test": {
|
|
13
|
-
"cache": false
|
|
14
|
-
},
|
|
15
|
-
"format": {
|
|
16
|
-
"cache": false
|
|
17
|
-
},
|
|
18
|
-
"lint": {
|
|
19
|
-
"cache": false
|
|
20
|
-
},
|
|
21
|
-
"preview": {
|
|
22
|
-
"cache": false,
|
|
23
|
-
"persistent": true
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
"ui": "tui",
|
|
27
|
-
"concurrency": "50",
|
|
28
|
-
"globalPassThroughEnv": ["*"]
|
|
29
|
-
}
|