增加了aggregate接口

This commit is contained in:
Xu Chang 2023-01-07 19:23:08 +08:00
parent 8d6fdb0185
commit 90f72210e3
8 changed files with 45 additions and 5 deletions

7
lib/AspectDict.d.ts vendored
View File

@ -1,4 +1,4 @@
import { EntityDict, OperateOption, SelectOption, OperationResult } from "oak-domain/lib/types";
import { EntityDict, OperateOption, SelectOption, OperationResult, AggregationResult } from "oak-domain/lib/types";
import { AmapInstance } from "oak-external-sdk";
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
import { AsyncContext } from "oak-domain/lib/store/AsyncRowStore";
@ -17,6 +17,11 @@ export declare type CommonAspectDict<ED extends EntityDict & BaseEntityDict, Cxt
data: Partial<ED[T]['Schema']>[];
count?: number;
}>;
aggregate: <T extends keyof ED, OP extends SelectOption>(params: {
entity: T;
aggregation: ED[T]['Aggregation'];
option?: OP;
}, context: Cxt) => Promise<AggregationResult<ED[T]['Schema']>>;
count: <T extends keyof ED, OP extends SelectOption>(params: {
entity: T;
selection: Pick<ED[T]['Selection'], 'filter'>;

5
lib/crud.d.ts vendored
View File

@ -16,6 +16,11 @@ export declare function select<ED extends EntityDict, T extends keyof ED, Cxt ex
data: Partial<ED[T]['Schema']>[];
count?: number | undefined;
}>;
export declare function aggregate<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, OP extends SelectOption>(params: {
entity: T;
aggregation: ED[T]['Aggregation'];
option?: OP;
}, context: Cxt): Promise<import("oak-domain/lib/types").AggregationResult<ED[T]["Schema"]>>;
export declare function fetchRows<ED extends EntityDict & BaseEntityDict, OP extends SelectOption, Cxt extends AsyncContext<ED>>(params: Array<{
entity: keyof ED;
selection: ED[keyof ED]['Selection'];

View File

@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.count = exports.fetchRows = exports.select = exports.operate = void 0;
exports.count = exports.fetchRows = exports.aggregate = exports.select = exports.operate = void 0;
const types_1 = require("oak-domain/lib/types");
async function operate(params, context) {
const { entity, operation, option } = params;
@ -39,6 +39,11 @@ async function select(params, context) {
return result;
}
exports.select = select;
async function aggregate(params, context) {
const { entity, aggregation, option } = params;
return context.aggregate(entity, aggregation, option || {});
}
exports.aggregate = aggregate;
async function fetchRows(params, context) {
await Promise.all(params.map((ele) => context.select(ele.entity, ele.selection, ele.option || {})));
}

3
lib/index.d.ts vendored
View File

@ -1,10 +1,11 @@
import { operate, select, fetchRows, count } from './crud';
import { operate, select, fetchRows, count, aggregate } from './crud';
import { amap } from './amap';
import { getTranslations } from './locales';
declare const aspectDict: {
operate: typeof operate;
select: typeof select;
count: typeof count;
aggregate: typeof aggregate;
fetchRows: typeof fetchRows;
amap: typeof amap;
getTranslations: typeof getTranslations;

View File

@ -8,6 +8,7 @@ const aspectDict = {
operate: crud_1.operate,
select: crud_1.select,
count: crud_1.count,
aggregate: crud_1.aggregate,
fetchRows: crud_1.fetchRows,
amap: amap_1.amap,
getTranslations: locales_1.getTranslations,

View File

@ -1,4 +1,4 @@
import { EntityDict, OperateOption, SelectOption, OperationResult } from "oak-domain/lib/types";
import { EntityDict, OperateOption, SelectOption, OperationResult, AggregationResult } from "oak-domain/lib/types";
import { AmapInstance } from "oak-external-sdk";
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
import { AsyncContext } from "oak-domain/lib/store/AsyncRowStore";
@ -23,6 +23,14 @@ export type CommonAspectDict<ED extends EntityDict & BaseEntityDict, Cxt extends
data: Partial<ED[T]['Schema']>[];
count?: number;
}>;
aggregate: <T extends keyof ED, OP extends SelectOption>(
params: {
entity: T;
aggregation: ED[T]['Aggregation'];
option?: OP;
},
context: Cxt
) => Promise<AggregationResult<ED[T]['Schema']>>;
count: <
T extends keyof ED,
OP extends SelectOption

View File

@ -91,6 +91,20 @@ export async function select<
return result;
}
export async function aggregate<
ED extends EntityDict,
T extends keyof ED,
Cxt extends AsyncContext<ED>,
OP extends SelectOption
>(params: {
entity: T,
aggregation: ED[T]['Aggregation'],
option?: OP,
}, context: Cxt) {
const { entity, aggregation, option } = params;
return context.aggregate(entity, aggregation, option || {});
}
export async function fetchRows<
ED extends EntityDict & BaseEntityDict,
OP extends SelectOption,

View File

@ -1,10 +1,11 @@
import { operate, select, fetchRows, count } from './crud';
import { operate, select, fetchRows, count, aggregate } from './crud';
import { amap } from './amap';
import { getTranslations } from './locales';
const aspectDict = {
operate,
select,
count,
aggregate,
fetchRows,
amap,
getTranslations,