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