修改了大量的类型定义,增加了token的feature
This commit is contained in:
parent
96bf35ffb9
commit
75d7c73f76
|
|
@ -1,13 +1,17 @@
|
|||
import { Context } from 'oak-domain/lib/types';
|
||||
import { UniversalContext } from 'oak-domain/lib/store/UniversalContext';
|
||||
import { EntityDict } from 'oak-app-domain/EntityDict';
|
||||
import { RowStore } from 'oak-domain/lib/types';
|
||||
export declare class GeneralRuntimeContext<ED extends EntityDict> extends UniversalContext<ED> implements Context<ED> {
|
||||
export declare abstract class GeneralRuntimeContext<ED extends EntityDict> extends UniversalContext<ED> {
|
||||
applicationId: string;
|
||||
constructor(store: RowStore<ED>, appId: string);
|
||||
token?: string;
|
||||
constructor(store: RowStore<ED, GeneralRuntimeContext<ED>>, appId: string, token?: string);
|
||||
getApplication(): Promise<import("oak-domain/lib/types").SelectRowShape<ED["application"]["Schema"], {
|
||||
id: 1;
|
||||
name: 1;
|
||||
}>>;
|
||||
getToken(): void;
|
||||
getToken(): Promise<import("oak-domain/lib/types").SelectRowShape<ED["token"]["Schema"], {
|
||||
id: 1;
|
||||
userId: 1;
|
||||
playerId: 1;
|
||||
}> | undefined>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@ exports.GeneralRuntimeContext = void 0;
|
|||
const UniversalContext_1 = require("oak-domain/lib/store/UniversalContext");
|
||||
class GeneralRuntimeContext extends UniversalContext_1.UniversalContext {
|
||||
applicationId;
|
||||
constructor(store, appId) {
|
||||
token;
|
||||
constructor(store, appId, token) {
|
||||
super(store);
|
||||
this.applicationId = appId;
|
||||
this.token = token;
|
||||
}
|
||||
async getApplication() {
|
||||
const { result: [application] } = await this.rowStore.select('application', {
|
||||
|
|
@ -20,7 +22,21 @@ class GeneralRuntimeContext extends UniversalContext_1.UniversalContext {
|
|||
}, this);
|
||||
return application;
|
||||
}
|
||||
getToken() {
|
||||
async getToken() {
|
||||
if (this.token) {
|
||||
const { result: [token] } = await this.rowStore.select('token', {
|
||||
data: {
|
||||
id: 1,
|
||||
userId: 1,
|
||||
playerId: 1,
|
||||
},
|
||||
filter: {
|
||||
id: this.token,
|
||||
ableState: 'enabled',
|
||||
}
|
||||
}, this);
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.GeneralRuntimeContext = GeneralRuntimeContext;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { loginByPassword, loginMp } from './token';
|
||||
declare const aspectDict: {
|
||||
export declare const aspectDict: {
|
||||
loginByPassword: typeof loginByPassword;
|
||||
loginMp: typeof loginMp;
|
||||
};
|
||||
export default aspectDict;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.aspectDict = void 0;
|
||||
const token_1 = require("./token");
|
||||
const aspectDict = {
|
||||
exports.aspectDict = {
|
||||
loginByPassword: token_1.loginByPassword,
|
||||
loginMp: token_1.loginMp,
|
||||
};
|
||||
exports.default = aspectDict;
|
||||
// export type AspectDict<ED extends EntityDict & BaseEntityDict> = TokenAD<ED> & CrudAD<ED>;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { GeneralRuntimeContext } from '../RuntimeContext';
|
||||
import { EntityDict } from 'oak-app-domain/EntityDict';
|
||||
export declare function loginMp<ED extends EntityDict>(params: {
|
||||
export declare function loginMp<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>>(params: {
|
||||
code: string;
|
||||
}, context: GeneralRuntimeContext<ED>): Promise<string>;
|
||||
export declare function loginByPassword<ED extends EntityDict>(params: {
|
||||
}, context: Cxt): Promise<string>;
|
||||
export declare function loginByPassword<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>>(params: {
|
||||
password: string;
|
||||
mobile: string;
|
||||
}, context: GeneralRuntimeContext<ED>): Promise<string>;
|
||||
}, context: Cxt): Promise<string>;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { Checker } from "oak-domain/lib/types";
|
||||
import { EntityDict } from 'oak-app-domain/EntityDict';
|
||||
declare const checkers: Checker<EntityDict, 'address'>[];
|
||||
import { GeneralRuntimeContext } from '../RuntimeContext';
|
||||
declare const checkers: Checker<EntityDict, 'address', GeneralRuntimeContext<EntityDict>>[];
|
||||
export default checkers;
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
declare const _default: import("oak-domain/lib/types").Checker<import("oak-app-domain").EntityDict, "address">[];
|
||||
declare const _default: import("oak-domain/lib/types").Checker<import("oak-app-domain").EntityDict, "address", import("..").GeneralRuntimeContext<import("oak-app-domain").EntityDict>>[];
|
||||
export default _default;
|
||||
|
|
|
|||
|
|
@ -2,10 +2,26 @@ import { String, Text } from 'oak-domain/lib/types/DataType';
|
|||
import { EntityShape } from 'oak-domain/lib/types/Entity';
|
||||
import { Schema as System } from './System';
|
||||
import { Schema as ExtraFile } from './ExtraFile';
|
||||
declare type WechatMpConfig = {
|
||||
type: 'wechatMp';
|
||||
appId: string;
|
||||
appSecret: string;
|
||||
};
|
||||
declare type WebConfig = {
|
||||
type: 'web';
|
||||
domain: string;
|
||||
};
|
||||
declare type WechatPublicCofig = {
|
||||
type: 'wechatPublic';
|
||||
appId: string;
|
||||
appSecret: string;
|
||||
};
|
||||
export interface Schema extends EntityShape {
|
||||
name: String<32>;
|
||||
description: Text;
|
||||
type: 'web' | 'wechatPublic' | 'weChatMp';
|
||||
system: System;
|
||||
dd: Array<ExtraFile>;
|
||||
config: WebConfig | WechatMpConfig | WechatPublicCofig;
|
||||
}
|
||||
export {};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
import { Token } from './token';
|
||||
export declare function initialize(): {
|
||||
token: Token;
|
||||
};
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initialize = void 0;
|
||||
const token_1 = require("./token");
|
||||
function initialize() {
|
||||
const token = new token_1.Token();
|
||||
return {
|
||||
token,
|
||||
};
|
||||
}
|
||||
exports.initialize = initialize;
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
import { EntityDict } from 'oak-app-domain';
|
||||
import { GeneralRuntimeContext } from '../RuntimeContext';
|
||||
import { aspectDict } from '../aspects';
|
||||
import { Feature } from 'oak-frontend-base';
|
||||
export declare class Token extends Feature<EntityDict, GeneralRuntimeContext<EntityDict>, typeof aspectDict> {
|
||||
private token?;
|
||||
loginByPassword(mobile: string, password: string): Promise<void>;
|
||||
logout(): Promise<void>;
|
||||
getToken(): string | undefined;
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Token = void 0;
|
||||
const oak_frontend_base_1 = require("oak-frontend-base");
|
||||
class Token extends oak_frontend_base_1.Feature {
|
||||
token;
|
||||
async loginByPassword(mobile, password) {
|
||||
this.token = await this.getAspectProxy().loginByPassword({ password, mobile });
|
||||
}
|
||||
async logout() {
|
||||
this.token = undefined;
|
||||
}
|
||||
getToken() {
|
||||
return this.token;
|
||||
}
|
||||
}
|
||||
__decorate([
|
||||
oak_frontend_base_1.Action
|
||||
], Token.prototype, "loginByPassword", null);
|
||||
__decorate([
|
||||
oak_frontend_base_1.Action
|
||||
], Token.prototype, "logout", null);
|
||||
exports.Token = Token;
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import aspectDict from "./aspects";
|
||||
import { aspectDict } from "./aspects";
|
||||
import triggers from "./triggers";
|
||||
import checkers from './checkers';
|
||||
import data from "./data";
|
||||
export { checkers, triggers, data, aspectDict, };
|
||||
import { initialize as initializeFeatures } from './features';
|
||||
export { checkers, triggers, data, aspectDict, initializeFeatures, };
|
||||
export * from './RuntimeContext';
|
||||
|
|
|
|||
|
|
@ -17,14 +17,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.aspectDict = exports.data = exports.triggers = exports.checkers = void 0;
|
||||
exports.initializeFeatures = exports.aspectDict = exports.data = exports.triggers = exports.checkers = void 0;
|
||||
// import './typings/polyfill';
|
||||
const aspects_1 = __importDefault(require("./aspects"));
|
||||
exports.aspectDict = aspects_1.default /* , { AspectDict } */;
|
||||
const aspects_1 = require("./aspects");
|
||||
Object.defineProperty(exports, "aspectDict", { enumerable: true, get: function () { return aspects_1.aspectDict; } });
|
||||
const triggers_1 = __importDefault(require("./triggers"));
|
||||
exports.triggers = triggers_1.default;
|
||||
const checkers_1 = __importDefault(require("./checkers"));
|
||||
exports.checkers = checkers_1.default;
|
||||
const data_1 = __importDefault(require("./data"));
|
||||
exports.data = data_1.default;
|
||||
const features_1 = require("./features");
|
||||
Object.defineProperty(exports, "initializeFeatures", { enumerable: true, get: function () { return features_1.initialize; } });
|
||||
__exportStar(require("./RuntimeContext"), exports);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { Trigger } from 'oak-domain/lib/types/Trigger';
|
||||
import { EntityDict } from 'oak-app-domain/EntityDict';
|
||||
declare const triggers: Trigger<EntityDict, 'address'>[];
|
||||
import { GeneralRuntimeContext } from '../RuntimeContext';
|
||||
declare const triggers: Trigger<EntityDict, 'address', GeneralRuntimeContext<EntityDict>>[];
|
||||
export default triggers;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { EntityDict as BaseEntityDict } from 'oak-app-domain/EntityDict';
|
||||
import { Trigger } from 'oak-domain/lib/types';
|
||||
declare const _default: Trigger<BaseEntityDict, "address">[];
|
||||
declare const _default: Trigger<BaseEntityDict, "address", import("..").GeneralRuntimeContext<BaseEntityDict>>[];
|
||||
export default _default;
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
|
||||
import { Context, SelectionResult } from 'oak-domain/lib/types';
|
||||
import { SelectionResult } from 'oak-domain/lib/types';
|
||||
import { UniversalContext } from 'oak-domain/lib/store/UniversalContext';
|
||||
import { EntityDict } from 'oak-app-domain/EntityDict';
|
||||
import { RowStore } from 'oak-domain/lib/types';
|
||||
|
||||
|
||||
export class GeneralRuntimeContext<ED extends EntityDict> extends UniversalContext<ED> implements Context<ED> {
|
||||
export abstract class GeneralRuntimeContext<ED extends EntityDict> extends UniversalContext<ED> {
|
||||
applicationId: string;
|
||||
constructor(store: RowStore<ED>, appId: string) {
|
||||
token?: string;
|
||||
constructor(store: RowStore<ED, GeneralRuntimeContext<ED>>, appId: string, token?: string) {
|
||||
super(store);
|
||||
this.applicationId = appId;
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
async getApplication () {
|
||||
|
|
@ -26,7 +28,21 @@ export class GeneralRuntimeContext<ED extends EntityDict> extends UniversalConte
|
|||
return application;
|
||||
}
|
||||
|
||||
getToken() {
|
||||
async getToken() {
|
||||
if (this.token) {
|
||||
const { result: [token] } = await this.rowStore.select('token', {
|
||||
data: {
|
||||
id: 1,
|
||||
userId: 1,
|
||||
playerId: 1,
|
||||
},
|
||||
filter: {
|
||||
id: this.token,
|
||||
ableState: 'enabled',
|
||||
}
|
||||
}, this) as SelectionResult<ED['token']['Schema'], {id: 1, userId: 1, playerId: 1}>;
|
||||
|
||||
return token;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -2,11 +2,9 @@ import { EntityDict } from 'oak-domain/lib/types';
|
|||
import { EntityDict as BaseEntityDict } from 'oak-app-domain/EntityDict';
|
||||
import { loginByPassword, loginMp, /* AspectDict as TokenAD */} from './token';
|
||||
|
||||
const aspectDict = {
|
||||
export const aspectDict = {
|
||||
loginByPassword,
|
||||
loginMp,
|
||||
};
|
||||
|
||||
export default aspectDict;
|
||||
|
||||
// export type AspectDict<ED extends EntityDict & BaseEntityDict> = TokenAD<ED> & CrudAD<ED>;
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
import { GeneralRuntimeContext } from '../RuntimeContext';
|
||||
import { EntityDict } from 'oak-app-domain/EntityDict';
|
||||
|
||||
export async function loginMp<ED extends EntityDict>(params: { code: string }, context: GeneralRuntimeContext<ED>): Promise<string> {
|
||||
export async function loginMp<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>>(params: { code: string }, context: Cxt): Promise<string> {
|
||||
const { rowStore } = context;
|
||||
throw new Error('method not implemented!');
|
||||
}
|
||||
|
||||
export async function loginByPassword<ED extends EntityDict>(params: { password: string, mobile: string }, context: GeneralRuntimeContext<ED>): Promise<string> {
|
||||
export async function loginByPassword<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>>(params: { password: string, mobile: string }, context: Cxt): Promise<string> {
|
||||
const { rowStore } = context;
|
||||
|
||||
const { result: [mobile]} = await rowStore.select('mobile', {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ import { isMobile } from 'oak-domain/lib/utils/validator';
|
|||
import { AttrIllegalError, Checker, CreateChecker, DeduceCreateOperation, InstinctiveAttributes } from "oak-domain/lib/types";
|
||||
import { EntityDict } from 'oak-app-domain/EntityDict';
|
||||
import { checkAttributesNotNull } from '../utils/check';
|
||||
import { GeneralRuntimeContext } from '../RuntimeContext';
|
||||
|
||||
const checkers: Checker<EntityDict, 'address'> [] = [
|
||||
const checkers: Checker<EntityDict, 'address', GeneralRuntimeContext<EntityDict>> [] = [
|
||||
{
|
||||
action: 'create',
|
||||
entity: 'address',
|
||||
|
|
|
|||
|
|
@ -3,10 +3,28 @@ import { EntityShape } from 'oak-domain/lib/types/Entity';
|
|||
import { Schema as System } from './System';
|
||||
import { Schema as ExtraFile } from './ExtraFile';
|
||||
|
||||
type WechatMpConfig = {
|
||||
type: 'wechatMp';
|
||||
appId: string;
|
||||
appSecret: string;
|
||||
};
|
||||
|
||||
type WebConfig = {
|
||||
type: 'web';
|
||||
domain: string;
|
||||
};
|
||||
|
||||
type WechatPublicCofig = {
|
||||
type: 'wechatPublic';
|
||||
appId: string;
|
||||
appSecret: string;
|
||||
};
|
||||
|
||||
export interface Schema extends EntityShape {
|
||||
name: String<32>;
|
||||
description: Text;
|
||||
type: 'web' | 'wechatPublic' | 'weChatMp';
|
||||
system: System;
|
||||
dd: Array<ExtraFile>;
|
||||
config: WebConfig | WechatMpConfig| WechatPublicCofig;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
import { Token } from './token';
|
||||
|
||||
export function initialize() {
|
||||
const token = new Token();
|
||||
return {
|
||||
token,
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import { EntityDict } from 'oak-app-domain';
|
||||
import { GeneralRuntimeContext } from '../RuntimeContext';
|
||||
import { aspectDict } from '../aspects';
|
||||
import { Action, Feature } from 'oak-frontend-base';
|
||||
|
||||
export class Token extends Feature<EntityDict, GeneralRuntimeContext<EntityDict>, typeof aspectDict> {
|
||||
|
||||
private token?: string;
|
||||
|
||||
@Action
|
||||
async loginByPassword(mobile: string, password: string) {
|
||||
this.token = await this.getAspectProxy().loginByPassword({ password, mobile });
|
||||
}
|
||||
|
||||
@Action
|
||||
async logout() {
|
||||
this.token = undefined;
|
||||
}
|
||||
|
||||
getToken() {
|
||||
return this.token;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,16 @@
|
|||
// import './typings/polyfill';
|
||||
import aspectDict/* , { AspectDict } */ from "./aspects";
|
||||
import { aspectDict } from "./aspects";
|
||||
import triggers from "./triggers";
|
||||
import checkers from './checkers';
|
||||
import data from "./data";
|
||||
import { initialize as initializeFeatures } from './features';
|
||||
|
||||
export {
|
||||
checkers,
|
||||
triggers,
|
||||
data,
|
||||
aspectDict,
|
||||
initializeFeatures,
|
||||
/* AspectDict, */
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { CreateTriggerInTxn, Trigger } from 'oak-domain/lib/types/Trigger';
|
||||
import { EntityDict } from 'oak-app-domain/EntityDict';
|
||||
import { GeneralRuntimeContext } from '../RuntimeContext';
|
||||
|
||||
|
||||
const triggers: Trigger<EntityDict, 'address'>[] = [
|
||||
const triggers: Trigger<EntityDict, 'address', GeneralRuntimeContext<EntityDict>>[] = [
|
||||
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@
|
|||
},
|
||||
"include": [ "./**/*.ts" ],
|
||||
"exclude": [
|
||||
"lib",
|
||||
"node_modules",
|
||||
"**/*.spec.ts",
|
||||
"test",
|
||||
|
|
|
|||
Loading…
Reference in New Issue