okai 0.0.34 → 0.0.36

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 CHANGED
@@ -471,8 +471,10 @@ Options:
471
471
  }
472
472
  if (command.type === "prompt") {
473
473
  try {
474
- if (!info.serviceModelDir)
475
- throw new Error("Could not find ServiceModel directory");
474
+ if (!info.serviceModelDir) {
475
+ console.log("Could not find ServiceModel directory, ensure okai is run within the context of a ServiceStack App");
476
+ process.exit(1);
477
+ }
476
478
  console.log(`Generating new APIs and Tables for: ${command.prompt}...`);
477
479
  const gist = await fetchGistFiles(command);
478
480
  // const projectGist = convertToProjectGist(info, gist)
@@ -751,17 +753,7 @@ function chooseFile(ctx, info, gist, comamnd) {
751
753
  const apiTypesPath = path.join(info.slnDir, relativeServiceModelDir, `api.d.ts`);
752
754
  const apiFile = path.join(import.meta.dirname, 'api.d.ts');
753
755
  fs.writeFileSync(apiTypesPath, fs.readFileSync(apiFile, 'utf-8'));
754
- let uiFileName = null;
755
- if (info.uiMjsDir) {
756
- uiFileName = `${res.groupName}.mjs`;
757
- const uiGroupPath = path.join(info.uiMjsDir, uiFileName);
758
- const uiVueGen = new UiMjsGroupGenerator();
759
- const uiGroupSrc = uiVueGen.generate(res.csAst, res.groupName);
760
- fs.writeFileSync(uiGroupPath, uiGroupSrc);
761
- const uiIndexGen = new UiMjsIndexGenerator();
762
- const uiIndexSrc = uiIndexGen.generate(fs.readdirSync(info.uiMjsDir));
763
- fs.writeFileSync(path.join(info.uiMjsDir, `index.mjs`), uiIndexSrc);
764
- }
756
+ let uiFileName = info.uiMjsDir ? `${res.groupName}.mjs` : null;
765
757
  const tsdContent = createTsdFile(info, {
766
758
  prompt: titleBar.content.replaceAll('/*', '').replaceAll('*/', ''),
767
759
  apiFileName,
@@ -783,6 +775,18 @@ function chooseFile(ctx, info, gist, comamnd) {
783
775
  fs.writeFileSync(fullApiPath, apiContent, { encoding: 'utf-8' });
784
776
  console.log(`Saved: ${fullApiPath}`);
785
777
  }
778
+ if (info.uiMjsDir) {
779
+ const uiGroupPath = path.join(info.uiMjsDir, uiFileName);
780
+ const uiVueGen = new UiMjsGroupGenerator();
781
+ const uiGroupSrc = uiVueGen.generate(res.csAst, res.groupName);
782
+ fs.writeFileSync(uiGroupPath, uiGroupSrc);
783
+ console.log(`Saved: ${uiGroupPath}`);
784
+ const uiIndexGen = new UiMjsIndexGenerator();
785
+ const uiIndexSrc = uiIndexGen.generate(fs.readdirSync(info.uiMjsDir));
786
+ const uiIndexPath = path.join(info.uiMjsDir, `index.mjs`);
787
+ fs.writeFileSync(uiIndexPath, uiIndexSrc);
788
+ console.log(`Saved: ${uiIndexPath}`);
789
+ }
786
790
  if (fs.existsSync(path.dirname(fullMigrationPath))) {
787
791
  fs.writeFileSync(fullMigrationPath, migrationContent, { encoding: 'utf-8' });
788
792
  console.log(`Saved: ${fullMigrationPath}`);
package/dist/info.js CHANGED
@@ -136,6 +136,8 @@ export function parseUserDtoType(cs) {
136
136
  };
137
137
  }
138
138
  function walk(dir, fileList = [], opt) {
139
+ if (!dir)
140
+ return fileList;
139
141
  const files = fs.readdirSync(dir);
140
142
  for (const file of files) {
141
143
  const filePath = path.join(dir, file);
package/dist/ts-once.js CHANGED
@@ -7,6 +7,7 @@ export function createTdAstFromAIAst(tsAst, gropName) {
7
7
  replaceIds(tsAst);
8
8
  tsAst.classes.forEach(cls => {
9
9
  // replaceUserRefs(cls)
10
+ replaceUserBaseClass(cls);
10
11
  rewriteDuplicateTypePropNames(cls);
11
12
  rewriteSelfReferencingIds(cls);
12
13
  convertToAuditBase(cls);
@@ -86,6 +87,16 @@ export function transformUserRefs(tsAst, info) {
86
87
  tsAst.classes = tsAst.classes.filter(x => x.name !== 'User');
87
88
  }
88
89
  }
90
+ function replaceUserBaseClass(type) {
91
+ if (type.extends === 'User') {
92
+ type.extends = 'AuditBase';
93
+ let idProp = type.properties?.find(x => x.name.toLowerCase() === 'id');
94
+ if (!idProp) {
95
+ idProp = { name: 'id', type: 'number' };
96
+ type.properties?.unshift(idProp);
97
+ }
98
+ }
99
+ }
89
100
  function rewriteDuplicateTypePropNames(type) {
90
101
  const duplicateTypePropMap = {
91
102
  note: 'content',
@@ -111,8 +122,8 @@ export function addCustomInputs(cls) {
111
122
  if (!prop.annotations)
112
123
  prop.annotations = [];
113
124
  prop.annotations.push({
114
- name: "IntlNumber",
115
- args: { Currency: "NumberCurrency.USD" }
125
+ name: "intlNumber",
126
+ args: { currency: "USD" }
116
127
  });
117
128
  }
118
129
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "okai",
3
3
  "type": "module",
4
- "version": "0.0.34",
4
+ "version": "0.0.36",
5
5
  "bin": "./dist/okai.js",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",