oak-domain 6.1.1 → 6.1.2
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.
- package/es/base-app-domain/ActionDefDict.d.ts +1 -0
- package/es/base-app-domain/ActionDefDict.js +3 -1
- package/es/base-app-domain/EntityDict.d.ts +86 -1
- package/es/base-app-domain/Log/Storage.js +4 -0
- package/es/base-app-domain/Log/_baseSchema.d.ts +5 -0
- package/es/base-app-domain/Storage.js +3 -1
- package/es/base-app-domain/StyleDict.js +3 -1
- package/es/base-app-domain/Version/Action.d.ts +6 -0
- package/es/base-app-domain/Version/Action.js +2 -0
- package/es/base-app-domain/Version/Schema.d.ts +19 -0
- package/es/base-app-domain/Version/Schema.js +1 -0
- package/es/base-app-domain/Version/Storage.d.ts +3 -0
- package/es/base-app-domain/Version/Storage.js +54 -0
- package/es/base-app-domain/Version/Style.d.ts +3 -0
- package/es/base-app-domain/Version/Style.js +6 -0
- package/es/base-app-domain/Version/_baseSchema.d.ts +57 -0
- package/es/base-app-domain/Version/_baseSchema.js +1 -0
- package/es/compiler/dependencyBuilder.d.ts +1 -0
- package/es/compiler/dependencyBuilder.js +94 -9
- package/es/compiler/routerBuilder.d.ts +4 -1
- package/es/compiler/routerBuilder.js +22 -19
- package/es/compiler/schemaBuilder.d.ts +5 -1
- package/es/compiler/schemaBuilder.js +10 -0
- package/es/context/BackendRuntimeContext.d.ts +9 -1
- package/es/context/BackendRuntimeContext.js +13 -1
- package/es/entities/Log.d.ts +2 -0
- package/es/entities/Log.js +2 -0
- package/es/entities/Version.d.ts +14 -0
- package/es/entities/Version.js +42 -0
- package/es/store/AsyncRowStore.d.ts +4 -1
- package/es/store/AsyncRowStore.js +7 -0
- package/es/store/CascadeStore.js +22 -0
- package/es/store/RelationAuth/authorizationFilter.d.ts +11 -0
- package/es/store/RelationAuth/authorizationFilter.js +104 -0
- package/es/store/RelationAuth/continuation.d.ts +9 -0
- package/es/store/RelationAuth/continuation.js +33 -0
- package/es/store/RelationAuth/index.d.ts +141 -0
- package/es/store/RelationAuth/index.js +1440 -0
- package/es/store/RelationAuth/model.d.ts +38 -0
- package/es/store/RelationAuth/model.js +24 -0
- package/es/store/RelationAuth/userLookup.d.ts +21 -0
- package/es/store/RelationAuth/userLookup.js +102 -0
- package/es/store/SyncRowStore.d.ts +2 -1
- package/es/store/SyncRowStore.js +3 -0
- package/es/store/filter.fix.d.ts +128 -0
- package/es/store/filter.fix.js +2862 -0
- package/es/store/filter.js +14 -9
- package/es/store/triggers.js +239 -44
- package/es/types/Context.d.ts +2 -1
- package/es/types/Demand.d.ts +11 -1
- package/es/types/Environment.d.ts +13 -2
- package/es/types/Exception.d.ts +3 -3
- package/es/types/Exception.js +25 -22
- package/es/types/Expression.d.ts +4 -1
- package/es/types/Expression.js +1 -1
- package/es/types/Storage.d.ts +15 -2
- package/es/utils/SimpleConnector.js +5 -2
- package/es/utils/decimal.js +2 -1
- package/es/utils/fetch/index.ali.d.ts +3 -0
- package/es/utils/fetch/index.ali.js +31 -0
- package/es/utils/fetch/index.d.ts +3 -0
- package/es/utils/fetch/index.js +5 -0
- package/es/utils/fetch/index.mp.d.ts +5 -3
- package/es/utils/fetch/index.mp.js +5 -280
- package/es/utils/fetch/index.wechat.d.ts +5 -0
- package/es/utils/fetch/index.wechat.js +174 -0
- package/es/utils/fetch/mini-program.shared.d.ts +37 -0
- package/es/utils/fetch/mini-program.shared.js +85 -0
- package/es/utils/geo.d.ts +1 -1
- package/es/utils/geo.js +1 -1
- package/es/utils/random/random.ali.d.ts +6 -0
- package/es/utils/random/random.ali.js +21 -0
- package/es/utils/random/random.mp.d.ts +5 -1
- package/es/utils/random/random.mp.js +11 -5
- package/es/utils/random/random.native.d.ts +1 -1
- package/es/utils/random/random.native.js +7 -4
- package/es/utils/random/random.wechat.d.ts +1 -0
- package/es/utils/random/random.wechat.js +10 -0
- package/lib/base-app-domain/ActionDefDict.d.ts +1 -0
- package/lib/base-app-domain/ActionDefDict.js +3 -1
- package/lib/base-app-domain/EntityDict.d.ts +86 -1
- package/lib/base-app-domain/Log/Storage.js +4 -0
- package/lib/base-app-domain/Log/_baseSchema.d.ts +5 -0
- package/lib/base-app-domain/Storage.js +3 -1
- package/lib/base-app-domain/StyleDict.js +3 -1
- package/lib/base-app-domain/Version/Action.d.ts +6 -0
- package/lib/base-app-domain/Version/Action.js +5 -0
- package/lib/base-app-domain/Version/Schema.d.ts +19 -0
- package/lib/base-app-domain/Version/Schema.js +4 -0
- package/lib/base-app-domain/Version/Storage.d.ts +3 -0
- package/lib/base-app-domain/Version/Storage.js +57 -0
- package/lib/base-app-domain/Version/Style.d.ts +3 -0
- package/lib/base-app-domain/Version/Style.js +9 -0
- package/lib/base-app-domain/Version/_baseSchema.d.ts +57 -0
- package/lib/base-app-domain/Version/_baseSchema.js +2 -0
- package/lib/compiler/dependencyBuilder.d.ts +1 -0
- package/lib/compiler/dependencyBuilder.js +95 -9
- package/lib/compiler/routerBuilder.d.ts +4 -1
- package/lib/compiler/routerBuilder.js +22 -19
- package/lib/compiler/schemaBuilder.d.ts +5 -1
- package/lib/compiler/schemaBuilder.js +10 -0
- package/lib/context/BackendRuntimeContext.d.ts +9 -1
- package/lib/context/BackendRuntimeContext.js +13 -1
- package/lib/entities/Log.d.ts +2 -0
- package/lib/entities/Log.js +2 -0
- package/lib/entities/Version.d.ts +14 -0
- package/lib/entities/Version.js +43 -0
- package/lib/store/AsyncRowStore.d.ts +4 -1
- package/lib/store/AsyncRowStore.js +7 -0
- package/lib/store/CascadeStore.js +22 -0
- package/lib/store/RelationAuth/authorizationFilter.d.ts +11 -0
- package/lib/store/RelationAuth/authorizationFilter.js +110 -0
- package/lib/store/RelationAuth/continuation.d.ts +9 -0
- package/lib/store/RelationAuth/continuation.js +37 -0
- package/lib/store/RelationAuth/index.d.ts +141 -0
- package/lib/store/RelationAuth/index.js +1445 -0
- package/lib/store/RelationAuth/model.d.ts +38 -0
- package/lib/store/RelationAuth/model.js +27 -0
- package/lib/store/RelationAuth/userLookup.d.ts +21 -0
- package/lib/store/RelationAuth/userLookup.js +105 -0
- package/lib/store/SyncRowStore.d.ts +2 -1
- package/lib/store/SyncRowStore.js +3 -0
- package/lib/store/filter.fix.d.ts +128 -0
- package/lib/store/filter.fix.js +2876 -0
- package/lib/store/filter.js +14 -9
- package/lib/store/triggers.js +239 -44
- package/lib/types/Context.d.ts +2 -1
- package/lib/types/Demand.d.ts +11 -1
- package/lib/types/Environment.d.ts +13 -2
- package/lib/types/Exception.d.ts +3 -3
- package/lib/types/Exception.js +25 -22
- package/lib/types/Expression.d.ts +4 -1
- package/lib/types/Expression.js +1 -1
- package/lib/types/Storage.d.ts +15 -2
- package/lib/utils/SimpleConnector.js +5 -2
- package/lib/utils/decimal.js +2 -1
- package/lib/utils/fetch/index.ali.d.ts +3 -0
- package/lib/utils/fetch/index.ali.js +36 -0
- package/lib/utils/fetch/index.d.ts +3 -0
- package/lib/utils/fetch/index.js +7 -0
- package/lib/utils/fetch/index.mp.d.ts +5 -3
- package/lib/utils/fetch/index.mp.js +5 -282
- package/lib/utils/fetch/index.wechat.d.ts +5 -0
- package/lib/utils/fetch/index.wechat.js +180 -0
- package/lib/utils/fetch/mini-program.shared.d.ts +37 -0
- package/lib/utils/fetch/mini-program.shared.js +96 -0
- package/lib/utils/geo.d.ts +1 -1
- package/lib/utils/geo.js +1 -1
- package/lib/utils/random/random.ali.d.ts +6 -0
- package/lib/utils/random/random.ali.js +24 -0
- package/lib/utils/random/random.mp.d.ts +5 -1
- package/lib/utils/random/random.mp.js +11 -5
- package/lib/utils/random/random.native.d.ts +1 -1
- package/lib/utils/random/random.native.js +7 -5
- package/lib/utils/random/random.wechat.d.ts +1 -0
- package/lib/utils/random/random.wechat.js +13 -0
- package/package.json +6 -3
- package/es/store/RelationAuth.d.ts +0 -115
- package/es/store/RelationAuth.js +0 -1340
- package/lib/store/RelationAuth.d.ts +0 -115
- package/lib/store/RelationAuth.js +0 -1345
|
@@ -13,15 +13,20 @@ const DESKTOP_PAGE_RENDER_FILES = [
|
|
|
13
13
|
'render.macos.tsx',
|
|
14
14
|
'render.linux.tsx',
|
|
15
15
|
];
|
|
16
|
+
const MINI_PROGRAM_PAGE_RENDER_FILES = [
|
|
17
|
+
'index.xml',
|
|
18
|
+
'index.wechat.xml',
|
|
19
|
+
'index.ali.xml',
|
|
20
|
+
];
|
|
16
21
|
const PAGE_RENDER_FILES = [
|
|
17
22
|
...WEB_PAGE_RENDER_FILES,
|
|
18
23
|
...DESKTOP_PAGE_RENDER_FILES,
|
|
19
24
|
'render.native.tsx',
|
|
20
25
|
'render.ios.tsx',
|
|
21
26
|
'render.android.tsx',
|
|
22
|
-
|
|
27
|
+
...MINI_PROGRAM_PAGE_RENDER_FILES,
|
|
23
28
|
];
|
|
24
|
-
const PAGE_WATCH_FILTER = /(?:^|[\\/])(?:web\.tsx|web\.pc\.tsx|web\.mobile\.tsx|index\.json|index\.config\.(?:ts|mts|cts|js|mjs|cjs)|index
|
|
29
|
+
const PAGE_WATCH_FILTER = /(?:^|[\\/])(?:web\.tsx|web\.pc\.tsx|web\.mobile\.tsx|index\.json|index\.config\.(?:ts|mts|cts|js|mjs|cjs)|index(?:\.wechat|\.ali)?\.xml|render\.(?:desktop|windows|macos|linux|native|ios|android)\.tsx)$/;
|
|
25
30
|
const NAMESPACE_WATCH_FILTER = /(?:^|[\\/])(?:index\.json|index\.config\.(?:ts|mts|cts|js|mjs|cjs))$/;
|
|
26
31
|
const VALID_PAGE_DIR_NAME = /^[A-Za-z0-9_-]+$/;
|
|
27
32
|
function normalizePath(path) {
|
|
@@ -45,9 +50,6 @@ function isDesktopRenderProfile() {
|
|
|
45
50
|
return process.env.OAK_RENDER === 'tauri'
|
|
46
51
|
|| process.env.OAK_RENDER === 'electron';
|
|
47
52
|
}
|
|
48
|
-
function isWebStartupDir(startupDir) {
|
|
49
|
-
return startupDir.startsWith('web') || isDesktopRenderProfile();
|
|
50
|
-
}
|
|
51
53
|
function getInvalidPageDirPath(relativePath) {
|
|
52
54
|
const segments = normalizeRelativePath(relativePath).split('/').filter(Boolean);
|
|
53
55
|
const validSegments = [];
|
|
@@ -81,7 +83,7 @@ function hasPageDescChanged(prev, next) {
|
|
|
81
83
|
|| prev.oakDisablePulldownRefresh !== next.oakDisablePulldownRefresh
|
|
82
84
|
|| prev.hasWeb !== next.hasWeb
|
|
83
85
|
|| prev.hasNative !== next.hasNative
|
|
84
|
-
|| prev.
|
|
86
|
+
|| prev.hasMiniProgram !== next.hasMiniProgram
|
|
85
87
|
|| JSON.stringify(prev.access) !== JSON.stringify(next.access);
|
|
86
88
|
}
|
|
87
89
|
function getNamespaceFromFilepath(rootDir, filepath) {
|
|
@@ -111,7 +113,7 @@ function checkPageDir(dir, relativePath, ns, type) {
|
|
|
111
113
|
const subdirs = [];
|
|
112
114
|
let hasNative = false;
|
|
113
115
|
let hasWeb = false;
|
|
114
|
-
let
|
|
116
|
+
let hasMiniProgram = false;
|
|
115
117
|
const files = readdirSync(dir);
|
|
116
118
|
files.forEach((file) => {
|
|
117
119
|
const filepath = join(dir, file);
|
|
@@ -125,8 +127,8 @@ function checkPageDir(dir, relativePath, ns, type) {
|
|
|
125
127
|
&& DESKTOP_PAGE_RENDER_FILES.includes(file))) {
|
|
126
128
|
hasWeb = true;
|
|
127
129
|
}
|
|
128
|
-
else if (file
|
|
129
|
-
|
|
130
|
+
else if (MINI_PROGRAM_PAGE_RENDER_FILES.includes(file)) {
|
|
131
|
+
hasMiniProgram = true;
|
|
130
132
|
}
|
|
131
133
|
}
|
|
132
134
|
else if (stat.isDirectory()) {
|
|
@@ -139,7 +141,7 @@ function checkPageDir(dir, relativePath, ns, type) {
|
|
|
139
141
|
}
|
|
140
142
|
});
|
|
141
143
|
let nextPageDesc;
|
|
142
|
-
if (hasNative || hasWeb ||
|
|
144
|
+
if (hasNative || hasWeb || hasMiniProgram) {
|
|
143
145
|
const indexJsonFile = join(dir, 'index.json');
|
|
144
146
|
let oakDisablePulldownRefresh = false;
|
|
145
147
|
let routePath;
|
|
@@ -172,7 +174,7 @@ function checkPageDir(dir, relativePath, ns, type) {
|
|
|
172
174
|
oakDisablePulldownRefresh,
|
|
173
175
|
hasNative,
|
|
174
176
|
hasWeb,
|
|
175
|
-
|
|
177
|
+
hasMiniProgram,
|
|
176
178
|
access,
|
|
177
179
|
};
|
|
178
180
|
}
|
|
@@ -547,7 +549,7 @@ function makeWebAllRouters(namespaceDir, projectDir, routerFileDir, options) {
|
|
|
547
549
|
oakDisablePulldownRefresh: false,
|
|
548
550
|
hasWeb: true,
|
|
549
551
|
hasNative: false,
|
|
550
|
-
|
|
552
|
+
hasMiniProgram: false,
|
|
551
553
|
};
|
|
552
554
|
children.push(factory.createObjectLiteralExpression([
|
|
553
555
|
factory.createPropertyAssignment('path', factory.createStringLiteral('*')),
|
|
@@ -744,7 +746,7 @@ function watchDir(projectDir, startupDir, type) {
|
|
|
744
746
|
BuildRouterContext.watchHandles.push(handle);
|
|
745
747
|
}
|
|
746
748
|
};
|
|
747
|
-
if (
|
|
749
|
+
if (type === 'web') {
|
|
748
750
|
const srcAppDir = join(projectDir, startupDir, 'src', 'app');
|
|
749
751
|
const namespaceDir = join(srcAppDir, 'namespaces');
|
|
750
752
|
const tryOutputAppDir = (ns) => {
|
|
@@ -827,11 +829,12 @@ export function buildRouter(projectDir, startupDir, watch, options) {
|
|
|
827
829
|
BuildRouterContext.options = options;
|
|
828
830
|
BuildRouterContext.warnedInvalidDirs = new Set();
|
|
829
831
|
BuildRouterContext.warnedRouteConflicts = new Set();
|
|
830
|
-
const
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
832
|
+
const platform = options.platform === 'wechatMp'
|
|
833
|
+
? 'miniProgram'
|
|
834
|
+
: options.platform;
|
|
835
|
+
traversePageDir(projectDir, platform);
|
|
836
|
+
assert(existsSync(join(projectDir, startupDir)));
|
|
837
|
+
if (platform === 'web') {
|
|
835
838
|
outputInWebDir(join(projectDir, startupDir));
|
|
836
839
|
}
|
|
837
840
|
// todo native
|
|
@@ -844,7 +847,7 @@ export function buildRouter(projectDir, startupDir, watch, options) {
|
|
|
844
847
|
markerFile,
|
|
845
848
|
};
|
|
846
849
|
writeFileSync(BuildRouterContext.watchSession.markerFile, JSON.stringify({ token: BuildRouterContext.watchSession.token }), 'utf-8');
|
|
847
|
-
watchDir(projectDir, startupDir,
|
|
850
|
+
watchDir(projectDir, startupDir, platform);
|
|
848
851
|
return {
|
|
849
852
|
close: closeCurrentWatchSession,
|
|
850
853
|
};
|
|
@@ -44,11 +44,15 @@ type ParsedIndexAttribute = {
|
|
|
44
44
|
};
|
|
45
45
|
type ParsedIndexConfig = {
|
|
46
46
|
unique?: boolean;
|
|
47
|
-
type?: string;
|
|
48
47
|
parser?: string;
|
|
49
48
|
tsConfig?: string | string[];
|
|
50
49
|
chineseParser?: string;
|
|
51
50
|
include?: string[];
|
|
51
|
+
type?: 'fulltext' | 'btree' | 'hash' | 'spatial';
|
|
52
|
+
spatial?: {
|
|
53
|
+
distanceModel: 'planar' | 'geodesic';
|
|
54
|
+
srid?: number;
|
|
55
|
+
};
|
|
52
56
|
};
|
|
53
57
|
type ParsedIndex = {
|
|
54
58
|
name: string;
|
|
@@ -1520,6 +1520,16 @@ function parseIndexesExpression(filename, moduleName, declaration, schemaAttrDic
|
|
|
1520
1520
|
const configProperty = getEntityDescProperty(element, 'config');
|
|
1521
1521
|
const config = configProperty ? readStaticValue(configProperty.initializer, filename, `indexes.${name}.config`) : undefined;
|
|
1522
1522
|
const isFulltext = config?.type === 'fulltext';
|
|
1523
|
+
if (config?.spatial) {
|
|
1524
|
+
assert(config.type === 'spatial', `「${filename}」索引「${name}」的 spatial 描述只能用于 spatial 索引`);
|
|
1525
|
+
assert(['planar', 'geodesic'].includes(config.spatial.distanceModel), `「${filename}」索引「${name}」的 spatial.distanceModel 非法`);
|
|
1526
|
+
if (config.spatial.srid !== undefined) {
|
|
1527
|
+
assert(Number.isInteger(config.spatial.srid) && config.spatial.srid > 0, `「${filename}」索引「${name}」的 spatial.srid 必须是正整数`);
|
|
1528
|
+
}
|
|
1529
|
+
if (config.spatial.distanceModel === 'geodesic') {
|
|
1530
|
+
assert(attributesProperty.initializer.elements.length === 1, `「${filename}」地球测地线索引「${name}」必须只声明一个坐标属性`);
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1523
1533
|
const attributes = parseIndexAttributes(filename, moduleName, name, attributesProperty.initializer, schemaAttrDict, isFulltext);
|
|
1524
1534
|
return {
|
|
1525
1535
|
name,
|
|
@@ -4,6 +4,8 @@ import { EntityDict as BaseEntityDict } from "../types/Entity";
|
|
|
4
4
|
import { AsyncContext } from '../store/AsyncRowStore';
|
|
5
5
|
import { SerializedData } from "./SerializedData";
|
|
6
6
|
export declare abstract class BackendRuntimeContext<ED extends EntityDict & BaseEntityDict> extends AsyncContext<ED> {
|
|
7
|
+
getAspectName(): string | undefined;
|
|
8
|
+
setAspectName(aspectName?: string): void;
|
|
7
9
|
private subscriberId?;
|
|
8
10
|
private be?;
|
|
9
11
|
private locale?;
|
|
@@ -17,7 +19,13 @@ export declare abstract class BackendRuntimeContext<ED extends EntityDict & Base
|
|
|
17
19
|
getBriefEnvironment(): BriefEnv | undefined;
|
|
18
20
|
getLocale(): string | undefined;
|
|
19
21
|
protected getSerializedData(): Promise<SerializedData>;
|
|
20
|
-
|
|
22
|
+
/**
|
|
23
|
+
* @param data 序列化上下文数据
|
|
24
|
+
* @param later 受信服务端回放标记。来自客户端的上下文串只允许携带受限字段;
|
|
25
|
+
* rm/userId 等受信字段只能在本进程自己生成的回放(volatile trigger、
|
|
26
|
+
* 测试加载器等)中以 later=true 传入。
|
|
27
|
+
*/
|
|
28
|
+
initialize(data?: SerializedData, later?: boolean): Promise<void>;
|
|
21
29
|
/**
|
|
22
30
|
* 未来可以支持在 event 中带 id 的占位符,到 saveOpRecord 时再动态注入 by Xc
|
|
23
31
|
* @param operationId
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { assert } from '../utils/assert';
|
|
2
2
|
import { AsyncContext } from '../store/AsyncRowStore';
|
|
3
3
|
export class BackendRuntimeContext extends AsyncContext {
|
|
4
|
+
getAspectName() {
|
|
5
|
+
return super.getAspectName();
|
|
6
|
+
}
|
|
7
|
+
setAspectName(aspectName) {
|
|
8
|
+
super.setAspectName(aspectName);
|
|
9
|
+
}
|
|
4
10
|
subscriberId;
|
|
5
11
|
be;
|
|
6
12
|
locale;
|
|
@@ -28,7 +34,13 @@ export class BackendRuntimeContext extends AsyncContext {
|
|
|
28
34
|
ns: this.ns,
|
|
29
35
|
};
|
|
30
36
|
}
|
|
31
|
-
|
|
37
|
+
/**
|
|
38
|
+
* @param data 序列化上下文数据
|
|
39
|
+
* @param later 受信服务端回放标记。来自客户端的上下文串只允许携带受限字段;
|
|
40
|
+
* rm/userId 等受信字段只能在本进程自己生成的回放(volatile trigger、
|
|
41
|
+
* 测试加载器等)中以 later=true 传入。
|
|
42
|
+
*/
|
|
43
|
+
async initialize(data, later) {
|
|
32
44
|
if (data?.sid) {
|
|
33
45
|
this.subscriberId = data.sid;
|
|
34
46
|
}
|
package/es/entities/Log.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { String } from "../types/DataType";
|
|
2
2
|
import { EntityShape } from "../types/Entity";
|
|
3
3
|
import { EntityDesc } from "../types/EntityDesc";
|
|
4
|
+
import { Schema as Version } from "./Version";
|
|
4
5
|
export interface Schema extends EntityShape {
|
|
5
6
|
entity: String<32>;
|
|
6
7
|
entityId: String<64>;
|
|
8
|
+
version?: Version;
|
|
7
9
|
iState: 'normal' | 'rollbacked';
|
|
8
10
|
}
|
|
9
11
|
export type IAction = 'undo' | 'redo';
|
package/es/entities/Log.js
CHANGED
|
@@ -6,6 +6,7 @@ export const entityDesc = {
|
|
|
6
6
|
attr: {
|
|
7
7
|
entity: '关联对象',
|
|
8
8
|
entityId: '关联对象ID',
|
|
9
|
+
version: '所属版本',
|
|
9
10
|
iState: '状态'
|
|
10
11
|
},
|
|
11
12
|
action: {
|
|
@@ -24,6 +25,7 @@ export const entityDesc = {
|
|
|
24
25
|
attr: {
|
|
25
26
|
entity: 'Entity',
|
|
26
27
|
entityId: 'Entity ID',
|
|
28
|
+
version: 'Version',
|
|
27
29
|
iState: 'Status',
|
|
28
30
|
},
|
|
29
31
|
action: {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { String } from "../types/DataType";
|
|
2
|
+
import { EntityShape } from "../types/Entity";
|
|
3
|
+
import { Schema as User } from "./User";
|
|
4
|
+
import { Schema as Log } from "./Log";
|
|
5
|
+
export interface Schema extends EntityShape {
|
|
6
|
+
entity: String<32>;
|
|
7
|
+
entityId: String<64>;
|
|
8
|
+
name: String<128>;
|
|
9
|
+
operator?: User;
|
|
10
|
+
log?: Log;
|
|
11
|
+
iState: 'normal' | 'rollbacked';
|
|
12
|
+
}
|
|
13
|
+
export type IAction = 'undo' | 'redo';
|
|
14
|
+
export type Action = IAction;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
;
|
|
2
|
+
const entityDesc = {
|
|
3
|
+
locales: {
|
|
4
|
+
zh_CN: {
|
|
5
|
+
name: '版本',
|
|
6
|
+
attr: {
|
|
7
|
+
entity: '关联对象',
|
|
8
|
+
entityId: '关联对象ID',
|
|
9
|
+
name: '名称',
|
|
10
|
+
operator: '操作者',
|
|
11
|
+
log: '日志',
|
|
12
|
+
iState: '状态',
|
|
13
|
+
},
|
|
14
|
+
action: { undo: '回滚', redo: '重做' },
|
|
15
|
+
v: { iState: { normal: '正常的', rollbacked: '已回滚' } },
|
|
16
|
+
},
|
|
17
|
+
en_US: {
|
|
18
|
+
name: 'Version',
|
|
19
|
+
attr: {
|
|
20
|
+
entity: 'Entity',
|
|
21
|
+
entityId: 'Entity ID',
|
|
22
|
+
name: 'Name',
|
|
23
|
+
operator: 'Operator',
|
|
24
|
+
log: 'Log',
|
|
25
|
+
iState: 'Status',
|
|
26
|
+
},
|
|
27
|
+
action: { undo: 'Undo', redo: 'Redo' },
|
|
28
|
+
v: { iState: { normal: 'Normal', rollbacked: 'Rolled back' } },
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
indexes: [
|
|
32
|
+
{
|
|
33
|
+
name: 'index_log_unique',
|
|
34
|
+
attributes: [{ name: 'log' }],
|
|
35
|
+
config: { unique: true },
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
style: {
|
|
39
|
+
icon: { undo: '', redo: '' },
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
export {};
|
|
@@ -9,6 +9,7 @@ export declare abstract class AsyncContext<ED extends EntityDict & BaseEntityDic
|
|
|
9
9
|
private uuid?;
|
|
10
10
|
opRecords: OpRecord<ED>[];
|
|
11
11
|
private scene?;
|
|
12
|
+
private aspectName?;
|
|
12
13
|
headers?: IncomingHttpHeaders;
|
|
13
14
|
clusterInfo?: ClusterInfo;
|
|
14
15
|
opResult: OperationResult<ED>;
|
|
@@ -25,6 +26,8 @@ export declare abstract class AsyncContext<ED extends EntityDict & BaseEntityDic
|
|
|
25
26
|
restartToExecute(routine: (context: this) => Promise<any>): Promise<void>;
|
|
26
27
|
getHeader(key: string): string | string[] | undefined;
|
|
27
28
|
getScene(): string | undefined;
|
|
29
|
+
getAspectName(): string | undefined;
|
|
30
|
+
setAspectName(aspectName?: string): void;
|
|
28
31
|
setScene(scene?: string): void;
|
|
29
32
|
private resetEvents;
|
|
30
33
|
on(event: 'commit' | 'rollback', callback: (records: OpRecord<ED>[], cxtStr: string) => Promise<void>): void;
|
|
@@ -53,7 +56,7 @@ export declare abstract class AsyncContext<ED extends EntityDict & BaseEntityDic
|
|
|
53
56
|
setMessage(message: string): void;
|
|
54
57
|
getMessage(): string | undefined;
|
|
55
58
|
abstract isRoot(): boolean;
|
|
56
|
-
abstract getCurrentUserId<T extends boolean>(allowUnloggedIn?: T): T extends true ? string | undefined : string;
|
|
59
|
+
abstract getCurrentUserId<T extends boolean = false>(allowUnloggedIn?: T): T extends true ? string | undefined : string;
|
|
57
60
|
abstract setCurrentUserId(userId: string | undefined): void;
|
|
58
61
|
abstract toString(): Promise<string>;
|
|
59
62
|
protected abstract getSerializedData(): Promise<object>;
|
|
@@ -10,6 +10,7 @@ export class AsyncContext {
|
|
|
10
10
|
uuid;
|
|
11
11
|
opRecords;
|
|
12
12
|
scene;
|
|
13
|
+
aspectName;
|
|
13
14
|
headers;
|
|
14
15
|
clusterInfo;
|
|
15
16
|
opResult;
|
|
@@ -53,6 +54,12 @@ export class AsyncContext {
|
|
|
53
54
|
getScene() {
|
|
54
55
|
return this.scene;
|
|
55
56
|
}
|
|
57
|
+
getAspectName() {
|
|
58
|
+
return this.aspectName;
|
|
59
|
+
}
|
|
60
|
+
setAspectName(aspectName) {
|
|
61
|
+
this.aspectName = aspectName;
|
|
62
|
+
}
|
|
56
63
|
setScene(scene) {
|
|
57
64
|
this.scene = scene;
|
|
58
65
|
}
|
package/es/store/CascadeStore.js
CHANGED
|
@@ -119,6 +119,13 @@ export function polishSelection(schema, entity, selection, context, option) {
|
|
|
119
119
|
const checkSortAttr = (e2, sortAttr, projNode) => {
|
|
120
120
|
const necessaryAttrs = [];
|
|
121
121
|
for (const attr in sortAttr) {
|
|
122
|
+
if (attr.toLowerCase().startsWith(EXPRESSION_PREFIX)) {
|
|
123
|
+
const expressionAttrs = getAttrRefInExpression(sortAttr[attr]);
|
|
124
|
+
const expressionNodes = Object.keys(expressionAttrs);
|
|
125
|
+
assert(expressionNodes.every((nodeName) => nodeName === '#current'), 'sorter expression only supports attributes on the current node');
|
|
126
|
+
necessaryAttrs.push(...(expressionAttrs['#current'] || []));
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
122
129
|
const rel = judgeRelation(schema, e2, attr);
|
|
123
130
|
if (typeof rel === 'number' && [0, 1].includes(rel)) {
|
|
124
131
|
necessaryAttrs.push(attr);
|
|
@@ -232,6 +239,21 @@ export function polishSelection(schema, entity, selection, context, option) {
|
|
|
232
239
|
// 如果对象上有relation关系,在此将本用户相关的relation和actionAuth全部取出
|
|
233
240
|
// 还要将actionAuth上没有relation关系但destEntity为本对象的行也全部取出,这些是指向userId的可能路径
|
|
234
241
|
// 放在这里有点怪异,暂先这样
|
|
242
|
+
// 前端回放只凭目标 Version/Log 是否存在来判断“从目标到历史末端”的数据是否已经取全。
|
|
243
|
+
// 因此普通 Aspect 不能把一段不完整的历史关联写入 Cache,否则 replayVersion 会把残缺数据
|
|
244
|
+
// 当成完整历史。这里复用 projection 原有的递归过程逐层检查,不需要再遍历一次整棵 projection。
|
|
245
|
+
// getVersionData 会一次返回完整历史链;dontCollect 查询不会进入前端 Cache,二者均可放行。
|
|
246
|
+
const aspectName = context?.getAspectName();
|
|
247
|
+
if (aspectName && aspectName !== 'getVersionData' && !option?.dontCollect) {
|
|
248
|
+
assert(entity2 !== 'oper' || !Object.prototype.hasOwnProperty.call(projectionNode, 'logId'), 'oper.logId and oper.log can only be selected by getVersionData');
|
|
249
|
+
assert(entity2 !== 'version'
|
|
250
|
+
|| (!Object.prototype.hasOwnProperty.call(projectionNode, 'log')
|
|
251
|
+
&& !Object.prototype.hasOwnProperty.call(projectionNode, 'log$version')), 'version.log and version.log$version can only be selected by getVersionData');
|
|
252
|
+
assert(entity2 !== 'log'
|
|
253
|
+
|| (!Object.prototype.hasOwnProperty.call(projectionNode, 'version')
|
|
254
|
+
&& !Object.prototype.hasOwnProperty.call(projectionNode, 'version$log')
|
|
255
|
+
&& !Object.prototype.hasOwnProperty.call(projectionNode, 'oper$log')), 'log.version, log.version$log and log.oper$log can only be selected by getVersionData');
|
|
256
|
+
}
|
|
235
257
|
if (context && !option?.dontCollect) {
|
|
236
258
|
const userId = context.getCurrentUserId(true);
|
|
237
259
|
if (userId && !SYSTEM_RESERVE_ENTITIES.includes(entity2)) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EntityDict } from '../../base-app-domain';
|
|
2
|
+
import { EntityDict as BaseEntityDict, StorageSchema } from '../../types';
|
|
3
|
+
/** 稳定序列化 filter,用于授权分支去重;循环引用只保留为不透明节点。 */
|
|
4
|
+
export declare const stableFilterKey: (value: unknown, ancestors?: WeakSet<object>) => string;
|
|
5
|
+
/** 检测用户传入或缓存中的授权 filter 是否带循环引用。 */
|
|
6
|
+
export declare const hasCyclicFilter: (value: unknown, ancestors?: WeakSet<object>) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* 在不改变授权集合的前提下裁剪 OR 分支(§3.3 授权合成只减少查询,不扩大权限)。
|
|
9
|
+
* 对授权过滤器集合 P_i,有 ⋃ P_i = ⋃ {P_i | 不存在 P_i ⊆ P_j 且 i ≠ j}。
|
|
10
|
+
*/
|
|
11
|
+
export declare function minimizeAuthorizationUnion<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(entity: T, schema: StorageSchema<ED>, filters: ED[T]['Filter'][]): ED[T]['Filter'][];
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { contains } from '../filter.fix';
|
|
2
|
+
/** 稳定序列化 filter,用于授权分支去重;循环引用只保留为不透明节点。 */
|
|
3
|
+
export const stableFilterKey = (value, ancestors = new WeakSet()) => {
|
|
4
|
+
if (value === null) {
|
|
5
|
+
return 'null';
|
|
6
|
+
}
|
|
7
|
+
if (value === undefined) {
|
|
8
|
+
return 'undefined';
|
|
9
|
+
}
|
|
10
|
+
if (typeof value === 'number') {
|
|
11
|
+
if (Number.isNaN(value)) {
|
|
12
|
+
return 'number:NaN';
|
|
13
|
+
}
|
|
14
|
+
if (value === Infinity) {
|
|
15
|
+
return 'number:Infinity';
|
|
16
|
+
}
|
|
17
|
+
if (value === -Infinity) {
|
|
18
|
+
return 'number:-Infinity';
|
|
19
|
+
}
|
|
20
|
+
return `number:${Object.is(value, -0) ? '-0' : String(value)}`;
|
|
21
|
+
}
|
|
22
|
+
if (typeof value === 'string') {
|
|
23
|
+
return `string:${JSON.stringify(value)}`;
|
|
24
|
+
}
|
|
25
|
+
if (typeof value === 'boolean') {
|
|
26
|
+
return `boolean:${value}`;
|
|
27
|
+
}
|
|
28
|
+
if (typeof value === 'bigint') {
|
|
29
|
+
return `bigint:${value.toString()}`;
|
|
30
|
+
}
|
|
31
|
+
if (value instanceof Date) {
|
|
32
|
+
return `Date(${value.getTime()})`;
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(value)) {
|
|
35
|
+
if (ancestors.has(value)) {
|
|
36
|
+
console.warn('RelationAuth: cyclic authorization filter; keeping the branch opaque');
|
|
37
|
+
return '[Circular]';
|
|
38
|
+
}
|
|
39
|
+
ancestors.add(value);
|
|
40
|
+
try {
|
|
41
|
+
return `[${value.map((item) => stableFilterKey(item, ancestors)).join(',')}]`;
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
ancestors.delete(value);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (value && typeof value === 'object') {
|
|
48
|
+
if (ancestors.has(value)) {
|
|
49
|
+
console.warn('RelationAuth: cyclic authorization filter; keeping the branch opaque');
|
|
50
|
+
return '{Circular}';
|
|
51
|
+
}
|
|
52
|
+
ancestors.add(value);
|
|
53
|
+
try {
|
|
54
|
+
const record = value;
|
|
55
|
+
return `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${stableFilterKey(record[key], ancestors)}`).join(',')}}`;
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
ancestors.delete(value);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return JSON.stringify(value) ?? String(value);
|
|
62
|
+
};
|
|
63
|
+
/** 检测用户传入或缓存中的授权 filter 是否带循环引用。 */
|
|
64
|
+
export const hasCyclicFilter = (value, ancestors = new WeakSet()) => {
|
|
65
|
+
if (!value || typeof value !== 'object' || value instanceof Date) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
if (ancestors.has(value)) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
ancestors.add(value);
|
|
72
|
+
try {
|
|
73
|
+
if (Array.isArray(value)) {
|
|
74
|
+
return value.some((item) => hasCyclicFilter(item, ancestors));
|
|
75
|
+
}
|
|
76
|
+
return Object.values(value).some((item) => hasCyclicFilter(item, ancestors));
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
ancestors.delete(value);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* 在不改变授权集合的前提下裁剪 OR 分支(§3.3 授权合成只减少查询,不扩大权限)。
|
|
84
|
+
* 对授权过滤器集合 P_i,有 ⋃ P_i = ⋃ {P_i | 不存在 P_i ⊆ P_j 且 i ≠ j}。
|
|
85
|
+
*/
|
|
86
|
+
export function minimizeAuthorizationUnion(entity, schema, filters) {
|
|
87
|
+
if (filters.some((filter) => hasCyclicFilter(filter))) {
|
|
88
|
+
console.warn('RelationAuth: cyclic authorization filter; preserving all authorization branches');
|
|
89
|
+
return filters;
|
|
90
|
+
}
|
|
91
|
+
const unique = [...new Map(filters.map((filter) => [stableFilterKey(filter), filter])).values()];
|
|
92
|
+
return unique.filter((candidate, candidateIndex) => unique.every((other, otherIndex) => {
|
|
93
|
+
if (candidateIndex === otherIndex) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
if (contains(entity, schema, candidate, other) !== true) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
if (contains(entity, schema, other, candidate) === true) {
|
|
100
|
+
return otherIndex < candidateIndex;
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** IO 叶子的结果形态:同步上下文为 T,异步上下文为 Promise<T>。 */
|
|
2
|
+
export type Tr<T> = T | Promise<T>;
|
|
3
|
+
/**
|
|
4
|
+
* 单源接续子:value 为 Promise 时链接续延,否则同步求值;续延返回 Promise 时结果扁平化。
|
|
5
|
+
* 同步链路全程不产生 Promise。
|
|
6
|
+
*/
|
|
7
|
+
export declare function bind<R, S>(value: Tr<R>, next: (v: R) => S | Promise<S>): Tr<S>;
|
|
8
|
+
/** 顺序串联(保序):全部同步 ⇒ 同步结果,不产生 Promise。 */
|
|
9
|
+
export declare function allBind<T, R>(values: Tr<T>[], next: (v: T[]) => R | Promise<R>): Tr<R>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 单源接续子:value 为 Promise 时链接续延,否则同步求值;续延返回 Promise 时结果扁平化。
|
|
3
|
+
* 同步链路全程不产生 Promise。
|
|
4
|
+
*/
|
|
5
|
+
export function bind(value, next) {
|
|
6
|
+
if (value instanceof Promise) {
|
|
7
|
+
return value.then((v) => {
|
|
8
|
+
const r = next(v);
|
|
9
|
+
return r instanceof Promise ? r : r;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
const r = next(value);
|
|
13
|
+
return r instanceof Promise ? r : r;
|
|
14
|
+
}
|
|
15
|
+
/** 顺序串联(保序):全部同步 ⇒ 同步结果,不产生 Promise。 */
|
|
16
|
+
export function allBind(values, next) {
|
|
17
|
+
const result = [];
|
|
18
|
+
let index = 0;
|
|
19
|
+
const step = () => {
|
|
20
|
+
while (index < values.length) {
|
|
21
|
+
const current = values[index++];
|
|
22
|
+
if (current instanceof Promise) {
|
|
23
|
+
return current.then((v) => {
|
|
24
|
+
result.push(v);
|
|
25
|
+
return step();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
result.push(current);
|
|
29
|
+
}
|
|
30
|
+
return next(result);
|
|
31
|
+
};
|
|
32
|
+
return step();
|
|
33
|
+
}
|