okai 0.0.41 → 0.0.42

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/cs-ast.js CHANGED
@@ -15,7 +15,9 @@ export class CSharpAst {
15
15
  "undefined": sys("string"),
16
16
  "bigint": sys("long"),
17
17
  "any": sysObj,
18
+ "unknown": sysObj,
18
19
  "Record": sys("Dictionary"),
20
+ "Buffer": sys("byte[]"),
19
21
  "ArrayBuffer": sys("byte[]"),
20
22
  "SharedArrayBuffer": sys("byte[]"),
21
23
  "Int8Array": sys("sbyte[]"),
@@ -1028,7 +1030,7 @@ export function convertArraysToLists(gen) {
1028
1030
  for (const prop of type.properties) {
1029
1031
  const optional = prop.type.endsWith('?');
1030
1032
  let propType = unwrap(prop.type);
1031
- if (propType.endsWith('[]')) {
1033
+ if (propType.endsWith('[]') && propType !== 'byte[]') {
1032
1034
  const elType = propType.substring(0, propType.length - 2);
1033
1035
  prop.namespace = 'System.Collections.Generic';
1034
1036
  prop.genericArgs = [elType];
package/dist/icons.js CHANGED
@@ -155,6 +155,7 @@ export const IconMap = {
155
155
  Play: S(`0 0 24 24`, `<path fill='currentColor' d='M8 5.14v14l11-7z'/>`),
156
156
  Result: S(`0 0 2048 2048`, `<path fill='currentColor' d='M2048 640v640h-768v512H128v128H0V0h128v128h1408v512zM128 256v384h1280V256zm1024 1408v-384H128v384zm768-512V768H128v384z'/>`),
157
157
  Auction: S(`0 0 24 24`, `<path fill='currentColor' d='M14.005 20.003v2h-12v-2zM14.59.689l7.778 7.778l-1.414 1.414l-1.061-.353l-2.475 2.475l5.657 5.657l-1.414 1.414l-5.657-5.657l-2.404 2.404l.283 1.132l-1.415 1.414l-7.778-7.778l1.414-1.415l1.132.283l6.293-6.293l-.353-1.06zm.707 3.536l-7.071 7.07l3.535 3.536l7.071-7.07z'/>`),
158
+ Portfolio: S(`0 0 32 32`, `<path fill='currentColor' d='M28 10h-6V6a2 2 0 0 0-2-2h-8a2 2 0 0 0-2 2v4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h24a2 2 0 0 0 2-2V12a2 2 0 0 0-2-2M12 6h8v4h-8ZM4 26V12h24v14Z'/>`),
158
159
  /** CMS */
159
160
  Page: S('0 0 24 24', `<g fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5'><path d='M4 21.4V2.6a.6.6 0 0 1 .6-.6h11.652a.6.6 0 0 1 .424.176l3.148 3.148A.6.6 0 0 1 20 5.75V21.4a.6.6 0 0 1-.6.6H4.6a.6.6 0 0 1-.6-.6M8 10h8m-8 8h8m-8-4h4'/><path d='M16 2v3.4a.6.6 0 0 0 .6.6H20'/></g>`),
160
161
  Tag: S('0 0 24 24', `<g fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='2'><path d='M6.5 7.5a1 1 0 1 0 2 0a1 1 0 1 0-2 0'/><path d='M3 6v5.172a2 2 0 0 0 .586 1.414l7.71 7.71a2.41 2.41 0 0 0 3.408 0l5.592-5.592a2.41 2.41 0 0 0 0-3.408l-7.71-7.71A2 2 0 0 0 11.172 3H6a3 3 0 0 0-3 3'/></g>`),
@@ -175,6 +176,8 @@ export const IconMap = {
175
176
  News: S('0 0 20 20', `<path fill='currentColor' d='M3 6c0-1.1.9-2 2-2h8l4-4h2v16h-2l-4-4H5a2 2 0 0 1-2-2H1V6zm8 9v5H8l-1.67-5H5v-2h8v2z'/>`),
176
177
  Search: S('0 0 24 24', `<path fill='currentColor' d='m19.6 21l-6.3-6.3q-.75.6-1.725.95T9.5 16q-2.725 0-4.612-1.888T3 9.5t1.888-4.612T9.5 3t4.613 1.888T16 9.5q0 1.1-.35 2.075T14.7 13.3l6.3 6.3zM9.5 14q1.875 0 3.188-1.312T14 9.5t-1.312-3.187T9.5 5T6.313 6.313T5 9.5t1.313 3.188T9.5 14'/>`),
177
178
  Save: S('0 0 24 24', `<path fill='currentColor' d='M7 19v-6h10v6h2V7.828L16.172 5H5v14zM4 3h13l4 4v13a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1m5 12v4h6v-4z'/>`),
179
+ Link: S('0 0 24 24', `<path fill='currentColor' d='M11 17H7q-2.075 0-3.537-1.463T2 12t1.463-3.537T7 7h4v2H7q-1.25 0-2.125.875T4 12t.875 2.125T7 15h4zm-3-4v-2h8v2zm5 4v-2h4q1.25 0 2.125-.875T20 12t-.875-2.125T17 9h-4V7h4q2.075 0 3.538 1.463T22 12t-1.463 3.538T17 17z'/>`),
180
+ Translate: S('0 0 24 24', `<path fill='currentColor' d='m11.9 22l4.55-12h2.1l4.55 12H21l-1.075-3.05h-4.85L14 22zM4 19l-1.4-1.4l5.05-5.05q-.875-.875-1.588-2T4.75 8h2.1q.5.975 1 1.7t1.2 1.45q.825-.825 1.713-2.313T12.1 6H1V4h7V2h2v2h7v2h-2.9q-.525 1.8-1.575 3.7t-2.075 2.9l2.4 2.45l-.75 2.05l-3.05-3.125zm11.7-1.8h3.6l-1.8-5.1z'/>`),
178
181
  /** Formatting */
179
182
  PlainText: S(`0 0 256 256`, `<path fill='currentColor' d='M212 56v32a12 12 0 0 1-24 0V68h-48v120h20a12 12 0 0 1 0 24H96a12 12 0 0 1 0-24h20V68H68v20a12 12 0 0 1-24 0V56a12 12 0 0 1 12-12h144a12 12 0 0 1 12 12Z'/>`),
180
183
  Markup: S(`0 0 24 24`, `<path fill='currentColor' d='M10 20q-.425 0-.713-.288T9 19v-5q-2.075 0-3.538-1.463T4 9q0-2.075 1.463-3.538T9 4h8q.425 0 .713.288T18 5q0 .425-.288.713T17 6h-1v13q0 .425-.288.713T15 20q-.425 0-.713-.288T14 19V6h-3v13q0 .425-.288.713T10 20Z'/>`),
@@ -184,17 +187,26 @@ export const IconMap = {
184
187
  Alert: S(`0 0 24 24`, `<path fill='currentColor' d='M12 2L1 21h22M12 6l7.53 13H4.47M11 10v4h2v-4m-2 6v2h2v-2'/>`),
185
188
  Data: S(`0 0 24 24`, `<path fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M18 12v5c0 1.657-2.686 3-6 3s-6-1.343-6-3v-5m12 0V7m0 5c0 1.657-2.686 3-6 3s-6-1.343-6-3m12-5c0-1.657-2.686-3-6-3S6 5.343 6 7m12 0c0 1.657-2.686 3-6 3S6 8.657 6 7m0 5V7'/>`),
186
189
  Tool: S(`0 0 24 24`, `<path fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M7 10h3V7L6.5 3.5a6 6 0 0 1 8 8l6 6a2 2 0 0 1-3 3l-6-6a6 6 0 0 1-8-8z'/>`),
190
+ Output: S('0 0 24 24', `<path fill='currentColor' d='m23 12l-4-4v3h-9v2h9v3M1 18V6a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v3h-2V6H3v12h12v-3h2v3a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2'/>`),
191
+ Instrument: S('0 0 24 24', `<path fill='currentColor' d='M11.5 2h-1v4.2c-.1.1-.2.1-.3.3L2.1 20.7c-.3.6.1 1.3.8 1.3H16v-2H4.8L11 9.2l5.7 10l1.7-1l-6.6-11.8l-.3-.3zM21 6h-1v12l-.5 4h2l-.5-4z'/>`),
187
192
  Chip: S('0 0 512 512', `<rect width='352' height='352' x='80' y='80' fill='none' stroke='currentColor' stroke-linejoin='round' stroke-width='32' rx='48' ry='48'/><rect width='224' height='224' x='144' y='144' fill='none' stroke='currentColor' stroke-linejoin='round' stroke-width='32' rx='16' ry='16'/><path fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='32' d='M256 80V48m80 32V48M176 80V48m80 416v-32m80 32v-32m-160 32v-32m256-176h32m-32 80h32m-32-160h32M48 256h32m-32 80h32M48 176h32'/>`),
193
+ /** Things */
194
+ Sport: S(`0 0 24 24`, `<path fill='currentColor' d='M4 6c0-1.1.9-2 2-2s2 .9 2 2s-.9 2-2 2s-2-.9-2-2M1 9h6l7-5l1.31 1.52l-4.17 2.98H14L21.8 4L23 5.4L14.5 12L14 22h-2l-.5-10L8 11H1z'/>`),
195
+ Help: S(`0 0 24 24`, `<path fill='currentColor' d='M12 4c4.411 0 8 3.589 8 8s-3.589 8-8 8s-8-3.589-8-8s3.589-8 8-8m0-2C6.477 2 2 6.477 2 12s4.477 10 10 10s10-4.477 10-10S17.523 2 12 2m4 8a4 4 0 0 0-8 0h2c0-1.103.897-2 2-2s2 .897 2 2s-.897 2-2 2a1 1 0 0 0-1 1v2h2v-1.141A3.99 3.99 0 0 0 16 10m-3 6h-2v2h2z'/>`),
196
+ Watch: S(`0 0 24 24`, `<path fill='currentColor' d='M11 6h2v7h-2zM9 20a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-5l2-9h4v7a1 1 0 0 1-1 1zm1-15H7V3h3zm5 15v-6a1 1 0 0 1-1-1V6h4l2 9v5a1 1 0 0 1-1 1h-3a1 1 0 0 1-1-1M14 5V3h3v2z'/>`),
197
+ Food: S(`0 0 24 24`, `<path fill='currentColor' d='M18.06 23h1.66c.84 0 1.53-.65 1.63-1.47L23 5.05h-5V1h-1.97v4.05h-4.97l.3 2.34c1.71.47 3.31 1.32 4.27 2.26c1.44 1.42 2.43 2.89 2.43 5.29zM1 22v-1h15.03v1c0 .54-.45 1-1.03 1H2c-.55 0-1-.46-1-1m15.03-7C16.03 7 1 7 1 15zM1 17h15v2H1z'/>`),
198
+ Animal: S(`0 0 20 20`, `<path fill='currentColor' d='M5.5 4.25c0-1.168.826-2.25 2-2.25s2 1.082 2 2.25s-.826 2.25-2 2.25s-2-1.082-2-2.25M3 4.5c-1.174 0-2 1.082-2 2.25S1.826 9 3 9s2-1.082 2-2.25S4.174 4.5 3 4.5m12 2.25c0-1.168.826-2.25 2-2.25s2 1.082 2 2.25S18.174 9 17 9s-2-1.082-2-2.25m-4.5-2.5c0-1.168.826-2.25 2-2.25s2 1.082 2 2.25s-.826 2.25-2 2.25s-2-1.082-2-2.25M4 14a6 6 0 0 1 12 0c0 .986-.504 1.753-1.21 2.255c-.697.495-1.601.745-2.485.745h-4.61c-.884 0-1.788-.25-2.484-.745C4.504 15.753 4 14.986 4 14'/>`),
199
+ Mix: S(`0 0 512 512`, `<path fill='currentColor' fill-rule='evenodd' d='m269.264 271.083l70.256 70.25l56.966-.001l-27.57-27.58l30.17-30.17l79.084 79.084l-79.085 79.085l-30.17-30.17L396.487 384H321.83l-82.745-82.74zM399.085 70.248l79.085 79.085l-79.085 79.085l-30.17-30.17l27.572-27.582H339.52L126.17 384H42.667v-42.667h65.813L321.83 128l74.657-.001l-27.572-27.581zM126.17 128l82.745 82.739l-30.179 30.177l-70.256-70.25H42.667V128z'/>`),
188
200
  /** Actions */
189
201
  Completed: S(`0 0 2048 2048`, `<path fill='currentColor' d='M1024 0q141 0 272 36t244 104t207 160t161 207t103 245t37 272q0 141-36 272t-104 244t-160 207t-207 161t-245 103t-272 37q-141 0-272-36t-244-104t-207-160t-161-207t-103-245t-37-272q0-141 36-272t104-244t160-207t207-161T752 37t272-37m603 685l-136-136l-659 659l-275-275l-136 136l411 411z'/>`),
190
202
  Failed: S(`0 0 2048 2048`, `<path fill='currentColor' d='M1024 0q141 0 272 36t244 104t207 160t161 207t103 245t37 272q0 141-36 272t-104 244t-160 207t-207 161t-245 103t-272 37q-141 0-272-36t-244-104t-207-160t-161-207t-103-245t-37-272q0-141 36-272t104-244t160-207t207-161T752 37t272-37m113 1024l342-342l-113-113l-342 342l-342-342l-113 113l342 342l-342 342l113 113l342-342l342 342l113-113z'/>`),
191
203
  };
192
204
  export const IconGroups = {
193
205
  User: ['AppUser', 'Author'],
194
- Contact: ['Customer', 'Client', 'Employee', 'Applicant', 'Candidate', 'Staff'],
206
+ Contact: ['Customer', 'Client', 'Manager', 'Employee', 'Applicant', 'Candidate', 'Staff'],
195
207
  Company: ['Organization', 'Conference', 'City'],
196
208
  Account: ['Profile'],
197
- Team: ['Collab', 'Collaboration'],
209
+ Team: ['Collab', 'Collaboration', 'Role'],
198
210
  Region: ['Country', 'State', 'Province', 'Capital'],
199
211
  Lock: ['Security', 'Padlock', 'Secure'],
200
212
  Location: ['Address', 'JobLocation'],
@@ -206,11 +218,12 @@ export const IconGroups = {
206
218
  Check: ['Require'],
207
219
  Screening: ['PhoneScreen'],
208
220
  Artifact: ['Media'],
221
+ Booking: ['Appointment', 'Reservation', 'Schedule'],
209
222
  Product: ['Sku', 'Item', 'Restock', 'Stock'],
210
223
  Order: ['Invoice'],
211
224
  LineItem: ['InvoiceItem'],
212
225
  Opportunity: ['Lead', 'Deal'],
213
- Connect: ['Interaction'],
226
+ Connect: ['Interaction', 'Api'],
214
227
  Conversion: ['Convert'],
215
228
  Expense: ['Cost', 'Price', 'Amount', 'Salary'],
216
229
  Approve: ['Approval'],
@@ -233,18 +246,18 @@ export const IconGroups = {
233
246
  Actual: ['Request'],
234
247
  Pay: ['Paystub'],
235
248
  Post: ['Posting'],
236
- Content: ['Website', 'Blog', 'Template', 'LandingPage', 'Portal', 'Workspace'],
237
- Menu: ['Nav', 'Form', 'MenuList'],
249
+ Content: ['Website', 'Blog', 'Template', 'LandingPage', 'Portal', 'Workspace', 'Layout'],
250
+ Menu: ['Nav', 'Form', 'MenuList', 'Section'],
238
251
  Skill: ['Qualification', 'Certification', 'Experience', 'Training', 'Requirement', 'Bid'],
239
- Analytics: ['Level', 'Metric', 'Kpi', 'Goal', 'Objective'],
252
+ Analytics: ['Level', 'Metric', 'Kpi', 'Goal', 'Objective', 'Chart', 'Finance', 'Analysis'],
240
253
  Review: ['Audit', 'Status'],
241
254
  Comment: ['Feedback'],
242
255
  Vote: ['Rating', 'Rank', 'Score', 'Priority'],
243
256
  Favorite: ['Bookmark', 'Star'],
244
- Logs: ['Detail', 'Details', 'History', 'Log', 'Record', 'Journal', 'Entry', 'Transaction'],
257
+ Logs: ['Detail', 'Details', 'History', 'Log', 'Record', 'Journal', 'Entry', 'Transaction', 'Trace'],
245
258
  PlainText: ['Field'],
246
259
  Ship: ['Shipment'],
247
- Setting: ['Adjustment', 'Configuration', 'Setup'],
260
+ Setting: ['Adjustment', 'Config', 'Configuration', 'Setup', 'Option'],
248
261
  Activity: ['Movement'],
249
262
  Attachment: ['File'],
250
263
  News: ['Announcement'],
@@ -253,6 +266,13 @@ export const IconGroups = {
253
266
  Search: ['Filter', 'Lookup', 'Query', 'Match'],
254
267
  Save: ['Saved', 'Archive', 'Backup', 'Download', 'Export'],
255
268
  Chip: ['Hardware'],
269
+ Output: ['Response'],
270
+ Range: ['Span', 'Exchange'],
271
+ Translate: ['Translation', 'Localization', 'Language'],
272
+ Portfolio: ['Holding'],
273
+ Tool: ['Maintenance', 'Support'],
274
+ Watch: ['Sight', 'Sighting', 'View', 'Watchlist'],
275
+ Animal: ['Wildlife', 'Pet', 'Zoo'],
256
276
  };
257
277
  export const Icons = withAliases(IconMap, IconGroups);
258
278
  const IconKeys = Object.keys(Icons).sort((a, b) => b.length - a.length);
package/dist/ts-ast.js CHANGED
@@ -22,7 +22,7 @@ export function toAst(src) {
22
22
  const parser = new TypeScriptParser();
23
23
  return parser.parse(src);
24
24
  }
25
- // Tranforms that are only applied once on AI TypeScript AST
25
+ // Transforms that are only applied once on AI TypeScript AST
26
26
  export function createAstFromAITypeScript(ts) {
27
27
  const parser = new TypeScriptParser();
28
28
  const tdAst = parser.parse(ts);
package/dist/ts-once.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { pick, splitCase, toCamelCase, toPascalCase } from "./utils.js";
2
- // Tranforms that are only applied once on AI TypeScript AST
3
- export function createTdAstFromAIAst(tsAst, gropName) {
2
+ // Transforms that are only applied once on AI TypeScript AST
3
+ export function createTdAstFromAIAst(tsAst, groupName) {
4
+ rewriteInterfaceNames(tsAst);
4
5
  mergeInterfacesAndClasses(tsAst);
5
6
  rewriteToPascalCase(tsAst);
6
7
  replaceReferences(tsAst);
@@ -10,14 +11,15 @@ export function createTdAstFromAIAst(tsAst, gropName) {
10
11
  // replaceUserRefs(cls)
11
12
  replaceUserBaseClass(cls);
12
13
  rewriteDuplicateTypePropNames(cls);
14
+ removeDuplicateProps(cls);
13
15
  rewriteSelfReferencingIds(cls);
14
16
  convertToAuditBase(cls);
15
17
  addCustomInputs(cls);
16
- if (gropName) {
18
+ if (groupName) {
17
19
  if (!cls.annotations)
18
20
  cls.annotations = [];
19
21
  if (!cls.annotations.some(x => x.name === 'tag')) {
20
- cls.annotations.push({ name: 'tag', constructorArgs: [gropName] });
22
+ cls.annotations.push({ name: 'tag', constructorArgs: [groupName] });
21
23
  }
22
24
  }
23
25
  });
@@ -140,6 +142,19 @@ function rewriteDuplicateTypePropNames(type) {
140
142
  duplicateProp.name = newName;
141
143
  }
142
144
  }
145
+ function removeDuplicateProps(type) {
146
+ const propNames = type.properties?.map(x => x.name) ?? [];
147
+ const duplicateProps = type.properties?.filter(x => propNames.filter(y => y === x.name).length > 1);
148
+ if (duplicateProps) {
149
+ const props = [];
150
+ for (const prop of type.properties) {
151
+ if (!props.find(x => x.name === prop.name)) {
152
+ props.push(prop);
153
+ }
154
+ }
155
+ type.properties = props;
156
+ }
157
+ }
143
158
  function rewriteSelfReferencingIds(type) {
144
159
  const selfRefId = type.properties?.find(x => x.name.toLowerCase() === `${type.name}id`.toLowerCase());
145
160
  if (selfRefId) {
@@ -177,6 +192,29 @@ function rewriteToPascalCase(ast) {
177
192
  }
178
193
  });
179
194
  }
195
+ function rewriteInterfaceNames(ast) {
196
+ const renameTypes = {};
197
+ ast.interfaces?.forEach(t => {
198
+ const hasIPrefix = t.name.startsWith('I')
199
+ && t.name[1].toUpperCase() === t.name[1]
200
+ && t.name[2].toLowerCase() === t.name[2];
201
+ if (hasIPrefix) {
202
+ renameTypes[t.name] = t.name.substring(1);
203
+ renameTypes[t.name + '[]'] = t.name.substring(1) + '[]';
204
+ t.name = t.name.substring(1);
205
+ }
206
+ });
207
+ ast.classes?.concat(ast.interfaces || []).forEach(t => {
208
+ if (renameTypes[t.extends]) {
209
+ t.extends = renameTypes[t.extends];
210
+ }
211
+ t.properties?.forEach(p => {
212
+ if (renameTypes[p.type]) {
213
+ p.type = renameTypes[p.type];
214
+ }
215
+ });
216
+ });
217
+ }
180
218
  function convertToAuditBase(cls) {
181
219
  const props = cls.properties ?? [];
182
220
  const auditFields = ['createdBy', 'updatedBy', 'createdAt', 'updatedAt', 'userId'];
package/dist/ts-parser.js CHANGED
@@ -6,7 +6,7 @@ export class TypeScriptParser {
6
6
  static CLASS_PATTERN = /class\s+(\w+)(?:\s+extends\s+([\w\s<>,]+))?(?:\s+implements\s+([\w\s<>,]+))?\s*{/gm;
7
7
  static INTERFACE_PATTERN = /interface\s+(\w+)(?:\s+extends\s+([\w\s<>,]+))?\s*{/gm;
8
8
  static ENUM_PATTERN = /enum\s+(\w+)\s*{([^}]*)}/gm;
9
- static PROPERTY_PATTERN = /(?:(?<modifier>private|public|protected|readonly)\s+)*(?<name>\w+)(?<optional>\?)?\s*:\s*(?<type>['"\w<>|[\],\s]+)?\s*;?/;
9
+ static PROPERTY_PATTERN = /(?:(?<modifier>private|public|protected|readonly)\s+)*(?<name>\w+)(?<optional>\?)?\s*:\s*(?<type>['"\w<>|[\]{}:,\s]+)?\s*;?/;
10
10
  static ENUM_MEMBER_PATTERN = /(\w+)\s*(?:=\s*("[^"]*"|'[^']*'|\d+|[^,\n]+))?\s*/;
11
11
  static ANNOTATION_PATTERN = /^\s*@([A-Za-z_][A-Za-z0-9_]*\.?[A-Za-z_]?[A-Za-z0-9_]*)/;
12
12
  static ANNOTATION_COMMENT = /\)[\s]*\/\/.*$/;
@@ -89,7 +89,7 @@ export class TypeScriptParser {
89
89
  }
90
90
  parseMetadata(body, line) {
91
91
  const annotations = [];
92
- const commments = [];
92
+ const comments = [];
93
93
  const ANNOTATION = TypeScriptParser.ANNOTATION_PATTERN;
94
94
  let previousLine = this.getPreviousLine(body, body.lastIndexOf(line));
95
95
  while (previousLine && (!previousLine.match(TypeScriptParser.PROPERTY_PATTERN) || previousLine.match(ANNOTATION))) {
@@ -100,14 +100,14 @@ export class TypeScriptParser {
100
100
  else {
101
101
  const comment = this.isComment(previousLine) ? this.getLineComment(previousLine) : null;
102
102
  if (comment) {
103
- commments.unshift(comment);
103
+ comments.unshift(comment);
104
104
  }
105
105
  }
106
106
  previousLine = this.getPreviousLine(body, body.lastIndexOf(previousLine));
107
107
  }
108
108
  const lineComment = this.getLineComment(line);
109
109
  if (lineComment) {
110
- commments.push(lineComment);
110
+ comments.push(lineComment);
111
111
  }
112
112
  else if (line.match(ANNOTATION)) {
113
113
  const annotation = parseAnnotation(line);
@@ -116,7 +116,7 @@ export class TypeScriptParser {
116
116
  }
117
117
  }
118
118
  const ret = {
119
- comment: commments.length ? commments.join('\n') : undefined,
119
+ comment: comments.length ? comments.join('\n') : undefined,
120
120
  annotations: annotations.length ? annotations : undefined,
121
121
  };
122
122
  return ret;
@@ -131,9 +131,21 @@ export class TypeScriptParser {
131
131
  return;
132
132
  const match = line.match(TypeScriptParser.PROPERTY_PATTERN);
133
133
  if (match?.groups) {
134
+ let type = match.groups.type?.trim();
135
+ const matchRecord = line.includes('{') ? line.match(/{\s*\[\s*\w+:\s*(\w+)\s*\]\s*:\s*(\w+)\s*;?\s*}/) : null;
136
+ if (matchRecord) {
137
+ // parse record: { [key: string]: string; }
138
+ const keyType = matchRecord[1];
139
+ const valType = leftPart(matchRecord[2], '|').trim();
140
+ type = `Record<${keyType},${valType}>`;
141
+ }
142
+ if (!type) {
143
+ console.log(`Failed to parse property type: ${line}`);
144
+ return;
145
+ }
134
146
  const member = {
135
147
  name: match.groups.name,
136
- type: match.groups.type.trim(),
148
+ type,
137
149
  };
138
150
  if (match.groups.modifier)
139
151
  member.modifier = match.groups.modifier;
package/dist/tsd-gen.js CHANGED
@@ -43,6 +43,9 @@ export class TsdGenerator {
43
43
  }
44
44
  toType(ast, type) {
45
45
  const sb = [];
46
+ if (ast.name === 'User') {
47
+ sb.push('/*: Merge with User DTO');
48
+ }
46
49
  if (ast.comment) {
47
50
  sb.push(ast.comment.split('\n').map(x => `// ${x}`).join('\n'));
48
51
  }
@@ -66,6 +69,9 @@ export class TsdGenerator {
66
69
  sb.push(` ${prop.name}${prop.optional ? '?' : ''}: ${prop.type}`);
67
70
  }
68
71
  sb.push('}');
72
+ if (ast.name === 'User') {
73
+ sb.push('*/');
74
+ }
69
75
  return sb.join('\n');
70
76
  }
71
77
  toEnum(ast) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "okai",
3
3
  "type": "module",
4
- "version": "0.0.41",
4
+ "version": "0.0.42",
5
5
  "bin": "./dist/okai.js",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",