Skip to content

Commit

Permalink
chore(release): v0.20.0 (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Oct 20, 2024
1 parent 6a38577 commit d961aa9
Show file tree
Hide file tree
Showing 25 changed files with 213 additions and 139 deletions.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ Each protocol has its own limitations, corner cases, and features; thus, each ha




1 change: 1 addition & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,4 @@ Prefix that follows specification is not enough though. Remember that the title
When you submit changes, your submissions are understood to be under the same [Apache 2.0 License](../LICENSE) that covers the project.



6 changes: 3 additions & 3 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.19.3 linux-x64 node-v18.20.4
@the-codegen-project/cli/0.20.0 linux-x64 node-v18.20.4
$ codegen --help [COMMAND]
USAGE
$ codegen COMMAND
Expand Down Expand Up @@ -81,7 +81,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.19.3/src/commands/generate.ts)_
_See code: [src/commands/generate.ts](https://github.com/the-codegen-project/cli/blob/v0.20.0/src/commands/generate.ts)_

## `codegen help [COMMAND]`

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

_See code: [src/commands/init.ts](https://github.com/the-codegen-project/cli/blob/v0.19.3/src/commands/init.ts)_
_See code: [src/commands/init.ts](https://github.com/the-codegen-project/cli/blob/v0.20.0/src/commands/init.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.

2 changes: 1 addition & 1 deletion 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.19.3",
"version": "0.20.0",
"bin": {
"codegen": "./bin/run.mjs"
},
Expand Down
50 changes: 50 additions & 0 deletions schemas/configuration-schema-0.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,56 @@
},
"additionalProperties": false
},
{
"type": "object",
"properties": {
"id": {
"type": "string",
"default": "client-typescript"
},
"dependencies": {
"type": "array",
"items": {
"type": "string"
},
"default": [
"channels-typescript"
]
},
"preset": {
"type": "string",
"const": "client",
"default": "client"
},
"outputPath": {
"type": "string",
"default": "src/__gen__/clients"
},
"protocols": {
"type": "array",
"items": {
"type": "string",
"enum": [
"nats"
]
},
"default": [
"nats"
]
},
"language": {
"type": "string",
"const": "typescript",
"default": "typescript"
},
"channelsGeneratorId": {
"type": "string",
"description": "In case you have multiple TypeScript channels generators, you can specify which one to use as the dependency for this channels generator.",
"default": "channels-typescript"
}
},
"additionalProperties": false
},
{
"type": "object",
"properties": {
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/generators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {TypeScriptChannelsGeneratorInternal} from './typescript/channels';
import {loadConfigFile} from '../configuration-manager';
import {loadAsyncapi} from '../inputs/asyncapi';
import {runGenerators} from '..';
import { TypeScriptClientGeneratorInternal } from './typescript/client';
import {TypeScriptClientGeneratorInternal} from './typescript/client';

export {
TypeScriptChannelsGenerator,
Expand All @@ -45,7 +45,7 @@ export {
defaultTypeScriptClientGenerator,
generateTypeScriptClient,
CustomGenerator,
defaultCustomGenerator,
defaultCustomGenerator
};

export async function renderGenerator(
Expand Down
40 changes: 24 additions & 16 deletions src/codegen/generators/typescript/channels/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ import {renderJetstreamPushSubscription} from './protocols/nats/jetstreamPushSub
import {ensureRelativePath, findNameFromChannel} from '../../../utils';
export type SupportedProtocols = 'nats';

export enum ChannelFunctionTypes {
export enum ChannelFunctionTypes {
NATS_JETSTREAM_PUBLISH = 'nats_jetstream_publish',
NATS_JETSTREAM_PULL_SUBSCRIBE = 'nats_jetstream_pull_subscribe',
NATS_JETSTREAM_PUSH_SUBSCRIBE = 'nats_jetstream_push_subscribe',
NATS_CORE_SUBSCRIBE = 'nats_core_subscribe',
NATS_CORE_PUBLISH = 'nats_core_publish',
NATS_REQUEST = 'nats_request',
NATS_REPLY = 'nats_reply'
};
NATS_REPLY = 'nats_reply'
}

export const zodTypescriptChannelsGenerator = z.object({
id: z.string().optional().default('channels-typescript'),
Expand Down Expand Up @@ -80,17 +80,17 @@ export interface TypeScriptChannelsContext extends GenericCodegenContext {
generator: TypeScriptChannelsGeneratorInternal;
}
export type renderedFunctionType = {
functionType: ChannelFunctionTypes,
functionName: string,
messageType: string,
parameterType?: string
functionType: ChannelFunctionTypes;
functionName: string;
messageType: string;
parameterType?: string;
};
export interface TypeScriptChannelRenderType {
payloadRender: TypeScriptPayloadRenderType,
parameterRender: TypeScriptparameterRenderType,
generator: TypeScriptChannelsGeneratorInternal,
payloadRender: TypeScriptPayloadRenderType;
parameterRender: TypeScriptparameterRenderType;
generator: TypeScriptChannelsGeneratorInternal;
// All the rendered functions based on protocol.
renderedFunctions: Record<string, renderedFunctionType[]>
renderedFunctions: Record<string, renderedFunctionType[]>;
}

// eslint-disable-next-line sonarjs/cognitive-complexity
Expand All @@ -106,8 +106,12 @@ export async function generateTypeScriptChannels(
'Internal error, could not determine previous rendered outputs that is required for channel typescript generator'
);
}
const payloads = context.dependencyOutputs[generator.payloadGeneratorId] as TypeScriptPayloadRenderType;
const parameters = context.dependencyOutputs[generator.parameterGeneratorId] as TypeScriptparameterRenderType;
const payloads = context.dependencyOutputs[
generator.payloadGeneratorId
] as TypeScriptPayloadRenderType;
const parameters = context.dependencyOutputs[
generator.parameterGeneratorId
] as TypeScriptparameterRenderType;
if (!payloads) {
throw new Error(
'Internal error, could not determine previous rendered payloads generator that is required for channel TypeScript generator'
Expand All @@ -120,7 +124,10 @@ export async function generateTypeScriptChannels(
}

const protocolCodeFunctions: Record<string, string[]> = {};
const externalProtocolFunctionInformation: Record<string, renderedFunctionType[]> = {};
const externalProtocolFunctionInformation: Record<
string,
renderedFunctionType[]
> = {};
const protocolsToUse = generator.protocols;
for (const protocol of protocolsToUse) {
protocolCodeFunctions[protocol] = [];
Expand Down Expand Up @@ -209,10 +216,11 @@ export async function generateTypeScriptChannels(
externalProtocolFunctionInformation[protocol].push(
...renders.map((value) => {
return {
functionType: value.functionType as any,
functionType: value.functionType as any,
functionName: value.functionName,
messageType: payload.messageType,
parameterType: parameter !== undefined ? parameter.model.type : undefined
parameterType:
parameter !== undefined ? parameter.model.type : undefined
};
})
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable sonarjs/no-nested-template-literals */
import { ChannelFunctionTypes } from '../..';
import {ChannelFunctionTypes} from '../..';
import {SingleFunctionRenderType} from '../../../../../types';
import {pascalCase} from '../../../utils';
import {ConstrainedMetaModel, ConstrainedObjectModel} from '@asyncapi/modelina';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-nested-ternary */
import { ChannelFunctionTypes } from '../..';
import {ChannelFunctionTypes} from '../..';
import {SingleFunctionRenderType} from '../../../../../types';
import {findRegexFromChannel, pascalCase} from '../../../utils';
import {ConstrainedMetaModel, ConstrainedObjectModel} from '@asyncapi/modelina';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-nested-ternary */
import { ChannelFunctionTypes } from '../..';
import {ChannelFunctionTypes} from '../..';
import {SingleFunctionRenderType} from '../../../../../types';
import {pascalCase} from '../../../utils';
import {ConstrainedMetaModel, ConstrainedObjectModel} from '@asyncapi/modelina';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable sonarjs/no-nested-template-literals */
/* eslint-disable no-nested-ternary */
import { ChannelFunctionTypes } from '../..';
import {ChannelFunctionTypes} from '../..';
import {SingleFunctionRenderType} from '../../../../../types';
import {findRegexFromChannel, pascalCase} from '../../../utils';
import {ConstrainedMetaModel, ConstrainedObjectModel} from '@asyncapi/modelina';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {SingleFunctionRenderType} from '../../../../../types';
import {pascalCase} from '../../../utils';
import {ConstrainedMetaModel, ConstrainedObjectModel} from '@asyncapi/modelina';
import {ChannelFunctionTypes } from '../../index';
import {ChannelFunctionTypes} from '../../index';
export function renderJetstreamPublish({
topic,
message,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable sonarjs/no-nested-template-literals */
/* eslint-disable no-nested-ternary */
import { ChannelFunctionTypes } from '../..';
import {ChannelFunctionTypes} from '../..';
import {SingleFunctionRenderType} from '../../../../../types';
import {findRegexFromChannel, pascalCase} from '../../../utils';
import {ConstrainedMetaModel, ConstrainedObjectModel} from '@asyncapi/modelina';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable sonarjs/no-nested-template-literals */
/* eslint-disable no-nested-ternary */
import { ChannelFunctionTypes } from '../..';
import {ChannelFunctionTypes} from '../..';
import {SingleFunctionRenderType} from '../../../../../types';
import {findRegexFromChannel, pascalCase} from '../../../utils';
import {ConstrainedMetaModel, ConstrainedObjectModel} from '@asyncapi/modelina';
Expand Down
15 changes: 6 additions & 9 deletions src/codegen/generators/typescript/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import {AsyncAPIDocumentInterface} from '@asyncapi/parser';
import {mkdir, writeFile} from 'node:fs/promises';
import path from 'node:path';
import {z} from 'zod';
import { defaultTypeScriptChannelsGenerator } from '../channels';
import { generateNatsClient } from './protocols/nats';
import {defaultTypeScriptChannelsGenerator} from '../channels';
import {generateNatsClient} from './protocols/nats';
export type SupportedProtocols = 'nats';

export const zodTypescriptClientGenerator = z.object({
id: z.string().optional().default('client-typescript'),
dependencies: z
.array(z.string())
.optional()
.default(['channels-typescript']),
dependencies: z.array(z.string()).optional().default(['channels-typescript']),
preset: z.literal('client').default('client'),
outputPath: z.string().default('src/__gen__/clients'),
protocols: z.array(z.enum(['nats'])).default(['nats']),
Expand All @@ -25,7 +22,7 @@ export const zodTypescriptClientGenerator = z.object({
.describe(
'In case you have multiple TypeScript channels generators, you can specify which one to use as the dependency for this channels generator.'
)
.default('channels-typescript'),
.default('channels-typescript')
});

export type TypeScriptClientGenerator = z.input<
Expand Down Expand Up @@ -53,7 +50,7 @@ export async function generateTypeScriptClient(
}

await mkdir(context.generator.outputPath, {recursive: true});

for (const protocol of generator.protocols) {
switch (protocol) {
case 'nats':
Expand All @@ -62,7 +59,7 @@ export async function generateTypeScriptClient(
await generateNatsClient(context)
);
break;

default:
break;
}
Expand Down
Loading

0 comments on commit d961aa9

Please sign in to comment.