voedger / kb

Knowledge base
0 stars 0 forks source link

howto: define command, query, projector and view #38

Open maxim-ge opened 10 months ago

maxim-ge commented 10 months ago

the following is actual for 2023.11.16

Commands & Queries

TYPE CreateLoginUnloggedParams ( Password text NOT NULL );

-- actually c.registrt.CreateLogin has no result, it is specified here for an example TYPE CreateLoginResult { Res text NOT NULL };

TYPE IssuePrincipalTokenParams ( Login text NOT NULL, Password text NOT NULL, AppName text NOT NULL );

TYPE IssuePrincipalTokenResult ( PrincipalToken text NOT NULL, WSID int64 NOT NULL, WSError text(1024) NOT NULL );

EXTENSION ENGINE BUILTIN ( COMMAND CreateLogin (CreateLoginParams, UNLOGGED CreateLoginUnloggedParams) RETURNS CreateLoginResult; QUERY InitiateResetPasswordByEmail (InitiateResetPasswordByEmailParams) RETURNS InitiateResetPasswordByEmailResult; );

### Go code
```golang
func Provide() {
    cfg.Resources.Add(istructsmem.NewCommandFunction(
        appdef.NewQName(RegistryPackage, "CreateLogin"),
        appdef.NullQName,
        appdef.NullQName,
        appdef.NullQName,
        execCmdCreateLogin,
    ))
    cfg.Resources.Add(istructsmem.NewQueryFunction(
        appdef.NewQName(RegistryPackage, "IssuePrincipalToken"),
        appdef.NullQName,
        appdef.NullQName,
        execQryIssuePrincipalToken(asp, itokens))
    )
}
func execCmdCreateLogin(args istructs.ExecCommandArgs) (err error) {
...
}
func execQryIssuePrincipalToken(ctx context.Context, args istructs.ExecQueryArgs, callback istructs.ExecQueryCallback) (err error) {
...
}

Views