merge
This commit is contained in:
commit
30ba13e841
|
|
@ -1,10 +1,10 @@
|
|||
/// <reference types="node" />
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { AppLoader as GeneralAppLoader, Trigger, EntityDict, Watcher, OpRecord, FreeTimer, OperationResult } from "oak-domain/lib/types";
|
||||
import { DbStore } from "./DbStore";
|
||||
import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext';
|
||||
import { IncomingHttpHeaders } from 'http';
|
||||
import { Namespace } from 'socket.io';
|
||||
import Koa from "koa";
|
||||
import DataSubscriber from './cluster/DataSubscriber';
|
||||
import Synchronizer from './Synchronizer';
|
||||
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
|
||||
|
|
|
|||
|
|
@ -274,42 +274,25 @@ class AppLoader extends types_1.AppLoader {
|
|||
url += `/:${p}`;
|
||||
}
|
||||
}
|
||||
if (type == "custom") {
|
||||
endPointRouters.push([type, name, method, url, async (koaCtx) => {
|
||||
const { request, res } = koaCtx;
|
||||
const { headers } = request;
|
||||
koaCtx.respond = false;
|
||||
try {
|
||||
await fn(() => this.makeContext(undefined, headers), koaCtx);
|
||||
res.statusCode = 200;
|
||||
}
|
||||
catch (err) {
|
||||
console.error(`endpoint「${key}」方法「${method}」出错`, err);
|
||||
res.statusCode = 500;
|
||||
throw err;
|
||||
}
|
||||
finally {
|
||||
res.end();
|
||||
}
|
||||
}]);
|
||||
}
|
||||
else {
|
||||
endPointRouters.push([type, name, method, url, async (koaCtx) => {
|
||||
const { request, params } = koaCtx;
|
||||
const { body, headers, files, req } = request;
|
||||
endPointRouters.push([name, method, url, async (params, headers, req, body) => {
|
||||
let result;
|
||||
if (type == "custom") {
|
||||
result = await fn(() => this.makeContext(undefined, headers), params, headers, req, body);
|
||||
}
|
||||
else {
|
||||
const context = await this.makeContext(undefined, headers);
|
||||
try {
|
||||
const result = await fn(context, params, headers, req, files ? Object.assign({}, body, files) : body);
|
||||
result = await fn(context, params, headers, req, body);
|
||||
await context.commit();
|
||||
request.body = result;
|
||||
}
|
||||
catch (err) {
|
||||
await context.rollback();
|
||||
console.error(`endpoint「${key}」方法「${method}」出错`, err);
|
||||
throw err;
|
||||
}
|
||||
}]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}]);
|
||||
};
|
||||
if (endPointMap[k]) {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ export default class Synchronizer<ED extends EntityDict & BaseEntityDict, Cxt ex
|
|||
* 根据sync的定义,生成对应的 commit triggers
|
||||
* @returns
|
||||
*/
|
||||
getSyncTriggers(): Array<VolatileTrigger<ED, keyof ED, Cxt>>;
|
||||
getSyncTriggers(): VolatileTrigger<ED, keyof ED, Cxt>[];
|
||||
getSelfEndpoint(): EndpointItem<ED, Cxt>;
|
||||
tryCreateSyncProcess(): void;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ class Synchronizer {
|
|||
remoteEntityId: entityId,
|
||||
data: queue.map((ele) => ({
|
||||
entity: ele.oper.targetEntity,
|
||||
rowIds: ele.oper.filter.id.$in, // 暂时应该没什么用
|
||||
rowIds: ele.oper.filter.id.$in,
|
||||
action: ele.oper.action,
|
||||
data: ele.oper.data,
|
||||
})),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getClusterInfo = getClusterInfo;
|
||||
exports.getClusterInfo = void 0;
|
||||
function getProcessEnvOption(option) {
|
||||
if (process.env.hasOwnProperty(option)) {
|
||||
return process.env[option];
|
||||
|
|
@ -54,3 +54,4 @@ const MyClusterInfo = initialize();
|
|||
function getClusterInfo() {
|
||||
return MyClusterInfo;
|
||||
}
|
||||
exports.getClusterInfo = getClusterInfo;
|
||||
|
|
|
|||
|
|
@ -342,45 +342,28 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Backe
|
|||
url += `/:${p}`;
|
||||
}
|
||||
}
|
||||
if (type == "custom") {
|
||||
endPointRouters.push(
|
||||
[type, name, method, url, async (koaCtx) => {
|
||||
const { request, res } = koaCtx
|
||||
const { headers } = request;
|
||||
koaCtx.respond = false
|
||||
try {
|
||||
await fn(() => this.makeContext(undefined, headers), koaCtx);
|
||||
res.statusCode = 200
|
||||
}
|
||||
catch (err) {
|
||||
console.error(`endpoint「${key}」方法「${method}」出错`, err);
|
||||
res.statusCode = 500
|
||||
throw err;
|
||||
} finally {
|
||||
res.end()
|
||||
}
|
||||
}]
|
||||
);
|
||||
} else {
|
||||
endPointRouters.push(
|
||||
[type, name, method, url, async (koaCtx) => {
|
||||
const { response, request, params } = koaCtx;
|
||||
const { body, headers, files, req } = request;
|
||||
const context = await this.makeContext(undefined, headers);
|
||||
endPointRouters.push(
|
||||
[name, method, url, async (params, headers, req, body) => {
|
||||
|
||||
let result: string | NodeJS.ReadableStream
|
||||
if (type == "custom") {
|
||||
result = await fn(() => this.makeContext(undefined, headers), params, headers, req, body);
|
||||
} else {
|
||||
const context = await this.makeContext(undefined, headers);
|
||||
try {
|
||||
const result = await fn(context, params, headers, req, files ? Object.assign({}, body, files) : body);
|
||||
result = await fn(context, params, headers, req, body);
|
||||
await context.commit();
|
||||
response.body = result;
|
||||
}
|
||||
catch (err) {
|
||||
await context.rollback();
|
||||
console.error(`endpoint「${key}」方法「${method}」出错`, err);
|
||||
throw err;
|
||||
}
|
||||
}]
|
||||
);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
}]
|
||||
);
|
||||
}
|
||||
if (endPointMap[k]) {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
|
|
|
|||
Loading…
Reference in New Issue