okai 0.0.19 → 0.0.22
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/dist/index.js +7 -6
- package/dist/tsd-gen.js +39 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -150,18 +150,19 @@ export async function cli(cmdArgs) {
|
|
150
150
|
if (command.unknown?.length) {
|
151
151
|
console.log(`Unknown Command: ${command.script} ${command.unknown.join(' ')}\n`);
|
152
152
|
}
|
153
|
+
const bin = script.padStart(7, ' ');
|
153
154
|
console.log(`Usage:
|
154
|
-
${
|
155
|
+
${bin} <prompt> Generate new TypeScript Data Models, C# APIs and Migrations from prompt
|
155
156
|
-m, -models <model,> Specify up to 5 LLM models to generate .d.ts Data Models
|
156
157
|
-l, -license <LC-xxx> Specify valid license certificate or key to use premium models
|
157
158
|
|
158
|
-
${
|
159
|
+
${bin} <models>.d.ts Regenerate C# *.cs files for Data Models defined in the TypeScript .d.ts file
|
159
160
|
-w, -watch Watch for changes to <models>.d.ts and regenerate *.cs on save
|
160
161
|
|
161
|
-
${
|
162
|
-
${
|
163
|
-
${
|
164
|
-
${
|
162
|
+
${bin} rm <models>.d.ts Remove <models>.d.ts and its generated *.cs files
|
163
|
+
${bin} ls models Display list of available premium LLM models
|
164
|
+
${bin} init Initialize okai.json with project info to override default paths
|
165
|
+
${bin} info Display current project info
|
165
166
|
|
166
167
|
Options:
|
167
168
|
-v, -verbose Display verbose logging
|
package/dist/tsd-gen.js
CHANGED
@@ -97,29 +97,50 @@ export class TsdGenerator {
|
|
97
97
|
}
|
98
98
|
}
|
99
99
|
export class TsdDataModelGenerator extends TsdGenerator {
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
100
|
+
duplicateTypePropMap = {
|
101
|
+
note: 'content',
|
102
|
+
};
|
103
|
+
convertType(type) {
|
104
|
+
type.name = toPascalCase(type.name);
|
105
|
+
type.properties?.forEach(prop => {
|
106
|
+
prop.name = toCamelCase(prop.name);
|
107
|
+
if (prop.type.startsWith('Array<')) {
|
108
|
+
const elType = prop.type.slice('Array<'.length, -1);
|
109
|
+
prop.type = elType + '[]';
|
110
|
+
}
|
111
|
+
if (prop.type === 'User') {
|
112
|
+
prop.name = 'userId';
|
113
|
+
prop.type = 'string';
|
114
|
+
}
|
115
|
+
if (prop.type === 'User[]') {
|
116
|
+
if (prop.name.endsWith('s')) {
|
117
|
+
prop.name = prop.name.slice(0, -1) + 'Ids';
|
113
118
|
}
|
114
|
-
|
119
|
+
prop.type = 'string[]';
|
120
|
+
}
|
121
|
+
});
|
122
|
+
this.rewriteDuplicateTypePropNames(type);
|
123
|
+
this.rewriteSelfReferencingIds(type);
|
124
|
+
}
|
125
|
+
rewriteDuplicateTypePropNames(type) {
|
126
|
+
const duplicateProp = type.properties?.find(x => toPascalCase(x.name) === type.name);
|
127
|
+
if (duplicateProp) {
|
128
|
+
const newName = this.duplicateTypePropMap[duplicateProp.name] ?? 'value';
|
129
|
+
duplicateProp.name = newName;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
rewriteSelfReferencingIds(type) {
|
133
|
+
const selfRefId = type.properties?.find(x => x.name.toLowerCase() === `${type.name}id`.toLowerCase());
|
134
|
+
if (selfRefId) {
|
135
|
+
selfRefId.name = `parentId`;
|
115
136
|
}
|
137
|
+
}
|
138
|
+
generate(ast) {
|
116
139
|
ast.classes?.forEach(cls => {
|
117
|
-
|
118
|
-
convertProps(cls.properties);
|
140
|
+
this.convertType(cls);
|
119
141
|
});
|
120
142
|
ast.interfaces?.forEach(cls => {
|
121
|
-
|
122
|
-
convertProps(cls.properties);
|
143
|
+
this.convertType(cls);
|
123
144
|
});
|
124
145
|
ast.enums?.forEach(e => {
|
125
146
|
e.name = toPascalCase(e.name);
|