Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ dist
coverage
test/config/src/__gen__/
playground
test/codegen/generators/*/output
test/codegen/generators/*/output
.claude
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ Get an overview of how telemetry works for this project




1 change: 1 addition & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,6 @@ Prefix that follows specification is not enough though. Remember that the title






32 changes: 26 additions & 6 deletions docs/generators/channels.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,34 @@ Depending on which protocol, these are the dependencies:
- `HTTP`: https://github.com/node-fetch/node-fetch v2
- `WebSocket`: https://github.com/websockets/ws v8

For TypeScript what is generated is a single file that include functions to help easier interact with AsyncAPI channels. For example;
For TypeScript, the generator creates one file per protocol plus an index file that re-exports all protocols as namespaces. For example;

```ts
import { Protocols } from 'src/__gen__/index';
const { nats, kafka, mqtt, amqp, event_source, ... } = Protocols;
const { jetStreamPublishTo..., jetStreamPullSubscribeTo..., jetStreamPushSubscriptionFrom..., publishTo..., subscribeTo... } = nats;
// Import specific functions from a protocol file
import {
jetStreamPublishToSendUserSignedup,
subscribeToReceiveUserSignedup,
publishToSendUserSignedup
} from 'src/__gen__/nats';

// Or import the entire protocol namespace
import * as nats from 'src/__gen__/nats';

// Or import all protocols from the index
import { nats, kafka, mqtt, amqp, event_source } from 'src/__gen__/index';
```

First we import the generated file, which is located based on your `outputPath` in the generator options.
The generated file structure is:
```
outputPath/
├── index.ts # Re-exports all protocol namespaces
├── nats.ts # NATS-specific functions
├── kafka.ts # Kafka-specific functions
├── mqtt.ts # MQTT-specific functions
├── amqp.ts # AMQP-specific functions
├── event_source.ts # EventSource-specific functions
├── http_client.ts # HTTP client-specific functions
└── websocket.ts # WebSocket-specific functions
```

Next we import the desired protocol and then we have access to all the support functions. These support functions are an easy way to interact with channels defined in your AsyncAPI document. Take notice it does not care which operations you have defined.
Each protocol file contains standalone exported functions for interacting with channels defined in your AsyncAPI document.
56 changes: 56 additions & 0 deletions docs/migrations/v0.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ sidebar_position: 99
* [Breaking Changes 0.39.0](#breaking-changes-0390)
+ [Functions Parameters](#functions-parameters)
* [Breaking Changes 0.55.1](#breaking-changes-0551)
* [Breaking Changes 0.61.0](#breaking-changes-0610)
+ [Channels Multi-File Output](#channels-multi-file-output)

<!-- tocstop -->

Expand Down Expand Up @@ -63,6 +65,60 @@ const subscriber = await jetStreamPullSubscribeToReceiveUserSignedup({

We upgraded the AsyncAPI Modelina dependency to the `next` version so for the next few versions it will contain breaking changes as we continue to improve the tool.

## Breaking Changes 0.61.0

### Channels Multi-File Output

The `channels` generator now outputs one file per protocol instead of a single file with a `Protocols` object. This change improves tree-shaking, reduces bundle size, and provides better code organization.

**Before (v0.60.x and earlier):**
```typescript
// Single file with Protocols object containing all protocols
import { Protocols } from './channels/index';
const { nats } = Protocols;
const { publishToSendUserSignedup, subscribeToReceiveUserSignedup } = nats;

// Or destructure directly
const { nats: { publishToSendUserSignedup } } = Protocols;
```

**After (v0.61.0+):**
```typescript
// Option 1: Import specific functions directly from protocol file
import {
publishToSendUserSignedup,
subscribeToReceiveUserSignedup
} from './channels/nats';

// Option 2: Import the entire protocol as a namespace
import * as nats from './channels/nats';
nats.publishToSendUserSignedup({ ... });

// Option 3: Import from index (protocols are re-exported as namespaces)
import { nats, kafka, mqtt } from './channels/index';
nats.publishToSendUserSignedup({ ... });
```

**New file structure:**
```
outputPath/
├── index.ts # Re-exports all protocol namespaces
├── nats.ts # NATS-specific functions
├── kafka.ts # Kafka-specific functions
├── mqtt.ts # MQTT-specific functions
├── amqp.ts # AMQP-specific functions
├── event_source.ts # EventSource-specific functions
├── http_client.ts # HTTP client-specific functions
└── websocket.ts # WebSocket-specific functions
```

**Migration steps:**
1. Replace `import { Protocols } from './channels'` with direct imports from protocol files
2. Remove destructuring of the `Protocols` object
3. Update function calls - functions are now standalone exports, not object properties
4. Optionally use namespace imports (`import * as nats from './channels/nats'`) to keep similar syntax





Expand Down
8 changes: 4 additions & 4 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $ npm install -g @the-codegen-project/cli
$ codegen COMMAND
running command...
$ codegen (--version)
@the-codegen-project/cli/0.60.0 linux-x64 node-v18.20.8
@the-codegen-project/cli/1.0.0 linux-x64 node-v18.20.8
$ codegen --help [COMMAND]
USAGE
$ codegen COMMAND
Expand Down Expand Up @@ -85,7 +85,7 @@ DESCRIPTION
Generate code based on your configuration, use `init` to get started.
```

_See code: [src/commands/generate.ts](https://github.com/the-codegen-project/cli/blob/v0.60.0/src/commands/generate.ts)_
_See code: [src/commands/generate.ts](https://github.com/the-codegen-project/cli/blob/v1.0.0/src/commands/generate.ts)_

## `codegen help [COMMAND]`

Expand Down Expand Up @@ -145,7 +145,7 @@ DESCRIPTION
Initialize The Codegen Project in your project
```

_See code: [src/commands/init.ts](https://github.com/the-codegen-project/cli/blob/v0.60.0/src/commands/init.ts)_
_See code: [src/commands/init.ts](https://github.com/the-codegen-project/cli/blob/v1.0.0/src/commands/init.ts)_

## `codegen telemetry ACTION`

Expand All @@ -172,7 +172,7 @@ EXAMPLES
$ codegen telemetry disable
```

_See code: [src/commands/telemetry.ts](https://github.com/the-codegen-project/cli/blob/v0.60.0/src/commands/telemetry.ts)_
_See code: [src/commands/telemetry.ts](https://github.com/the-codegen-project/cli/blob/v1.0.0/src/commands/telemetry.ts)_

## `codegen version`

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@the-codegen-project/cli",
"description": "CLI to work with code generation in any environment",
"version": "0.60.0",
"version": "1.0.0",
"bin": {
"codegen": "./bin/run.mjs"
},
Expand Down Expand Up @@ -119,7 +119,8 @@
"bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION",
"runtime:prepare": "npm link",
"runtime:typescript": "npm run runtime:typescript:setup && npm run runtime:typescript:test",
"runtime:typescript:setup": "npm run runtime:prepare && npm run runtime:services:start && npm run runtime:typescript:generate",
"runtime:typescript:clean": "rimraf test/runtime/typescript/src",
"runtime:typescript:setup": "npm run runtime:typescript:clean && npm run runtime:prepare && npm run runtime:services:start && npm run runtime:typescript:generate",
"runtime:typescript:generate": "cd test/runtime/typescript && npm ci && npm run generate",
"runtime:typescript:test": "cd test/runtime/typescript && npm run test",
"runtime:services:start": "npm run runtime:nats:start && npm run runtime:kafka:start && npm run runtime:mqtt:start && npm run runtime:amqp:start",
Expand All @@ -134,7 +135,7 @@
"runtime:amqp:stop": "cd test/runtime && docker compose -f ./docker-compose-amqp.yml down",
"test:blackbox": "concurrently --group -n typescript \"npm run test:blackbox:typescript\"",
"test:blackbox:typescript": "jest ./test/blackbox/typescript.spec.ts",
"prepare:pr": "npm run build && npm run format && npm run lint:fix && npm run test:update"
"prepare:pr": "npm run build && npm run format && npm run lint:fix && npm run test:update && npm run runtime:typescript:generate"
},
"engines": {
"node": ">=18.0.0"
Expand Down
Loading