oak-domain 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/lib/OakError.d.ts +7 -0
  2. package/lib/OakError.js +29 -0
  3. package/lib/actions/action.d.ts +6 -0
  4. package/lib/actions/action.js +12 -0
  5. package/lib/actions/relation.d.ts +1 -0
  6. package/lib/actions/relation.js +2 -0
  7. package/lib/compiler/env.d.ts +10 -0
  8. package/lib/compiler/env.js +26 -0
  9. package/lib/compiler/schemalBuilder.d.ts +2 -0
  10. package/lib/compiler/schemalBuilder.js +2738 -0
  11. package/lib/compiler/uiBuilder.d.ts +1 -0
  12. package/lib/compiler/uiBuilder.js +3 -0
  13. package/lib/compiler/utils.d.ts +2 -0
  14. package/lib/compiler/utils.js +11 -0
  15. package/lib/store/CascadeStore.d.ts +38 -0
  16. package/lib/store/CascadeStore.js +681 -0
  17. package/lib/store/TriggerExecutor.d.ts +30 -0
  18. package/lib/store/TriggerExecutor.js +549 -0
  19. package/lib/store/UniversalContext.d.ts +26 -0
  20. package/lib/store/UniversalContext.js +208 -0
  21. package/lib/store/actionDef.d.ts +8 -0
  22. package/lib/store/actionDef.js +241 -0
  23. package/lib/store/filter.d.ts +36 -0
  24. package/lib/store/filter.js +121 -0
  25. package/lib/store/relation.d.ts +13 -0
  26. package/lib/store/relation.js +64 -0
  27. package/lib/store/watchers.d.ts +2 -0
  28. package/lib/store/watchers.js +32 -0
  29. package/lib/types/Action.d.ts +14 -0
  30. package/lib/types/Action.js +2 -0
  31. package/lib/types/AppLoader.d.ts +11 -0
  32. package/lib/types/AppLoader.js +10 -0
  33. package/lib/types/Aspect.d.ts +12 -0
  34. package/lib/types/Aspect.js +4 -0
  35. package/lib/types/Auth.d.ts +28 -0
  36. package/lib/types/Auth.js +2 -0
  37. package/lib/types/Connector.d.ts +26 -0
  38. package/lib/types/Connector.js +9 -0
  39. package/lib/types/Context.d.ts +14 -0
  40. package/lib/types/Context.js +3 -0
  41. package/lib/types/DataType.d.ts +17 -0
  42. package/lib/types/DataType.js +5 -0
  43. package/lib/types/Demand.d.ts +77 -0
  44. package/lib/types/Demand.js +9 -0
  45. package/lib/types/Entity.d.ts +138 -0
  46. package/lib/types/Entity.js +8 -0
  47. package/lib/types/Exception.d.ts +48 -0
  48. package/lib/types/Exception.js +178 -0
  49. package/lib/types/Expression.d.ts +132 -0
  50. package/lib/types/Expression.js +378 -0
  51. package/lib/types/Geo.d.ts +18 -0
  52. package/lib/types/Geo.js +2 -0
  53. package/lib/types/Locale.d.ts +24 -0
  54. package/lib/types/Locale.js +2 -0
  55. package/lib/types/Logger.d.ts +5 -0
  56. package/lib/types/Logger.js +3 -0
  57. package/lib/types/Polyfill.d.ts +23 -0
  58. package/lib/types/Polyfill.js +2 -0
  59. package/lib/types/RowStore.d.ts +22 -0
  60. package/lib/types/RowStore.js +33 -0
  61. package/lib/types/Storage.d.ts +48 -0
  62. package/lib/types/Storage.js +2 -0
  63. package/lib/types/Trigger.d.ts +105 -0
  64. package/lib/types/Trigger.js +24 -0
  65. package/lib/types/Txn.d.ts +2 -0
  66. package/lib/types/Txn.js +3 -0
  67. package/lib/types/Watcher.d.ts +19 -0
  68. package/lib/types/Watcher.js +4 -0
  69. package/lib/types/index.d.ts +18 -0
  70. package/lib/types/index.js +30 -0
  71. package/lib/types/schema/DataTypes.d.ts +32 -0
  72. package/lib/types/schema/DataTypes.js +3 -0
  73. package/lib/utils/SimpleConnector.d.ts +29 -0
  74. package/lib/utils/SimpleConnector.js +145 -0
  75. package/lib/utils/assert.d.ts +5 -0
  76. package/lib/utils/assert.js +11 -0
  77. package/lib/utils/concurrent.d.ts +15 -0
  78. package/lib/utils/concurrent.js +138 -0
  79. package/lib/utils/geo.d.ts +4 -0
  80. package/lib/utils/geo.js +24 -0
  81. package/lib/utils/lodash.d.ts +16 -0
  82. package/lib/utils/lodash.js +32 -0
  83. package/lib/utils/string.d.ts +2 -0
  84. package/lib/utils/string.js +11 -0
  85. package/lib/utils/uuid.d.ts +2 -0
  86. package/lib/utils/uuid.js +11 -0
  87. package/lib/utils/validator.d.ts +23 -0
  88. package/lib/utils/validator.js +123 -0
  89. package/package.json +38 -0
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.judgeRelation = void 0;
7
+ var assert_1 = __importDefault(require("assert"));
8
+ var Demand_1 = require("../types/Demand");
9
+ var Entity_1 = require("../types/Entity");
10
+ /**
11
+ * 判断对象和属性之间的关系
12
+ * @param schema
13
+ * @param entity
14
+ * @param attr
15
+ * @param row
16
+ * @returns
17
+ */
18
+ function judgeRelation(schema, entity, attr) {
19
+ var _a = schema, _b = entity, attributes = _a[_b].attributes;
20
+ if (attr.startsWith(Demand_1.EXPRESSION_PREFIX) || attr.startsWith('#')) {
21
+ // 表达式属性或者metadata
22
+ return 0;
23
+ }
24
+ if (attributes.hasOwnProperty(attr) || Entity_1.initinctiveAttributes.includes(attr)) {
25
+ // 原生属性
26
+ return 1;
27
+ }
28
+ if (attr.includes('$')) {
29
+ var entity2 = attr.slice(0, attr.indexOf('$'));
30
+ (0, assert_1.default)(schema.hasOwnProperty(entity2));
31
+ var foreignKey = attr.slice(attr.indexOf('$') + 1);
32
+ var _c = schema, _d = entity2, attributes2 = _c[_d].attributes;
33
+ if (foreignKey === 'entity') {
34
+ // 基于反指对象的反向关联
35
+ return [entity2];
36
+ }
37
+ else if (attributes2.hasOwnProperty("".concat(foreignKey, "Id"))
38
+ && attributes2["".concat(foreignKey, "Id")].type === 'ref'
39
+ && attributes2["".concat(foreignKey, "Id")].ref === entity) {
40
+ // 基于外键的反向关联
41
+ return [entity2, "".concat(foreignKey, "Id")];
42
+ }
43
+ else {
44
+ // 这种情况应该不会跑到
45
+ (0, assert_1.default)(false);
46
+ }
47
+ }
48
+ else if ((attributes.hasOwnProperty("".concat(attr, "Id")))) {
49
+ var _e = attributes["".concat(attr, "Id")], type = _e.type, ref = _e.ref;
50
+ (0, assert_1.default)(type === 'ref');
51
+ return ref;
52
+ }
53
+ else if (attributes.hasOwnProperty('entity')
54
+ && attributes.hasOwnProperty('entityId')
55
+ && schema.hasOwnProperty(attr)) {
56
+ // 反向指针的外键
57
+ return 2;
58
+ }
59
+ else {
60
+ (0, assert_1.default)(Entity_1.initinctiveAttributes.includes(attr), "".concat(attr, "\u5C5E\u6027\u627E\u4E0D\u5230"));
61
+ return 1;
62
+ }
63
+ }
64
+ exports.judgeRelation = judgeRelation;
@@ -0,0 +1,2 @@
1
+ import { Context, EntityDict, StorageSchema, Watcher } from "../types";
2
+ export declare function makeIntrinsicWatchers<ED extends EntityDict, Cxt extends Context<ED>>(schema: StorageSchema<ED>): Watcher<ED, keyof ED, Cxt>[];
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeIntrinsicWatchers = void 0;
4
+ function makeIntrinsicWatchers(schema) {
5
+ const watchers = [];
6
+ for (const entity in schema) {
7
+ const { attributes } = schema[entity];
8
+ const { expiresAt, expired } = attributes;
9
+ if (expiresAt && expiresAt.type === 'datetime' && expired && expired.type === 'boolean') {
10
+ // 如果有定义expiresAt和expired,则自动生成一个检查的watcher
11
+ watchers.push({
12
+ entity,
13
+ name: `对象${entity}上的过期自动watcher`,
14
+ filter: async () => {
15
+ const now = Date.now();
16
+ return {
17
+ expired: false,
18
+ expiresAt: {
19
+ $lte: now,
20
+ },
21
+ };
22
+ },
23
+ action: 'update',
24
+ actionData: {
25
+ expired: true,
26
+ },
27
+ });
28
+ }
29
+ }
30
+ return watchers;
31
+ }
32
+ exports.makeIntrinsicWatchers = makeIntrinsicWatchers;
@@ -0,0 +1,14 @@
1
+ import { EntityDict } from "./Entity";
2
+ export declare type Action = string;
3
+ export declare type State = string;
4
+ export declare type ActionDef<A extends Action, S extends State> = {
5
+ stm: {
6
+ [a in A]: [p: S | S[], n: S];
7
+ };
8
+ is?: S;
9
+ };
10
+ export declare type ActionDictOfEntityDict<E extends EntityDict> = {
11
+ [T in keyof E]?: {
12
+ [A in keyof E[T]['OpSchema']]?: ActionDef<string, string>;
13
+ };
14
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ import { Context, RowStore } from ".";
2
+ import { EntityDict } from "./Entity";
3
+ export declare abstract class AppLoader<ED extends EntityDict, Cxt extends Context<ED>> {
4
+ protected path: string;
5
+ constructor(path: string);
6
+ abstract execAspect(name: string, context: Cxt, params?: any): Promise<any>;
7
+ abstract initialize(dropIfExists?: boolean): Promise<void>;
8
+ abstract mount(): Promise<void>;
9
+ abstract unmount(): Promise<void>;
10
+ abstract getStore(): RowStore<ED, Cxt>;
11
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppLoader = void 0;
4
+ var AppLoader = /** @class */ (function () {
5
+ function AppLoader(path) {
6
+ this.path = path;
7
+ }
8
+ return AppLoader;
9
+ }());
10
+ exports.AppLoader = AppLoader;
@@ -0,0 +1,12 @@
1
+ import { EntityDict } from "./Entity";
2
+ import { Context } from './Context';
3
+ import { OpRecord } from "./Entity";
4
+ export interface Aspect<ED extends EntityDict, Cxt extends Context<ED>> {
5
+ (params: any, context: Cxt): Promise<any>;
6
+ }
7
+ export interface AspectWrapper<ED extends EntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>> {
8
+ exec: <T extends keyof AD>(name: T, params: Parameters<AD[T]>[0]) => Promise<{
9
+ result: Awaited<ReturnType<AD[T]>>;
10
+ opRecords: OpRecord<ED>[];
11
+ }>;
12
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ ;
4
+ ;
@@ -0,0 +1,28 @@
1
+ import { EntityDict } from "../types/Entity";
2
+ import { Context } from "./Context";
3
+ import { CreateTriggerBase, RemoveTriggerBase, UpdateTriggerBase, CheckerType, SelectTriggerBefore } from "./Trigger";
4
+ export declare type CreateChecker<ED extends EntityDict, T extends keyof ED, Cxt extends Context<ED>> = {
5
+ type: CheckerType;
6
+ action: 'create';
7
+ entity: T;
8
+ checker: CreateTriggerBase<ED, T, Cxt>['fn'];
9
+ };
10
+ export declare type UpdateChecker<ED extends EntityDict, T extends keyof ED, Cxt extends Context<ED>> = {
11
+ type: CheckerType;
12
+ action: UpdateTriggerBase<ED, T, Cxt>['action'];
13
+ entity: T;
14
+ checker: UpdateTriggerBase<ED, T, Cxt>['fn'];
15
+ };
16
+ export declare type RemoveChecker<ED extends EntityDict, T extends keyof ED, Cxt extends Context<ED>> = {
17
+ type: CheckerType;
18
+ action: 'remove';
19
+ entity: T;
20
+ checker: RemoveTriggerBase<ED, T, Cxt>['fn'];
21
+ };
22
+ export declare type SelectChecker<ED extends EntityDict, T extends keyof ED, Cxt extends Context<ED>> = {
23
+ type: CheckerType;
24
+ action: 'select';
25
+ entity: T;
26
+ checker: SelectTriggerBefore<ED, T, Cxt>['fn'];
27
+ };
28
+ export declare type Checker<ED extends EntityDict, T extends keyof ED, Cxt extends Context<ED>> = CreateChecker<ED, T, Cxt> | UpdateChecker<ED, T, Cxt> | RemoveChecker<ED, T, Cxt> | SelectChecker<ED, T, Cxt>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,26 @@
1
+ /// <reference types="node" />
2
+ import { IncomingHttpHeaders } from "http";
3
+ import { RowStore } from ".";
4
+ import { Context } from "./Context";
5
+ import { EntityDict, OpRecord } from "./Entity";
6
+ import { OakException } from "./Exception";
7
+ export declare abstract class Connector<ED extends EntityDict, Cxt extends Context<ED>> {
8
+ abstract callAspect(name: string, params: any, context: Cxt): Promise<{
9
+ result: any;
10
+ opRecords: OpRecord<ED>[];
11
+ }>;
12
+ abstract getRouter(): string;
13
+ abstract parseRequest(headers: IncomingHttpHeaders, body: any, store: RowStore<ED, Cxt>): {
14
+ name: string;
15
+ params: any;
16
+ context: Cxt;
17
+ };
18
+ abstract serializeResult(result: any, context: Cxt, headers: IncomingHttpHeaders, body: any): {
19
+ body: any;
20
+ headers?: Record<string, any>;
21
+ };
22
+ abstract serializeException(exception: OakException, headers: IncomingHttpHeaders, body: any): {
23
+ body: any;
24
+ headers?: Record<string, any>;
25
+ };
26
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Connector = void 0;
4
+ var Connector = /** @class */ (function () {
5
+ function Connector() {
6
+ }
7
+ return Connector;
8
+ }());
9
+ exports.Connector = Connector;
@@ -0,0 +1,14 @@
1
+ import { EntityDict, OpRecord } from './Entity';
2
+ import { RowStore } from './RowStore';
3
+ export interface Context<ED extends EntityDict> {
4
+ opRecords: OpRecord<ED>[];
5
+ rowStore: RowStore<ED, this>;
6
+ begin(options?: object): Promise<void>;
7
+ commit(): Promise<void>;
8
+ rollback(): Promise<void>;
9
+ getCurrentTxnId(): string | undefined;
10
+ on(event: 'commit' | 'rollback', callback: () => Promise<void>): void;
11
+ toString(): Promise<string>;
12
+ getScene(): string | undefined;
13
+ setScene(scene?: string): void;
14
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ ;
@@ -0,0 +1,17 @@
1
+ import { Geo, SingleGeo } from "./Geo";
2
+ export declare type Int<L extends 1 | 2 | 4 | 8> = number;
3
+ export declare type Uint<L extends 1 | 2 | 4 | 8> = number;
4
+ export declare type Double<P extends number, S extends number> = number;
5
+ export declare type Float<P extends number, S extends number> = number;
6
+ export declare type String<L extends number> = string;
7
+ export declare type Text = string;
8
+ export declare type Image = string;
9
+ export declare type File = string;
10
+ export declare type Datetime = number | Date;
11
+ export declare type Boolean = boolean;
12
+ export declare type PrimaryKey = string;
13
+ export declare type ForeignKey<E extends string> = string;
14
+ export { Geo, SingleGeo } from './Geo';
15
+ export declare type DataTypes = number | string | Datetime | Geo | object | SingleGeo;
16
+ export declare const types: string[];
17
+ export declare const unIndexedTypes: string[];
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unIndexedTypes = exports.types = void 0;
4
+ exports.types = ['Int', 'Uint', 'Double', 'Float', 'String', 'Text', 'Datetime', 'Boolean', 'Image', 'File', 'Geo', 'SingleGeo'];
5
+ exports.unIndexedTypes = ['Text', 'Image', 'File', 'Object'];
@@ -0,0 +1,77 @@
1
+ import { RefOrExpression } from "./Expression";
2
+ import { OneOf } from "./Polyfill";
3
+ export declare const EXPRESSION_PREFIX = "$expr";
4
+ export declare type NodeId = `node-${number}`;
5
+ export declare type ExpressionKey = '$expr' | '$expr1' | '$expr2' | '$expr3' | '$expr4' | '$expr5' | '$expr6' | '$expr7' | '$expr8' | '$expr9' | '$expr10' | '$expr11' | '$expr12' | '$expr13' | '$expr14' | '$expr15' | '$expr16' | '$expr17' | '$expr18' | '$expr19' | '$expr20';
6
+ export declare type ExprOp<A> = {
7
+ [K in ExpressionKey]: RefOrExpression<A>;
8
+ };
9
+ export declare type Q_NumberComparisonValue = number | OneOf<{
10
+ $gt: number;
11
+ $lt: number;
12
+ $gte: number;
13
+ $lte: number;
14
+ $eq: number;
15
+ $ne: number;
16
+ $in: number[];
17
+ $nin: number[];
18
+ $between: [number, number];
19
+ }>;
20
+ export declare type Q_StringComparisonValue = string | OneOf<{
21
+ $gt: string;
22
+ $lt: string;
23
+ $gte: string;
24
+ $lte: string;
25
+ $eq: string;
26
+ $ne: string;
27
+ $startsWith: string;
28
+ $endsWith: string;
29
+ $includes: string;
30
+ $in: string[];
31
+ $nin: string[];
32
+ }>;
33
+ export declare type Q_BooleanComparisonValue = boolean;
34
+ export declare type Q_DateComparisonValue = Q_NumberComparisonValue;
35
+ export declare type Q_EnumComparisonValue<E> = E | OneOf<{
36
+ $in: E[];
37
+ $nin: E[];
38
+ }>;
39
+ export declare type Q_ExistsValue = {
40
+ $exists: boolean;
41
+ };
42
+ export declare type Q_NumberValue = Q_NumberComparisonValue | Q_ExistsValue;
43
+ export declare type Q_StringValue = Q_StringComparisonValue | Q_ExistsValue;
44
+ export declare type Q_BooleanValue = Q_BooleanComparisonValue | Q_ExistsValue;
45
+ export declare type Q_DateValue = Q_DateComparisonValue | Q_ExistsValue;
46
+ export declare type Q_EnumValue<E> = Q_EnumComparisonValue<E> | Q_ExistsValue;
47
+ export declare type Q_State<S> = S | {
48
+ $in: S[];
49
+ } | {
50
+ $nin: S[];
51
+ } | Q_ExistsValue;
52
+ export declare type Q_FullTextValue = {
53
+ $search: string;
54
+ $language?: 'zh_CN' | 'en_US';
55
+ };
56
+ export declare type Q_FullTextKey = '$text';
57
+ export declare type FulltextFilter = {
58
+ [F in Q_FullTextKey]?: Q_FullTextValue;
59
+ };
60
+ declare type Q_LogicKey = '$and' | '$or';
61
+ declare type Q_LinearLogicKey = '$not';
62
+ export declare type MakeFilterWrapper<F extends Object> = {
63
+ [Q in Q_LogicKey]?: Array<MakeFilterWrapper<F>>;
64
+ } & {
65
+ [Q in Q_LinearLogicKey]?: MakeFilterWrapper<F>;
66
+ } & Partial<F>;
67
+ export declare type MakeFilter<F extends Object> = {
68
+ '#id'?: NodeId;
69
+ } & MakeFilterWrapper<F>;
70
+ export declare type RefAttr<A> = {
71
+ '#attr': A;
72
+ } | {
73
+ '#refId': NodeId;
74
+ '#refAttr': string;
75
+ };
76
+ export declare function isRefAttrNode<A>(node: any): node is RefAttr<A>;
77
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRefAttrNode = exports.EXPRESSION_PREFIX = void 0;
4
+ exports.EXPRESSION_PREFIX = '$expr';
5
+ function isRefAttrNode(node) {
6
+ return node.hasOwnProperty('#attr') || (node.hasOwnProperty('#refId') && node.hasOwnProperty('#refAttr'));
7
+ }
8
+ exports.isRefAttrNode = isRefAttrNode;
9
+ ;
@@ -0,0 +1,138 @@
1
+ import { GenericAction } from '../actions/action';
2
+ import { ExpressionKey, ExprOp, MakeFilter, NodeId } from './Demand';
3
+ import { OneOf, OptionalKeys } from './Polyfill';
4
+ export declare type TriggerDataAttribute = '$$triggerData$$';
5
+ export declare type TriggerTimestampAttribute = '$$triggerTimestamp$$';
6
+ declare type PrimaryKeyAttribute = 'id';
7
+ export declare type InstinctiveAttributes = PrimaryKeyAttribute | '$$createAt$$' | '$$updateAt$$' | '$$deleteAt$$' | TriggerDataAttribute | TriggerTimestampAttribute;
8
+ export declare const initinctiveAttributes: string[];
9
+ export declare type Filter<A extends string, F extends Object | undefined = undefined> = {
10
+ filter?: A extends 'create' ? undefined : F;
11
+ indexFrom?: A extends 'create' ? undefined : number;
12
+ count?: A extends 'create' ? undefined : number;
13
+ };
14
+ export declare type SelectOption = {
15
+ dontCollect?: boolean;
16
+ ignoreTrigger?: true;
17
+ obscure?: boolean;
18
+ forUpdate?: true;
19
+ includedDeleted?: true;
20
+ dummy?: 1;
21
+ };
22
+ export declare type OperateOption = {
23
+ dontCollect?: boolean;
24
+ dummy?: 1;
25
+ };
26
+ export declare type FormUpdateData<SH extends GeneralEntityShape> = Partial<Omit<SH, InstinctiveAttributes>>;
27
+ export declare type FormCreateData<SH extends GeneralEntityShape> = Omit<SH, InstinctiveAttributes> & {
28
+ id: string;
29
+ };
30
+ export declare type Operation<A extends GenericAction | string, DATA extends Object, FILTER extends Object | undefined = undefined, SORTER extends Object | undefined = undefined> = {
31
+ action: A;
32
+ data: DATA;
33
+ sorter?: SORTER;
34
+ option?: A extends 'select' ? SelectOption : undefined;
35
+ } & Filter<A, FILTER>;
36
+ export declare type Selection<DATA extends Object, FILTER extends Object | undefined = undefined, SORT extends Object | undefined = undefined> = Operation<'select', DATA, FILTER, SORT>;
37
+ export interface EntityShape {
38
+ id: string;
39
+ $$createAt$$: number | Date;
40
+ $$updateAt$$: number | Date;
41
+ $$deleteAt$$?: number | Date | null;
42
+ }
43
+ export interface FileCarrierEntityShape extends EntityShape {
44
+ }
45
+ interface GeneralEntityShape extends EntityShape {
46
+ [K: string]: any;
47
+ }
48
+ export interface EntityDef {
49
+ Schema: GeneralEntityShape;
50
+ OpSchema: GeneralEntityShape;
51
+ Action: string;
52
+ ParticularAction?: string;
53
+ Selection: Omit<DeduceSelection<this['Schema']>, 'action'>;
54
+ Operation: DeduceOperation<this['Schema']>;
55
+ Create: DeduceCreateOperation<this['Schema']>;
56
+ CreateSingle: DeduceCreateSingleOperation<this['Schema']>;
57
+ CreateMulti: DeduceCreateMultipleOperation<this['Schema']>;
58
+ Update: DeduceUpdateOperation<this['Schema']>;
59
+ Remove: DeduceRemoveOperation<this['Schema']>;
60
+ }
61
+ export interface EntityDict {
62
+ [E: string]: EntityDef;
63
+ }
64
+ export interface OtmSubProjection extends Omit<DeduceSelection<any>, 'action'> {
65
+ $entity: string;
66
+ }
67
+ declare type DeduceProjection<SH extends GeneralEntityShape> = Partial<{
68
+ '#id': NodeId;
69
+ } & {
70
+ [K in keyof SH]: 1 | OtmSubProjection | any;
71
+ } & ExprOp<keyof SH>>;
72
+ export declare type AttrFilter<SH extends GeneralEntityShape> = {
73
+ [K in keyof SH]: any;
74
+ };
75
+ export declare type DeduceFilter<SH extends GeneralEntityShape> = MakeFilter<AttrFilter<SH> & ExprOp<keyof SH>>;
76
+ export declare type DeduceSorterAttr<SH extends GeneralEntityShape> = OneOf<{
77
+ [K: string]: 1 | object | undefined;
78
+ } & ExprOp<keyof SH>>;
79
+ export declare type DeduceSorterItem<SH extends GeneralEntityShape> = {
80
+ $attr: DeduceSorterAttr<SH>;
81
+ $direction?: "asc" | "desc";
82
+ };
83
+ export declare type DeduceSorter<SH extends GeneralEntityShape> = Array<DeduceSorterItem<SH>>;
84
+ export declare type DeduceSelection<SH extends GeneralEntityShape> = Selection<DeduceProjection<SH>, DeduceFilter<SH>, DeduceSorter<SH>>;
85
+ export declare type DeduceCreateOperationData<SH extends GeneralEntityShape> = FormCreateData<SH> & {
86
+ [k: string]: any;
87
+ };
88
+ export declare type DeduceCreateSingleOperation<SH extends GeneralEntityShape> = Operation<'create', DeduceCreateOperationData<SH>>;
89
+ export declare type DeduceCreateMultipleOperation<SH extends GeneralEntityShape> = Operation<'create', Array<DeduceCreateOperationData<SH>>>;
90
+ export declare type DeduceCreateOperation<SH extends GeneralEntityShape> = DeduceCreateSingleOperation<SH> | DeduceCreateMultipleOperation<SH>;
91
+ export declare type DeduceUpdateOperationData<SH extends GeneralEntityShape> = FormUpdateData<SH> & {
92
+ [k: string]: any;
93
+ };
94
+ export declare type DeduceUpdateOperation<SH extends GeneralEntityShape> = Operation<'update' | string, DeduceUpdateOperationData<SH>, DeduceFilter<SH>, DeduceSorter<SH>>;
95
+ export declare type DeduceRemoveOperationData<SH extends GeneralEntityShape> = {
96
+ [A in keyof SH]?: any;
97
+ } & {
98
+ [A: string]: any;
99
+ };
100
+ export declare type DeduceRemoveOperation<SH extends GeneralEntityShape> = Operation<'remove', DeduceRemoveOperationData<SH>, DeduceFilter<SH>, DeduceSorter<SH>>;
101
+ export declare type DeduceOperation<SH extends GeneralEntityShape> = DeduceCreateOperation<SH> | DeduceUpdateOperation<SH> | DeduceRemoveOperation<SH> | DeduceSelection<SH>;
102
+ export declare type CreateOpResult<ED extends EntityDict, T extends keyof ED> = {
103
+ a: 'c';
104
+ e: T;
105
+ d: ED[T]['OpSchema'] | ED[T]['OpSchema'][];
106
+ };
107
+ export declare type UpdateOpResult<ED extends EntityDict, T extends keyof ED> = {
108
+ a: 'u';
109
+ e: T;
110
+ d: FormUpdateData<ED[T]['OpSchema']>;
111
+ f?: DeduceFilter<ED[T]['Schema']>;
112
+ };
113
+ export declare type RemoveOpResult<ED extends EntityDict, T extends keyof ED> = {
114
+ a: 'r';
115
+ e: T;
116
+ f?: DeduceFilter<ED[T]['Schema']>;
117
+ };
118
+ export declare type SelectOpResult<ED extends EntityDict> = {
119
+ a: 's';
120
+ d: {
121
+ [T in keyof ED]?: {
122
+ [ID: string]: ED[T]['OpSchema'];
123
+ };
124
+ };
125
+ };
126
+ export declare type OpRecord<ED extends EntityDict> = CreateOpResult<ED, keyof ED> | UpdateOpResult<ED, keyof ED> | RemoveOpResult<ED, keyof ED> | SelectOpResult<ED>;
127
+ export declare type OperationResult<ED extends EntityDict> = {
128
+ [K in keyof ED]?: {
129
+ [A in ED[K]['Action']]?: number;
130
+ };
131
+ };
132
+ export declare type SelectRowShape<E extends GeneralEntityShape, P extends DeduceProjection<GeneralEntityShape>> = {
133
+ [K in keyof P]: K extends ExpressionKey ? any : (K extends keyof E ? (P[K] extends 1 | undefined ? E[K] : (P[K] extends OtmSubProjection ? SelectRowShape<Required<E>[K][0], P[K]['data']>[] | Array<never> : (K extends OptionalKeys<E> ? SelectRowShape<NonNullable<Required<E>[K]>, P[K]> | null : SelectRowShape<NonNullable<Required<E>[K]>, P[K]>))) : never);
134
+ };
135
+ export declare type SelectionResult<E extends GeneralEntityShape, P extends DeduceProjection<GeneralEntityShape>> = {
136
+ result: Array<SelectRowShape<E, P>>;
137
+ };
138
+ export {};
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initinctiveAttributes = void 0;
4
+ exports.initinctiveAttributes = ['id', '$$createAt$$', '$$updateAt$$', '$$deleteAt$$', '$$triggerData$$', '$$triggerTimestamp$$'];
5
+ ;
6
+ ;
7
+ ;
8
+ ;
@@ -0,0 +1,48 @@
1
+ import { EntityDict, OpRecord } from "./Entity";
2
+ export declare class OakException extends Error {
3
+ constructor(message?: string);
4
+ toString(): string;
5
+ }
6
+ export declare class OakExternalException extends Error {
7
+ }
8
+ export declare class OakUserException extends OakException {
9
+ }
10
+ /**
11
+ * 数据不一致异常,系统认为现有的数据不允许相应的动作时抛此异常
12
+ *
13
+ */
14
+ export declare class OakRowInconsistencyException<ED extends EntityDict> extends OakUserException {
15
+ private data?;
16
+ constructor(data?: OpRecord<ED>, message?: string);
17
+ getData(): OpRecord<ED> | undefined;
18
+ toString(): string;
19
+ }
20
+ /**
21
+ * 当输入的数据非法时抛此异常,attributes表示非法的属性
22
+ */
23
+ export declare class OakInputIllegalException extends OakUserException {
24
+ private attributes;
25
+ constructor(attributes: string[], message?: string);
26
+ getAttributes(): string[];
27
+ addAttributesPrefix(prefix: string): void;
28
+ toString(): string;
29
+ }
30
+ /**
31
+ * 用户权限不够时抛的异常
32
+ */
33
+ export declare class OakUserUnpermittedException extends OakUserException {
34
+ }
35
+ /**
36
+ * 要插入行时,发现已经有相同的行数据
37
+ */
38
+ export declare class OakCongruentRowExists<ED extends EntityDict, T extends keyof ED> extends OakUserException {
39
+ private data;
40
+ constructor(data: ED[T]['OpSchema'], message?: string);
41
+ getData(): ED[T]["OpSchema"];
42
+ toString(): string;
43
+ }
44
+ export declare function makeException(data: {
45
+ name: string;
46
+ message?: string;
47
+ [A: string]: any;
48
+ }): OakException | OakExternalException | undefined;