Skip to content

Commit 81665c6

Browse files
authored
chore(release): v0.25.0 (#175)
1 parent 4f12190 commit 81665c6

24 files changed

+417
-140
lines changed

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ Each protocol has its own limitations, corner cases, and features; thus, each ha
5454

5555

5656

57+

docs/contributing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ sidebar_label: Contributing
1515
- [Getting started](#getting-started)
1616
- [Contribution recogniton](#contribution-recogniton)
1717
- [Summary of the contribution flow](#summary-of-the-contribution-flow)
18+
- [Code of Conduct](#code-of-conduct)
1819
- [Our Development Process](#our-development-process)
1920
- [Pull Requests](#pull-requests)
2021
- [Conventional commits](#conventional-commits)
@@ -133,3 +134,4 @@ Pull requests should have a title that follows the specification, otherwise, mer
133134
What about MAJOR release? just add `!` to the prefix, like `fix!: ` or `refactor!: `
134135

135136
Prefix that follows specification is not enough though. Remember that the title must be clear and descriptive with usage of [imperative mood](https://chris.beams.io/posts/git-commit/#imperative).
137+

docs/usage.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $ npm install -g @the-codegen-project/cli
99
$ codegen COMMAND
1010
running command...
1111
$ codegen (--version)
12-
@the-codegen-project/cli/0.24.2 linux-x64 node-v18.20.5
12+
@the-codegen-project/cli/0.25.0 linux-x64 node-v18.20.5
1313
$ codegen --help [COMMAND]
1414
USAGE
1515
$ codegen COMMAND
@@ -81,7 +81,7 @@ DESCRIPTION
8181
Generate code based on your configuration, use `init` to get started.
8282
```
8383

84-
_See code: [src/commands/generate.ts](https://github.com/the-codegen-project/cli/blob/v0.24.2/src/commands/generate.ts)_
84+
_See code: [src/commands/generate.ts](https://github.com/the-codegen-project/cli/blob/v0.25.0/src/commands/generate.ts)_
8585

8686
## `codegen help [COMMAND]`
8787

@@ -139,7 +139,7 @@ DESCRIPTION
139139
Initialize The Codegen Project in your project
140140
```
141141

142-
_See code: [src/commands/init.ts](https://github.com/the-codegen-project/cli/blob/v0.24.2/src/commands/init.ts)_
142+
_See code: [src/commands/init.ts](https://github.com/the-codegen-project/cli/blob/v0.25.0/src/commands/init.ts)_
143143

144144
## `codegen version`
145145

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@the-codegen-project/cli",
33
"description": "CLI to work with code generation in any environment",
4-
"version": "0.24.2",
4+
"version": "0.25.0",
55
"bin": {
66
"codegen": "./bin/run.mjs"
77
},

schemas/configuration-schema-0.json

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,24 @@
99
"type": "object",
1010
"properties": {
1111
"$schema": {
12-
"type": "string"
12+
"type": "string",
13+
"description": "For JSON and YAML configuration files this is used to force the IDE to enable auto completion and validation features"
1314
},
1415
"inputType": {
1516
"type": "string",
16-
"const": "asyncapi"
17+
"const": "asyncapi",
18+
"description": "The type of document "
1719
},
1820
"inputPath": {
19-
"type": "string"
21+
"type": "string",
22+
"description": "The path to the input document "
2023
},
2124
"language": {
2225
"type": "string",
2326
"enum": [
2427
"typescript"
25-
]
28+
],
29+
"description": "Set the global language for all generators, either one needs to be set"
2630
},
2731
"generators": {
2832
"type": "array",
@@ -177,6 +181,43 @@
177181
"description": "In case you have multiple TypeScript payload generators, you can specify which one to use as the dependency for this channels generator.",
178182
"default": "payloads-typescript"
179183
},
184+
"asyncapiReverseOperations": {
185+
"type": "boolean",
186+
"default": false,
187+
"description": "Setting this to true generate operations with reversed meaning. So for AsyncAPI this means if an operation is defined as action: \"send\", it gets the opposite view of \"receive\"."
188+
},
189+
"asyncapiGenerateForOperations": {
190+
"type": "boolean",
191+
"default": true,
192+
"description": "Setting this to false means we dont enforce the operations defined in the AsyncAPI document and generate more generic channels."
193+
},
194+
"functionTypeMapping": {
195+
"type": "object",
196+
"additionalProperties": {
197+
"anyOf": [
198+
{
199+
"not": {}
200+
},
201+
{
202+
"type": "array",
203+
"items": {
204+
"type": "string",
205+
"enum": [
206+
"nats_jetstream_publish",
207+
"nats_jetstream_pull_subscribe",
208+
"nats_jetstream_push_subscribe",
209+
"nats_subscribe",
210+
"nats_publish",
211+
"nats_request",
212+
"nats_reply"
213+
]
214+
}
215+
}
216+
]
217+
},
218+
"default": {},
219+
"description": "Used in conjunction with AsyncAPI input, can define channel ID along side the type of functions that should be rendered."
220+
},
180221
"language": {
181222
"type": "string",
182223
"const": "typescript",

src/codegen/generators/helpers/payloads.ts

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import {
44
ConstrainedObjectModel,
55
OutputModel
66
} from '@asyncapi/modelina';
7-
import {AsyncAPIDocumentInterface, ChannelInterface, MessageInterface, OperationInterface, OperationReplyInterface} from '@asyncapi/parser';
7+
import {
8+
AsyncAPIDocumentInterface,
9+
ChannelInterface,
10+
MessageInterface,
11+
OperationInterface,
12+
OperationReplyInterface
13+
} from '@asyncapi/parser';
814
import {ChannelPayload, PayloadRenderType} from '../../types';
915
import {pascalCase} from '../typescript/utils';
1016
import {findExtensionObject, findNameFromChannel} from '../../utils';
@@ -23,17 +29,20 @@ export async function generateAsyncAPIPayloads<GeneratorType>(
2329
let otherModels: ChannelPayload[] = [];
2430
if (asyncapiDocument.allChannels().all().length > 0) {
2531
for (const channel of asyncapiDocument.allChannels().all()) {
26-
const processMessages = async (messagesToProcess: MessageInterface[], preId: string): Promise<{generatedMessages: any[], messageType: string} | undefined> => {
32+
const processMessages = async (
33+
messagesToProcess: MessageInterface[],
34+
preId: string
35+
): Promise<
36+
{generatedMessages: any[]; messageType: string} | undefined
37+
> => {
2738
let schemaObj: any = {
2839
type: 'object',
2940
$schema: 'http://json-schema.org/draft-07/schema'
3041
};
3142
const messages = messagesToProcess;
3243
if (messages.length > 1) {
3344
schemaObj.oneOf = [];
34-
schemaObj['$id'] = pascalCase(
35-
`${preId}_Payload`
36-
);
45+
schemaObj['$id'] = pascalCase(`${preId}_Payload`);
3746
for (const message of messages) {
3847
const schema = AsyncAPIInputProcessor.convertToInternalSchema(
3948
message.payload() as any
@@ -87,25 +96,39 @@ export async function generateAsyncAPIPayloads<GeneratorType>(
8796
const operationMessages = operation.messages().all();
8897
const operationReply = operation.reply();
8998
if (operationReply) {
90-
const operationReplyId = findReplyId(operation, operationReply, channel);
91-
const operationReplyGeneratedMessages = await processMessages(operationReply.messages().all(), operationReplyId);
99+
const operationReplyId = findReplyId(
100+
operation,
101+
operationReply,
102+
channel
103+
);
104+
const operationReplyGeneratedMessages = await processMessages(
105+
operationReply.messages().all(),
106+
operationReplyId
107+
);
92108
if (operationReplyGeneratedMessages) {
93109
generatedOperationPayloads[operationReplyId] = {
94-
messageModel: operationReplyGeneratedMessages.generatedMessages[0],
110+
messageModel:
111+
operationReplyGeneratedMessages.generatedMessages[0],
95112
messageType: operationReplyGeneratedMessages.messageType
96113
};
97114
}
98115
}
99116
const operationId = findOperationId(operation, channel);
100-
const operationGeneratedMessages = await processMessages(operationMessages, operationId);
117+
const operationGeneratedMessages = await processMessages(
118+
operationMessages,
119+
operationId
120+
);
101121
if (operationGeneratedMessages) {
102122
generatedOperationPayloads[operationId] = {
103123
messageModel: operationGeneratedMessages.generatedMessages[0],
104124
messageType: operationGeneratedMessages.messageType
105125
};
106126
}
107127
}
108-
const channelGeneratedMessages = await processMessages(channel.messages().all(), findNameFromChannel(channel));
128+
const channelGeneratedMessages = await processMessages(
129+
channel.messages().all(),
130+
findNameFromChannel(channel)
131+
);
109132
if (channelGeneratedMessages) {
110133
generatedChannelPayloads[channel.id()] = {
111134
messageModel: channelGeneratedMessages.generatedMessages[0],
@@ -131,12 +154,24 @@ export async function generateAsyncAPIPayloads<GeneratorType>(
131154
};
132155
}
133156

134-
export function findReplyId(operation: OperationInterface, reply: OperationReplyInterface, channel: ChannelInterface) {
135-
return (reply.json() as any)?.id ?? `${findOperationId(operation, reply.channel() ?? channel)}_reply`;
157+
export function findReplyId(
158+
operation: OperationInterface,
159+
reply: OperationReplyInterface,
160+
channel: ChannelInterface
161+
) {
162+
return (
163+
(reply.json() as any)?.id ??
164+
`${findOperationId(operation, reply.channel() ?? channel)}_reply`
165+
);
136166
}
137-
export function findOperationId(operation: OperationInterface, channel: ChannelInterface) {
167+
export function findOperationId(
168+
operation: OperationInterface,
169+
channel: ChannelInterface
170+
) {
138171
let operationId = operation.id();
139-
operationId = operation.hasOperationId() ? operation.operationId() : operationId;
172+
operationId = operation.hasOperationId()
173+
? operation.operationId()
174+
: operationId;
140175
const userSpecificName = findExtensionObject(operation)
141176
? findExtensionObject(operation)['channelName']
142177
: undefined;

src/codegen/generators/typescript/channels/asyncapi.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ChannelFunctionTypes } from "./types";
1+
import {ChannelFunctionTypes} from './types';
22

3-
type Action = 'send' | 'receive' | 'subscribe' | 'publish'
3+
type Action = 'send' | 'receive' | 'subscribe' | 'publish';
44
const sendingFunctionTypes = [
55
ChannelFunctionTypes.NATS_JETSTREAM_PUBLISH,
66
ChannelFunctionTypes.NATS_PUBLISH,
@@ -20,21 +20,31 @@ export function shouldRenderFunctionType(
2020
action: Action,
2121
reverseOperation: boolean
2222
) {
23-
const listToCheck = [...(Array.isArray(functionTypesToCheckFor) ? functionTypesToCheckFor : [functionTypesToCheckFor])];
23+
const listToCheck = [
24+
...(Array.isArray(functionTypesToCheckFor)
25+
? functionTypesToCheckFor
26+
: [functionTypesToCheckFor])
27+
];
2428
const hasSendingOperation = action === 'send' || action === 'subscribe';
2529
const hasReceivingOperation = action === 'receive' || action === 'publish';
2630
const hasFunctionMappingConfig = givenFunctionTypes !== undefined;
27-
const checkForSending = listToCheck.some(item => sendingFunctionTypes.includes(item));
28-
const checkForReceiving = listToCheck.some(item => receivingFunctionTypes.includes(item));
29-
const hasFunctionType = (givenFunctionTypes ?? []).some(item => listToCheck.includes(item));
31+
const checkForSending = listToCheck.some((item) =>
32+
sendingFunctionTypes.includes(item)
33+
);
34+
const checkForReceiving = listToCheck.some((item) =>
35+
receivingFunctionTypes.includes(item)
36+
);
37+
const hasFunctionType = (givenFunctionTypes ?? []).some((item) =>
38+
listToCheck.includes(item)
39+
);
3040
if (hasFunctionMappingConfig) {
3141
if (hasFunctionType) {
3242
const renderForSending = checkForSending && hasSendingOperation;
33-
const renderForReceiving = checkForReceiving && hasReceivingOperation;
43+
const renderForReceiving = checkForReceiving && hasReceivingOperation;
3444
return renderForSending || renderForReceiving;
3545
}
3646
return false;
37-
}
47+
}
3848

3949
if (reverseOperation) {
4050
const renderForSending = hasSendingOperation && checkForReceiving;

0 commit comments

Comments
 (0)