vona-cli-set-api 1.0.61 → 1.0.63
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.
|
@@ -17,6 +17,7 @@ export interface IControllerOptionsPassport extends IDecoratorControllerOptions
|
|
|
17
17
|
@Controller<IControllerOptionsPassport>('passport')
|
|
18
18
|
export class ControllerPassport extends BeanBase {
|
|
19
19
|
@Web.get('current')
|
|
20
|
+
@Passport.public()
|
|
20
21
|
@Api.body(v.optional(), v.object(DtoPassport))
|
|
21
22
|
current(): DtoPassport | undefined {
|
|
22
23
|
return this._combineDtoPassport();
|
|
@@ -106,7 +107,7 @@ export class ControllerPassport extends BeanBase {
|
|
|
106
107
|
|
|
107
108
|
private _combineDtoPassport(): DtoPassport | undefined {
|
|
108
109
|
const passport = this.bean.passport.getCurrent();
|
|
109
|
-
if (!passport) return;
|
|
110
|
+
if (!passport || !passport.auth) return;
|
|
110
111
|
return {
|
|
111
112
|
user: passport.user as EntityUser,
|
|
112
113
|
auth: { id: passport.auth!.id },
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { metadataCustomSnippet } from '@cabloy/cli';
|
|
3
|
+
import { catchError } from '@cabloy/utils';
|
|
4
|
+
|
|
5
|
+
declare module '@cabloy/cli' {
|
|
6
|
+
interface ICommandArgv {
|
|
7
|
+
module: string;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const __snippet_import1 = 'import { $tableColumns } from \'vona-module-a-database\';\n';
|
|
12
|
+
const __snippet_import2 = 'import { Entity<%=argv.resourceNameCapitalize%> } from \'../entity/<%=argv.resourceName%>.ts\';\n';
|
|
13
|
+
const __snippet_update = `...$tableColumns(
|
|
14
|
+
() => Entity<%=argv.resourceNameCapitalize%>,
|
|
15
|
+
entity => entity.name,
|
|
16
|
+
),`;
|
|
17
|
+
|
|
18
|
+
export default metadataCustomSnippet({
|
|
19
|
+
file: 'src/bean/meta.index.ts',
|
|
20
|
+
language: 'plain',
|
|
21
|
+
init: async ({ cli, argv, targetFile }) => {
|
|
22
|
+
await catchError(() => {
|
|
23
|
+
return cli.helper.invokeCli([
|
|
24
|
+
':create:bean',
|
|
25
|
+
'meta',
|
|
26
|
+
'index',
|
|
27
|
+
`--module=${argv.module}`,
|
|
28
|
+
], { cwd: argv.projectPath });
|
|
29
|
+
});
|
|
30
|
+
return fs.readFileSync(targetFile).toString('utf8');
|
|
31
|
+
},
|
|
32
|
+
async transform({ cli, ast }) {
|
|
33
|
+
// import1
|
|
34
|
+
if (!ast.includes(__snippet_import1)) {
|
|
35
|
+
const code = await cli.template.renderContent({ content: __snippet_import1 });
|
|
36
|
+
ast = `${code}${ast}`;
|
|
37
|
+
}
|
|
38
|
+
// import2
|
|
39
|
+
let code = await cli.template.renderContent({ content: __snippet_import2 });
|
|
40
|
+
ast = `${code}${ast}`;
|
|
41
|
+
// update
|
|
42
|
+
code = await cli.template.renderContent({ content: __snippet_update });
|
|
43
|
+
ast = ast.replace('indexes: {', `indexes: {\n${code}`);
|
|
44
|
+
// ok
|
|
45
|
+
return ast;
|
|
46
|
+
},
|
|
47
|
+
});
|