oak-domain 6.1.0 → 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.
Files changed (161) hide show
  1. package/es/base-app-domain/ActionDefDict.d.ts +1 -0
  2. package/es/base-app-domain/ActionDefDict.js +3 -1
  3. package/es/base-app-domain/EntityDict.d.ts +86 -1
  4. package/es/base-app-domain/Log/Storage.js +4 -0
  5. package/es/base-app-domain/Log/_baseSchema.d.ts +5 -0
  6. package/es/base-app-domain/Storage.js +3 -1
  7. package/es/base-app-domain/StyleDict.js +3 -1
  8. package/es/base-app-domain/Version/Action.d.ts +6 -0
  9. package/es/base-app-domain/Version/Action.js +2 -0
  10. package/es/base-app-domain/Version/Schema.d.ts +19 -0
  11. package/es/base-app-domain/Version/Schema.js +1 -0
  12. package/es/base-app-domain/Version/Storage.d.ts +3 -0
  13. package/es/base-app-domain/Version/Storage.js +54 -0
  14. package/es/base-app-domain/Version/Style.d.ts +3 -0
  15. package/es/base-app-domain/Version/Style.js +6 -0
  16. package/es/base-app-domain/Version/_baseSchema.d.ts +57 -0
  17. package/es/base-app-domain/Version/_baseSchema.js +1 -0
  18. package/es/compiler/dependencyBuilder.d.ts +1 -0
  19. package/es/compiler/dependencyBuilder.js +173 -55
  20. package/es/compiler/routerBuilder.d.ts +4 -1
  21. package/es/compiler/routerBuilder.js +22 -19
  22. package/es/compiler/schemaBuilder.d.ts +5 -1
  23. package/es/compiler/schemaBuilder.js +10 -0
  24. package/es/context/BackendRuntimeContext.d.ts +9 -1
  25. package/es/context/BackendRuntimeContext.js +13 -1
  26. package/es/entities/Log.d.ts +2 -0
  27. package/es/entities/Log.js +2 -0
  28. package/es/entities/Version.d.ts +14 -0
  29. package/es/entities/Version.js +42 -0
  30. package/es/store/AsyncRowStore.d.ts +4 -1
  31. package/es/store/AsyncRowStore.js +7 -0
  32. package/es/store/CascadeStore.js +22 -0
  33. package/es/store/RelationAuth/authorizationFilter.d.ts +11 -0
  34. package/es/store/RelationAuth/authorizationFilter.js +104 -0
  35. package/es/store/RelationAuth/continuation.d.ts +9 -0
  36. package/es/store/RelationAuth/continuation.js +33 -0
  37. package/es/store/RelationAuth/index.d.ts +141 -0
  38. package/es/store/RelationAuth/index.js +1440 -0
  39. package/es/store/RelationAuth/model.d.ts +38 -0
  40. package/es/store/RelationAuth/model.js +24 -0
  41. package/es/store/RelationAuth/userLookup.d.ts +21 -0
  42. package/es/store/RelationAuth/userLookup.js +102 -0
  43. package/es/store/SyncRowStore.d.ts +2 -1
  44. package/es/store/SyncRowStore.js +3 -0
  45. package/es/store/filter.fix.d.ts +128 -0
  46. package/es/store/filter.fix.js +2862 -0
  47. package/es/store/filter.js +14 -9
  48. package/es/store/triggers.js +239 -44
  49. package/es/types/Context.d.ts +2 -1
  50. package/es/types/Demand.d.ts +11 -1
  51. package/es/types/Environment.d.ts +13 -2
  52. package/es/types/Exception.d.ts +3 -3
  53. package/es/types/Exception.js +25 -22
  54. package/es/types/Expression.d.ts +4 -1
  55. package/es/types/Expression.js +1 -1
  56. package/es/types/Storage.d.ts +15 -2
  57. package/es/utils/SimpleConnector.js +5 -2
  58. package/es/utils/decimal.js +2 -1
  59. package/es/utils/fetch/index.ali.d.ts +3 -0
  60. package/es/utils/fetch/index.ali.js +31 -0
  61. package/es/utils/fetch/index.d.ts +3 -0
  62. package/es/utils/fetch/index.js +5 -0
  63. package/es/utils/fetch/index.mp.d.ts +5 -3
  64. package/es/utils/fetch/index.mp.js +5 -280
  65. package/es/utils/fetch/index.wechat.d.ts +5 -0
  66. package/es/utils/fetch/index.wechat.js +174 -0
  67. package/es/utils/fetch/mini-program.shared.d.ts +37 -0
  68. package/es/utils/fetch/mini-program.shared.js +85 -0
  69. package/es/utils/geo.d.ts +1 -1
  70. package/es/utils/geo.js +1 -1
  71. package/es/utils/random/random.ali.d.ts +6 -0
  72. package/es/utils/random/random.ali.js +21 -0
  73. package/es/utils/random/random.mp.d.ts +5 -1
  74. package/es/utils/random/random.mp.js +11 -5
  75. package/es/utils/random/random.native.d.ts +1 -1
  76. package/es/utils/random/random.native.js +7 -4
  77. package/es/utils/random/random.wechat.d.ts +1 -0
  78. package/es/utils/random/random.wechat.js +10 -0
  79. package/lib/base-app-domain/ActionDefDict.d.ts +1 -0
  80. package/lib/base-app-domain/ActionDefDict.js +3 -1
  81. package/lib/base-app-domain/EntityDict.d.ts +86 -1
  82. package/lib/base-app-domain/Log/Storage.js +4 -0
  83. package/lib/base-app-domain/Log/_baseSchema.d.ts +5 -0
  84. package/lib/base-app-domain/Storage.js +3 -1
  85. package/lib/base-app-domain/StyleDict.js +3 -1
  86. package/lib/base-app-domain/Version/Action.d.ts +6 -0
  87. package/lib/base-app-domain/Version/Action.js +5 -0
  88. package/lib/base-app-domain/Version/Schema.d.ts +19 -0
  89. package/lib/base-app-domain/Version/Schema.js +4 -0
  90. package/lib/base-app-domain/Version/Storage.d.ts +3 -0
  91. package/lib/base-app-domain/Version/Storage.js +57 -0
  92. package/lib/base-app-domain/Version/Style.d.ts +3 -0
  93. package/lib/base-app-domain/Version/Style.js +9 -0
  94. package/lib/base-app-domain/Version/_baseSchema.d.ts +57 -0
  95. package/lib/base-app-domain/Version/_baseSchema.js +2 -0
  96. package/lib/compiler/dependencyBuilder.d.ts +1 -0
  97. package/lib/compiler/dependencyBuilder.js +173 -54
  98. package/lib/compiler/routerBuilder.d.ts +4 -1
  99. package/lib/compiler/routerBuilder.js +22 -19
  100. package/lib/compiler/schemaBuilder.d.ts +5 -1
  101. package/lib/compiler/schemaBuilder.js +10 -0
  102. package/lib/context/BackendRuntimeContext.d.ts +9 -1
  103. package/lib/context/BackendRuntimeContext.js +13 -1
  104. package/lib/entities/Log.d.ts +2 -0
  105. package/lib/entities/Log.js +2 -0
  106. package/lib/entities/Version.d.ts +14 -0
  107. package/lib/entities/Version.js +43 -0
  108. package/lib/store/AsyncRowStore.d.ts +4 -1
  109. package/lib/store/AsyncRowStore.js +7 -0
  110. package/lib/store/CascadeStore.js +22 -0
  111. package/lib/store/RelationAuth/authorizationFilter.d.ts +11 -0
  112. package/lib/store/RelationAuth/authorizationFilter.js +110 -0
  113. package/lib/store/RelationAuth/continuation.d.ts +9 -0
  114. package/lib/store/RelationAuth/continuation.js +37 -0
  115. package/lib/store/RelationAuth/index.d.ts +141 -0
  116. package/lib/store/RelationAuth/index.js +1445 -0
  117. package/lib/store/RelationAuth/model.d.ts +38 -0
  118. package/lib/store/RelationAuth/model.js +27 -0
  119. package/lib/store/RelationAuth/userLookup.d.ts +21 -0
  120. package/lib/store/RelationAuth/userLookup.js +105 -0
  121. package/lib/store/SyncRowStore.d.ts +2 -1
  122. package/lib/store/SyncRowStore.js +3 -0
  123. package/lib/store/filter.fix.d.ts +128 -0
  124. package/lib/store/filter.fix.js +2876 -0
  125. package/lib/store/filter.js +14 -9
  126. package/lib/store/triggers.js +239 -44
  127. package/lib/types/Context.d.ts +2 -1
  128. package/lib/types/Demand.d.ts +11 -1
  129. package/lib/types/Environment.d.ts +13 -2
  130. package/lib/types/Exception.d.ts +3 -3
  131. package/lib/types/Exception.js +25 -22
  132. package/lib/types/Expression.d.ts +4 -1
  133. package/lib/types/Expression.js +1 -1
  134. package/lib/types/Storage.d.ts +15 -2
  135. package/lib/utils/SimpleConnector.js +5 -2
  136. package/lib/utils/decimal.js +2 -1
  137. package/lib/utils/fetch/index.ali.d.ts +3 -0
  138. package/lib/utils/fetch/index.ali.js +36 -0
  139. package/lib/utils/fetch/index.d.ts +3 -0
  140. package/lib/utils/fetch/index.js +7 -0
  141. package/lib/utils/fetch/index.mp.d.ts +5 -3
  142. package/lib/utils/fetch/index.mp.js +5 -282
  143. package/lib/utils/fetch/index.wechat.d.ts +5 -0
  144. package/lib/utils/fetch/index.wechat.js +180 -0
  145. package/lib/utils/fetch/mini-program.shared.d.ts +37 -0
  146. package/lib/utils/fetch/mini-program.shared.js +96 -0
  147. package/lib/utils/geo.d.ts +1 -1
  148. package/lib/utils/geo.js +1 -1
  149. package/lib/utils/random/random.ali.d.ts +6 -0
  150. package/lib/utils/random/random.ali.js +24 -0
  151. package/lib/utils/random/random.mp.d.ts +5 -1
  152. package/lib/utils/random/random.mp.js +11 -5
  153. package/lib/utils/random/random.native.d.ts +1 -1
  154. package/lib/utils/random/random.native.js +7 -5
  155. package/lib/utils/random/random.wechat.d.ts +1 -0
  156. package/lib/utils/random/random.wechat.js +13 -0
  157. package/package.json +8 -5
  158. package/es/store/RelationAuth.d.ts +0 -115
  159. package/es/store/RelationAuth.js +0 -1340
  160. package/lib/store/RelationAuth.d.ts +0 -115
  161. package/lib/store/RelationAuth.js +0 -1345
@@ -1,5 +1,5 @@
1
1
  import { assert } from '../utils/assert';
2
- import { join as pathJoin } from 'path';
2
+ import { dirname, join as pathJoin } from 'path';
3
3
  import { existsSync, readFileSync, writeFileSync, readdirSync, statSync } from 'fs';
4
4
  import * as ts from 'typescript';
5
5
  import { firstLetterLowerCase, firstLetterUpperCase } from '../utils/string';
@@ -11,11 +11,30 @@ const PROJECT_NAME_PLACEHOLDER = '__OAK_PROJECT_NAME__';
11
11
  function uniqueDependencies(dependencies) {
12
12
  return Array.from(new Set(dependencies.filter((dep) => !!dep)));
13
13
  }
14
+ function resolveInstalledPackageDir(fromDir, packageName) {
15
+ let currentDir = fromDir;
16
+ while (true) {
17
+ const packageDir = join(currentDir, 'node_modules', packageName);
18
+ if (existsSync(join(packageDir, 'package.json'))) {
19
+ return packageDir;
20
+ }
21
+ const parentDir = dirname(currentDir);
22
+ if (parentDir === currentDir) {
23
+ return undefined;
24
+ }
25
+ currentDir = parentDir;
26
+ }
27
+ }
28
+ function writeGeneratedFile(filename, content) {
29
+ mkdirSync(dirname(filename), { recursive: true });
30
+ writeFileSync(filename, content, { flag: 'w' });
31
+ }
14
32
  function readInstalledPackageManifest(dir, packageName) {
15
- const packageJsonPath = join(dir, 'node_modules', packageName, 'package.json');
16
- if (!existsSync(packageJsonPath)) {
33
+ const packageDir = resolveInstalledPackageDir(dir, packageName);
34
+ if (!packageDir) {
17
35
  return undefined;
18
36
  }
37
+ const packageJsonPath = join(packageDir, 'package.json');
19
38
  return JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
20
39
  }
21
40
  function readDependencyConfiguration(dir) {
@@ -42,10 +61,11 @@ function collectInstalledOakLibDependencies(dir) {
42
61
  ...Object.keys(packageJson.devDependencies || {}),
43
62
  ]).sort((left, right) => left.localeCompare(right));
44
63
  return dependencyNames.filter((dep) => {
45
- const manifestPath = join(dir, 'node_modules', dep, 'package.json');
46
- if (!existsSync(manifestPath)) {
64
+ const packageDir = resolveInstalledPackageDir(dir, dep);
65
+ if (!packageDir) {
47
66
  return false;
48
67
  }
68
+ const manifestPath = join(packageDir, 'package.json');
49
69
  const dependencyManifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
50
70
  return isOakBusinessModule(dependencyManifest);
51
71
  });
@@ -142,12 +162,10 @@ export function analyzeDepedency(cwd) {
142
162
  depGraph.dependencies[name][dep] = 1;
143
163
  }
144
164
  if (!depGraph.nodes[dep]) {
145
- let dir2 = join(cwd, 'node_modules', dep);
146
- if (!existsSync(dir2)) {
147
- dir2 = join(dir, 'node_modules', dep);
148
- if (!existsSync(dir2)) {
149
- throw new Error(`找不到依赖包${dep}的安装位置,当前包是${dir}`);
150
- }
165
+ const dir2 = resolveInstalledPackageDir(dir, dep)
166
+ || resolveInstalledPackageDir(cwd, dep);
167
+ if (!dir2) {
168
+ throw new Error(`找不到依赖包${dep}的安装位置,当前包是${dir}`);
151
169
  }
152
170
  analyzeOne(dir2, dep);
153
171
  }
@@ -281,7 +299,7 @@ function outputPolyfillDts(dependencies, briefNames, sourceFile, printer, filena
281
299
  statements2 = [...sourceFile.statements];
282
300
  }
283
301
  const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
284
- writeFileSync(filename, result, { flag: 'w' });
302
+ writeGeneratedFile(filename, result);
285
303
  console.log(`构建${filename}文件成功`);
286
304
  }
287
305
  function outputDependentExceptions(dependencies, briefNames, sourceFile, printer, filename, isModule) {
@@ -323,7 +341,7 @@ function outputDependentExceptions(dependencies, briefNames, sourceFile, printer
323
341
  });
324
342
  }
325
343
  const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
326
- writeFileSync(filename, result, { flag: 'w' });
344
+ writeGeneratedFile(filename, result);
327
345
  console.log(`构建${filename}文件成功`);
328
346
  }
329
347
  function outputRuntimeCxt(dependencies, briefNames, sourceFile, printer, filename) {
@@ -381,7 +399,7 @@ function outputRuntimeCxt(dependencies, briefNames, sourceFile, printer, filenam
381
399
  ];
382
400
  }
383
401
  const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
384
- writeFileSync(filename, result, { flag: 'w' });
402
+ writeGeneratedFile(filename, result);
385
403
  console.log(`构建${filename}文件成功`);
386
404
  }
387
405
  function outputContext(depGraph, sourceFile, printer, filename) {
@@ -399,11 +417,14 @@ function outputContext(depGraph, sourceFile, printer, filename) {
399
417
  ...statements
400
418
  ];
401
419
  const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
402
- writeFileSync(filename, result, { flag: 'w' });
420
+ writeGeneratedFile(filename, result);
403
421
  console.log(`构建${filename}文件成功`);
404
422
  }
405
423
  function hasRuntimeContextEntry(cwd, dependency, target) {
406
- const dependencyDir = join(cwd, 'node_modules', dependency);
424
+ const dependencyDir = resolveInstalledPackageDir(cwd, dependency);
425
+ if (!dependencyDir) {
426
+ return false;
427
+ }
407
428
  const fileName = `${target}RuntimeContext`;
408
429
  return [
409
430
  join(dependencyDir, 'src', 'context', `${fileName}.ts`),
@@ -497,7 +518,7 @@ export default ${generatedName};
497
518
  }
498
519
  function outputGeneratedContext(cwd, target, isModule) {
499
520
  const fileName = join(cwd, 'src', 'context', `generated${target}.ts`);
500
- writeFileSync(fileName, renderGeneratedContextSource(cwd, target, isModule), { flag: 'w' });
521
+ writeGeneratedFile(fileName, renderGeneratedContextSource(cwd, target, isModule));
501
522
  console.log(`构建${fileName}文件成功`);
502
523
  }
503
524
  function outputProjectContextShell(templateFile, targetFile) {
@@ -505,7 +526,7 @@ function outputProjectContextShell(templateFile, targetFile) {
505
526
  console.log(`[${targetFile}]文件已经存在,保留项目自定义上下文。`);
506
527
  return;
507
528
  }
508
- writeFileSync(targetFile, readFileSync(templateFile, 'utf-8'), { flag: 'w' });
529
+ writeGeneratedFile(targetFile, readFileSync(templateFile, 'utf-8'));
509
530
  console.log(`构建${targetFile}文件成功`);
510
531
  }
511
532
  export function writeContextCompositionFiles(cwd, isModule, templates) {
@@ -532,9 +553,9 @@ function outputIntializeProd(cwd, dependencies, briefNames, sourceFile, printer,
532
553
  // 所有的import
533
554
  const importStatements = [];
534
555
  dependencies.forEach((dep, idx) => {
535
- const depDir = join(cwd, 'node_modules', dep);
536
- if (!existsSync(depDir)) {
537
- throw new Error(`依赖模块${dep}未能找到相应的安装目录【${depDir}】`);
556
+ const depDir = resolveInstalledPackageDir(cwd, dep);
557
+ if (!depDir) {
558
+ throw new Error(`依赖模块${dep}未能找到相应的安装目录`);
538
559
  }
539
560
  const esDir = join(depDir, 'es');
540
561
  const libDir = join(depDir, 'lib');
@@ -643,7 +664,7 @@ function outputIntializeProd(cwd, dependencies, briefNames, sourceFile, printer,
643
664
  });
644
665
  }
645
666
  const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
646
- writeFileSync(filename, result, { flag: 'w' });
667
+ writeGeneratedFile(filename, result);
647
668
  console.log(`构建${filename}文件成功`);
648
669
  }
649
670
  /**
@@ -660,9 +681,9 @@ function outputIntializeDev(cwd, dependencies, briefNames, sourceFile, printer,
660
681
  // 所有的import
661
682
  const importStatements = [];
662
683
  dependencies.forEach((dep, idx) => {
663
- const depDir = join(cwd, 'node_modules', dep);
664
- if (!existsSync(depDir)) {
665
- throw new Error(`依赖模块${dep}未能找到相应的安装目录【${depDir}】`);
684
+ const depDir = resolveInstalledPackageDir(cwd, dep);
685
+ if (!depDir) {
686
+ throw new Error(`依赖模块${dep}未能找到相应的安装目录`);
666
687
  }
667
688
  const esDir = join(depDir, 'es');
668
689
  const libDir = join(depDir, 'lib');
@@ -792,7 +813,7 @@ function outputIntializeDev(cwd, dependencies, briefNames, sourceFile, printer,
792
813
  });
793
814
  }
794
815
  const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
795
- writeFileSync(filename, result, { flag: 'w' });
816
+ writeGeneratedFile(filename, result);
796
817
  console.log(`构建${filename}文件成功`);
797
818
  }
798
819
  export function renderFeatureIndexSource(dependencies, briefNames, sourceFile, isModule, printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed })) {
@@ -866,12 +887,12 @@ export function renderFeatureIndexSource(dependencies, briefNames, sourceFile, i
866
887
  */
867
888
  function outputFeatureIndex(dependencies, briefNames, sourceFile, printer, filename, isModule) {
868
889
  const result = renderFeatureIndexSource(dependencies, briefNames, sourceFile, isModule, printer);
869
- writeFileSync(filename, result, { flag: 'w' });
890
+ writeGeneratedFile(filename, result);
870
891
  console.log(`构建${filename}文件成功`);
871
892
  }
872
893
  function outputIntializeFeatures(cwd, dependencies, briefNames, sourceFile, printer, filename) {
873
894
  const result = renderInitializeFeaturesSource(cwd, dependencies, briefNames, sourceFile, printer);
874
- writeFileSync(filename, result, { flag: 'w' });
895
+ writeGeneratedFile(filename, result);
875
896
  console.log(`构建${filename}文件成功`);
876
897
  }
877
898
  export function renderInitializeFeaturesSource(cwd, dependencies, briefNames, sourceFile, printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed })) {
@@ -879,9 +900,9 @@ export function renderInitializeFeaturesSource(cwd, dependencies, briefNames, so
879
900
  const features = [];
880
901
  const importStatements = [];
881
902
  dependencies.forEach((dep, idx) => {
882
- const depDir = join(cwd, 'node_modules', dep);
883
- if (!existsSync(depDir)) {
884
- throw new Error(`依赖模块${dep}未能找到相应的安装目录【${depDir}】`);
903
+ const depDir = resolveInstalledPackageDir(cwd, dep);
904
+ if (!depDir) {
905
+ throw new Error(`依赖模块${dep}未能找到相应的安装目录`);
885
906
  }
886
907
  const esDir = join(depDir, 'es');
887
908
  const libDir = join(depDir, 'lib');
@@ -923,10 +944,15 @@ export function renderInitializeFeaturesSource(cwd, dependencies, briefNames, so
923
944
  }
924
945
  export function resolveDependencyTemplateFile(cwd, dependencies, templateFileName, fallback) {
925
946
  const rootPlan = resolveDependencyRootPlan(cwd, dependencies);
926
- const candidates = rootPlan.rootDependencies.map((dependency) => ({
927
- dependency,
928
- filePath: join(cwd, 'node_modules', dependency, 'template', templateFileName),
929
- })).filter(({ filePath }) => existsSync(filePath));
947
+ const candidates = rootPlan.rootDependencies.map((dependency) => {
948
+ const dependencyDir = resolveInstalledPackageDir(cwd, dependency);
949
+ return {
950
+ dependency,
951
+ filePath: dependencyDir
952
+ ? join(dependencyDir, 'template', templateFileName)
953
+ : '',
954
+ };
955
+ }).filter(({ filePath }) => existsSync(filePath));
930
956
  if (candidates.length > 1) {
931
957
  throw new Error(`多个顶层依赖同时提供 template/${templateFileName}:${candidates.map(({ dependency }) => dependency).join(', ')},无法确定使用哪个模板`);
932
958
  }
@@ -935,7 +961,37 @@ export function resolveDependencyTemplateFile(cwd, dependencies, templateFileNam
935
961
  function injectDataIndexFile(dataIndexFile, briefNames, printer) {
936
962
  const sourceFile = ts.createSourceFile('index.ts', readFileSync(dataIndexFile, 'utf-8'), ts.ScriptTarget.Latest, false, ts.ScriptKind.TS);
937
963
  const { statements } = sourceFile;
938
- const importStatements = briefNames.map((ele) => factory.createImportDeclaration(undefined, factory.createImportClause(false, factory.createIdentifier(`${ele}Data`), undefined), factory.createStringLiteral(`./${ele}Data`), undefined));
964
+ const existingSpreads = new Set();
965
+ const exportStmt = statements[statements.length - 1];
966
+ assert(ts.isExportAssignment(exportStmt));
967
+ const { expression } = exportStmt;
968
+ assert(ts.isObjectLiteralExpression(expression));
969
+ const { properties } = expression;
970
+ properties.forEach((prop) => {
971
+ if (ts.isSpreadAssignment(prop)) {
972
+ existingSpreads.add(prop.expression.getText());
973
+ }
974
+ });
975
+ // data/index.ts 可能来自项目模板(如 create --template blog 自行 import 了同名数据文件),
976
+ // 注入前按 import 声明与 export 展分别去重,避免注入出重复标识符导致编译失败。
977
+ const injectImports = [];
978
+ const injectSpreads = [];
979
+ briefNames.forEach((ele) => {
980
+ const hasImport = statements.some((stmt) => ts.isImportDeclaration(stmt)
981
+ && stmt.moduleSpecifier.text === `./${ele}Data`
982
+ && !!stmt.importClause?.name
983
+ && stmt.importClause.name.text === `${ele}Data`);
984
+ if (!hasImport) {
985
+ injectImports.push(ele);
986
+ }
987
+ if (!existingSpreads.has(`${ele}Data`)) {
988
+ injectSpreads.push(ele);
989
+ }
990
+ });
991
+ if (injectImports.length === 0 && injectSpreads.length === 0) {
992
+ console.log(`data/index.ts中${briefNames.join('、')}的引用已存在,跳过注入`);
993
+ return;
994
+ }
939
995
  /**
940
996
  * 在文件末尾的这个位置上注入引用
941
997
  export default {
@@ -946,24 +1002,19 @@ function injectDataIndexFile(dataIndexFile, briefNames, printer) {
946
1002
  i18n,
947
1003
  };
948
1004
  */
949
- const exportStmt = statements[statements.length - 1];
950
- assert(ts.isExportAssignment(exportStmt));
951
- const { expression } = exportStmt;
952
- assert(ts.isObjectLiteralExpression(expression));
953
- const { properties } = expression;
954
1005
  Object.assign(expression, {
955
1006
  properties: [
956
1007
  ...properties,
957
- ...briefNames.map((ele) => factory.createSpreadAssignment(factory.createIdentifier(`${ele}Data`)))
1008
+ ...injectSpreads.map((ele) => factory.createSpreadAssignment(factory.createIdentifier(`${ele}Data`)))
958
1009
  ]
959
1010
  });
960
1011
  const statements2 = [
961
- ...importStatements,
1012
+ ...injectImports.map((ele) => factory.createImportDeclaration(undefined, factory.createImportClause(false, factory.createIdentifier(`${ele}Data`), undefined), factory.createStringLiteral(`./${ele}Data`), undefined)),
962
1013
  ...statements,
963
1014
  ];
964
1015
  const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
965
- writeFileSync(dataIndexFile, result, { flag: 'w' });
966
- console.log(`注入${dataIndexFile}文件成功,共注入了${briefNames.length}个初始化数据引用`);
1016
+ writeGeneratedFile(dataIndexFile, result);
1017
+ console.log(`注入${dataIndexFile}文件成功,共注入了${injectImports.length}个 import 与 ${injectSpreads.length} 个 export 引用`);
967
1018
  }
968
1019
  /**
969
1020
  * 将依赖项目的目录去覆盖原来的目录
@@ -1013,7 +1064,10 @@ function tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer, rebu
1013
1064
  const injectDataIndexFileDependencies = [];
1014
1065
  const injectDataIndexFileBriefNames = [];
1015
1066
  dependencies.forEach((dep, idx) => {
1016
- const moduleDir = join(cwd, 'node_modules', dep);
1067
+ const moduleDir = resolveInstalledPackageDir(cwd, dep);
1068
+ if (!moduleDir) {
1069
+ throw new Error(`依赖模块${dep}未能找到相应的安装目录`);
1070
+ }
1017
1071
  const moduleTemplateDir = join(moduleDir, 'template');
1018
1072
  if (existsSync(moduleTemplateDir)) {
1019
1073
  // data.ts中规定的初始化数据,拷贝到data目录下,并注入到data/index.ts
@@ -1043,6 +1097,65 @@ function tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer, rebu
1043
1097
  injectDataIndexFile(join(cwd, 'src', 'data', 'index.ts'), injectDataIndexFileBriefNames, printer);
1044
1098
  }
1045
1099
  }
1100
+ function makeSystemAlias(packageName, usedAliases) {
1101
+ const packageBaseName = packageName
1102
+ .replace(/^@/, '')
1103
+ .replace(/[\\/]/g, '-')
1104
+ .split('-')
1105
+ .filter(Boolean)
1106
+ .map((part) => `${part[0].toUpperCase()}${part.slice(1)}`)
1107
+ .join('')
1108
+ .replace(/^Oak/, '')
1109
+ .replace(/Business$/, '') || 'Dependency';
1110
+ const baseAlias = `${packageBaseName}System`;
1111
+ let alias = baseAlias;
1112
+ let index = 2;
1113
+ while (usedAliases.has(alias)) {
1114
+ alias = `${baseAlias}${index}`;
1115
+ index += 1;
1116
+ }
1117
+ usedAliases.add(alias);
1118
+ return alias;
1119
+ }
1120
+ export function renderSystemEntitySource(dependencies, cwd) {
1121
+ const usedAliases = new Set();
1122
+ const imports = [];
1123
+ const schemas = [];
1124
+ dependencies.forEach((dependency) => {
1125
+ const dependencyDir = resolveInstalledPackageDir(cwd, dependency);
1126
+ if (!dependencyDir) {
1127
+ return;
1128
+ }
1129
+ const manifestPath = join(dependencyDir, 'package.json');
1130
+ const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
1131
+ if (!isOakBusinessModule(manifest)) {
1132
+ return;
1133
+ }
1134
+ const systemDeclaration = join(dependencyDir, 'es', 'entities', 'System.d.ts');
1135
+ if (!existsSync(systemDeclaration)) {
1136
+ return;
1137
+ }
1138
+ const alias = makeSystemAlias(dependency, usedAliases);
1139
+ imports.push(`import { Schema as ${alias} } from '${makeOakImport(dependency, 'entities/System')}';`);
1140
+ schemas.push(alias);
1141
+ });
1142
+ if (schemas.length === 0) {
1143
+ return undefined;
1144
+ }
1145
+ return `${imports.join('\n')}\nimport { EntityDesc } from '@oak-domain/types';\n\nexport interface Schema extends ${schemas.join(', ')} {}\n\nexport type Relation = 'owner' | 'manager';\n\nexport const entityDesc: EntityDesc<Schema, '', Relation> = {\n locales: {\n zh_CN: {\n name: '系统',\n attr: {\n name: '名称',\n description: '描述',\n config: '设置',\n platform: '平台',\n super: '超级系统',\n folder: '代码目录名',\n style: '样式',\n entity: '关联对象',\n entityId: '关联对象id',\n oldestVersion: '最早支持版本',\n },\n r: {\n owner: '所有者',\n manager: '管理员',\n },\n },\n },\n};\n`;
1146
+ }
1147
+ function ensureSystemEntity(cwd, dependencies, rebuild) {
1148
+ const systemFile = join(cwd, 'src', 'entities', 'System.ts');
1149
+ if (existsSync(systemFile) && !rebuild) {
1150
+ return;
1151
+ }
1152
+ const source = renderSystemEntitySource(dependencies, cwd);
1153
+ if (!source) {
1154
+ return;
1155
+ }
1156
+ writeGeneratedFile(systemFile, source);
1157
+ console.log(`${rebuild ? '重建' : '生成'}${systemFile}`);
1158
+ }
1046
1159
  function resolveDependencyBuildContext(cwd) {
1047
1160
  const webDir = join(cwd, 'web');
1048
1161
  const isModule = !existsSync(webDir); // 如果没有web目录,说明是module,不需要处理应用模板注入
@@ -1069,6 +1182,7 @@ export function initializeDependencyTemplates(cwd = process.cwd(), rebuild) {
1069
1182
  }
1070
1183
  const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
1071
1184
  tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer, rebuild);
1185
+ ensureSystemEntity(cwd, dependencies, rebuild);
1072
1186
  return dependencies;
1073
1187
  }
1074
1188
  /**
@@ -1100,7 +1214,7 @@ function injectInitializeToFeatureIndex(cwd, dependencies, briefNames, printer)
1100
1214
  ], undefined, factory.createBlock([], true))
1101
1215
  ];
1102
1216
  const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
1103
- writeFileSync(featureIndexFile, result, { flag: 'w' });
1217
+ writeGeneratedFile(featureIndexFile, result);
1104
1218
  console.log(`注入${featureIndexFile}文件成功,用户可以自己修正initialize函数的参数和逻辑`);
1105
1219
  }
1106
1220
  }
@@ -1111,19 +1225,23 @@ function injectInitializeToFeatureIndex(cwd, dependencies, briefNames, printer)
1111
1225
  export default function buildDependency(rebuild) {
1112
1226
  const cwd = process.cwd();
1113
1227
  const { depGraph, dependencies, briefNames, isModule, } = resolveDependencyBuildContext(cwd);
1228
+ const oakCliDir = resolveInstalledPackageDir(cwd, OAK_CLI_MODULE_NAME);
1229
+ if (!oakCliDir) {
1230
+ throw new Error(`找不到依赖包${OAK_CLI_MODULE_NAME}的安装位置,当前包是${cwd}`);
1231
+ }
1114
1232
  const defaultTemplateFiles = {
1115
- initializeServer: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments', 'initialize.server.ts'),
1116
- initializeFeatures: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments', 'initializeFeatures.ts'),
1117
- runtimeCxt: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments', 'RuntimeCxt.ts'),
1118
- dependentExceptions: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments', 'DependentExceptions.ts'),
1119
- polyfillDts: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments', 'polyfill.d.ts'),
1120
- featureIndex: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments', !isModule && dependencies.length === 0
1233
+ initializeServer: join(oakCliDir, 'scaffold', 'fragments', 'initialize.server.ts'),
1234
+ initializeFeatures: join(oakCliDir, 'scaffold', 'fragments', 'initializeFeatures.ts'),
1235
+ runtimeCxt: join(oakCliDir, 'scaffold', 'fragments', 'RuntimeCxt.ts'),
1236
+ dependentExceptions: join(oakCliDir, 'scaffold', 'fragments', 'DependentExceptions.ts'),
1237
+ polyfillDts: join(oakCliDir, 'scaffold', 'fragments', 'polyfill.d.ts'),
1238
+ featureIndex: join(oakCliDir, 'scaffold', 'fragments', !isModule && dependencies.length === 0
1121
1239
  ? 'features/index.standalone.ts'
1122
1240
  : 'features/index.ts'),
1123
- backendRuntimeContext: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments', dependencies.length === 0
1241
+ backendRuntimeContext: join(oakCliDir, 'scaffold', 'fragments', dependencies.length === 0
1124
1242
  ? 'BackendRuntimeContext.standalone.ts'
1125
1243
  : 'BackendRuntimeContext.ts'),
1126
- frontendRuntimeContext: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments', dependencies.length === 0
1244
+ frontendRuntimeContext: join(oakCliDir, 'scaffold', 'fragments', dependencies.length === 0
1127
1245
  ? 'FrontendRuntimeContext.standalone.ts'
1128
1246
  : 'FrontendRuntimeContext.ts'),
1129
1247
  };
@@ -24,14 +24,17 @@ type NamespaceConfig = {
24
24
  params?: Record<string, string>;
25
25
  };
26
26
  };
27
+ type RouterPlatform = 'web' | 'native' | 'miniProgram' | 'wechatMp';
27
28
  type BuildRouterOptions = {
29
+ /** `wechatMp` is retained as a compatibility alias for `miniProgram`. */
30
+ platform: RouterPlatform;
28
31
  useOutlet?: boolean;
29
32
  onWarning?: (message: string) => void;
30
33
  getPageConfig?: (pageDirectoryPath: string) => PageConfig | undefined;
31
34
  getNamespaceConfig?: (namespaceDirectoryPath: string, namespace: string) => NamespaceConfig | undefined;
32
35
  };
33
36
  declare function closeCurrentWatchSession(): void;
34
- export declare function buildRouter(projectDir: string, startupDir: string, watch?: boolean, options?: BuildRouterOptions): {
37
+ export declare function buildRouter(projectDir: string, startupDir: string, watch: boolean, options: BuildRouterOptions): {
35
38
  close: typeof closeCurrentWatchSession;
36
39
  } | undefined;
37
40
  export {};
@@ -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
- 'index.xml',
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\.xml|render\.(?:desktop|windows|macos|linux|native|ios|android)\.tsx)$/;
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.hasWechatMp !== next.hasWechatMp
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 hasWechatMp = false;
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 === 'index.xml') {
129
- hasWechatMp = true;
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 || hasWechatMp) {
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
- hasWechatMp,
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
- hasWechatMp: false,
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 (isWebStartupDir(startupDir)) {
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 type = isWebStartupDir(startupDir) ? 'web' : (startupDir.startsWith('native') ? 'native' : 'wechatMp');
831
- traversePageDir(projectDir, type);
832
- const subDir = readdirSync(projectDir);
833
- assert(subDir.includes(startupDir));
834
- if (isWebStartupDir(startupDir)) {
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, type);
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
- initialize(data?: SerializedData): Promise<void>;
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
- async initialize(data) {
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
  }
@@ -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';