oak-domain 4.0.2 → 4.0.3

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.
@@ -1,27 +1,27 @@
1
- /// <reference types="node" />
2
- import { Hash } from 'crypto';
3
- /**
4
- * 这个类的作用是把项目和所有相关的模块下的locales编译成为src/data/i18n中的数据
5
- */
6
- export default class LocaleBuilder {
7
- asLib: boolean;
8
- dependencies: string[];
9
- pwd: string;
10
- locales: Record<string, [string, string, string, object]>;
11
- hash: Hash;
12
- constructor(asLib?: boolean);
13
- /**
14
- * 将locales输出成为data/i18n.ts中的数据
15
- * 如果有Dependency需要引出来
16
- */
17
- private outputDataFile;
18
- /**
19
- * 这里不能直接用require, webpack貌似有缓存
20
- * @param filepath
21
- */
22
- private readLocaleFileContent;
23
- private parseFile;
24
- private traverse;
25
- private buildproject;
26
- build(watch?: boolean): void;
27
- }
1
+ /// <reference types="node" />
2
+ import { Hash } from 'crypto';
3
+ /**
4
+ * 这个类的作用是把项目和所有相关的模块下的locales编译成为src/data/i18n中的数据
5
+ */
6
+ export default class LocaleBuilder {
7
+ asLib: boolean;
8
+ dependencies: string[];
9
+ pwd: string;
10
+ locales: Record<string, [string, string, string, object]>;
11
+ hash: Hash;
12
+ constructor(asLib?: boolean);
13
+ /**
14
+ * 将locales输出成为data/i18n.ts中的数据
15
+ * 如果有Dependency需要引出来
16
+ */
17
+ private outputDataFile;
18
+ /**
19
+ * 这里不能直接用require, webpack貌似有缓存
20
+ * @param filepath
21
+ */
22
+ private readLocaleFileContent;
23
+ private parseFile;
24
+ private traverse;
25
+ private buildProject;
26
+ build(watch?: boolean): void;
27
+ }
@@ -153,18 +153,20 @@ class LocaleBuilder {
153
153
  }
154
154
  });
155
155
  }
156
- buildproject(root, src, watch) {
156
+ buildProject(root, src, watch) {
157
157
  const packageJson = (0, path_1.join)(root, 'package.json');
158
158
  const { name } = require(packageJson);
159
- const pagePath = (0, path_1.join)(src ? 'src' : 'lib', 'pages');
160
- if (fs_1.default.existsSync(pagePath)) {
161
- this.traverse(name, 'p', pagePath, (0, path_1.join)(root, pagePath), false, 'locales', watch);
159
+ const pagePath = (0, path_1.join)(src ? 'src' : 'es', 'pages');
160
+ const pageAbsolutePath = (0, path_1.join)(root, pagePath); //编译i18时font中的componentPath缺少根目录导致编译不出
161
+ if (fs_1.default.existsSync(pageAbsolutePath)) {
162
+ this.traverse(name, 'p', pagePath, pageAbsolutePath, false, 'locales', watch);
162
163
  }
163
- const componentPath = (0, path_1.join)(src ? 'src' : 'lib', 'components');
164
- if (fs_1.default.existsSync(componentPath)) {
165
- this.traverse(name, 'c', componentPath, (0, path_1.join)(root, componentPath), false, 'locales', watch);
164
+ const componentPath = (0, path_1.join)(src ? 'src' : 'es', 'components');
165
+ const componentAbsolutePath = (0, path_1.join)(root, componentPath);
166
+ if (fs_1.default.existsSync(componentAbsolutePath)) {
167
+ this.traverse(name, 'c', componentPath, componentAbsolutePath, false, 'locales', watch);
166
168
  }
167
- const localePath = (0, path_1.join)(root, src ? 'src' : 'lib', 'locales');
169
+ const localePath = (0, path_1.join)(root, src ? 'src' : 'es', 'locales');
168
170
  if (fs_1.default.existsSync(localePath)) {
169
171
  const files = fs_1.default.readdirSync(localePath);
170
172
  files.forEach((file) => {
@@ -201,11 +203,11 @@ class LocaleBuilder {
201
203
  }
202
204
  }
203
205
  build(watch) {
204
- this.buildproject(this.pwd, true, watch);
206
+ this.buildProject(this.pwd, true, watch);
205
207
  if (!this.asLib) {
206
208
  // 如果不是lib,把front里的数据也处理掉
207
209
  const fbPath = (0, path_1.join)(this.pwd, 'node_modules', 'oak-frontend-base');
208
- this.buildproject(fbPath, false, watch);
210
+ this.buildProject(fbPath, false, watch);
209
211
  }
210
212
  this.outputDataFile();
211
213
  }
@@ -1 +1 @@
1
- export declare function buildRouter(projectDir: string, startupDir: string, watch?: boolean): void;
1
+ export declare function buildRouter(projectDir: string, startupDir: string, watch?: boolean): void;
@@ -114,6 +114,7 @@ function makeWebAllRouters(namespaceDir, projectDir, routerFileDir) {
114
114
  }
115
115
  }
116
116
  }
117
+ let firstPage;
117
118
  const children = Object.values(pages).filter((ele) => ele.hasWeb).map(({ path, oakDisablePulldownRefresh }) => {
118
119
  const properties = [
119
120
  factory.createPropertyAssignment('path', factory.createStringLiteral(path)),
@@ -126,10 +127,15 @@ function makeWebAllRouters(namespaceDir, projectDir, routerFileDir) {
126
127
  ]))]))
127
128
  ];
128
129
  if (first2 === path) {
129
- properties.push(factory.createPropertyAssignment('isFirst', factory.createTrue()));
130
+ const firstProperties = [...properties];
131
+ firstProperties.push(factory.createPropertyAssignment('isFirst', factory.createTrue()));
132
+ firstPage = factory.createObjectLiteralExpression(firstProperties, true);
130
133
  }
131
134
  return factory.createObjectLiteralExpression(properties, true);
132
135
  });
136
+ if (firstPage) {
137
+ children.push(firstPage);
138
+ }
133
139
  if (notFound2) {
134
140
  children.push(factory.createObjectLiteralExpression([
135
141
  factory.createPropertyAssignment('path', factory.createStringLiteral('*')),
@@ -1,176 +1,180 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AsyncContext = void 0;
4
- const tslib_1 = require("tslib");
5
- const action_1 = require("../actions/action");
6
- const assert_1 = tslib_1.__importDefault(require("assert"));
7
- /**
8
- * 服务器端执行的异步环境的底层抽象
9
- */
10
- class AsyncContext {
11
- rowStore;
12
- uuid;
13
- opRecords;
14
- scene;
15
- headers;
16
- clusterInfo;
17
- opResult;
18
- message;
19
- events;
20
- constructor(store) {
21
- this.rowStore = store;
22
- this.opRecords = [];
23
- this.events = {
24
- commit: [],
25
- rollback: [],
26
- };
27
- this.opResult = {};
28
- }
29
- // 使一个上下文重新开始事务执行,清除历史数据(定时器中使用)
30
- async restartToExecute(routine) {
31
- const newContext = !this.uuid ? this : {
32
- ...this,
33
- }; // 这里可能有问题,继承的context对象中如果有对象属性会变成指针公用,但是估计目前是跑不到的。by Xc 20231215
34
- if (newContext !== this) {
35
- console.warn('restartToExecute跑出了非重用当前context的情况,请仔细调试');
36
- }
37
- newContext.opRecords = [];
38
- newContext.events = {
39
- commit: [],
40
- rollback: [],
41
- };
42
- newContext.opResult = {};
43
- await newContext.begin();
44
- try {
45
- await routine(newContext);
46
- await newContext.commit();
47
- }
48
- catch (err) {
49
- await newContext.rollback();
50
- throw err;
51
- }
52
- }
53
- getHeader(key) {
54
- if (this.headers) {
55
- return this.headers[key];
56
- }
57
- }
58
- getScene() {
59
- return this.scene;
60
- }
61
- setScene(scene) {
62
- this.scene = scene;
63
- }
64
- resetEvents() {
65
- this.events = {
66
- commit: [],
67
- rollback: [],
68
- };
69
- }
70
- on(event, callback) {
71
- this.uuid && this.events[event].push(callback);
72
- }
73
- saveOpRecord(entity, operation) {
74
- const { action, data, filter, id } = operation;
75
- switch (action) {
76
- case 'create': {
77
- this.opRecords.push({
78
- id,
79
- a: 'c',
80
- e: entity,
81
- d: data
82
- });
83
- break;
84
- }
85
- case 'remove': {
86
- this.opRecords.push({
87
- id,
88
- a: 'r',
89
- e: entity,
90
- f: filter,
91
- });
92
- break;
93
- }
94
- default: {
95
- (0, assert_1.default)(!action_1.readOnlyActions.includes(action));
96
- this.opRecords.push({
97
- id,
98
- a: 'u',
99
- e: entity,
100
- d: data,
101
- f: filter,
102
- });
103
- }
104
- }
105
- }
106
- /**
107
- * 一个context中不应该有并发的事务,这里将事务串行化,使用的时候千万要注意不要自己等自己
108
- * @param options
109
- */
110
- async begin(options) {
111
- if (!this.uuid) {
112
- this.uuid = await this.rowStore.begin(options);
113
- }
114
- else {
115
- (0, assert_1.default)(false);
116
- }
117
- }
118
- async commit() {
119
- if (this.uuid) {
120
- await this.rowStore.commit(this.uuid);
121
- this.uuid = undefined;
122
- const { commit: commitEvents } = this.events;
123
- this.resetEvents();
124
- for (const e of commitEvents) {
125
- await e();
126
- }
127
- }
128
- }
129
- async rollback() {
130
- if (this.uuid) {
131
- await this.rowStore.rollback(this.uuid);
132
- // console.log('rollback', this.uuid);
133
- this.uuid = undefined;
134
- const { rollback: rollbackEvents } = this.events;
135
- this.resetEvents();
136
- for (const e of rollbackEvents) {
137
- await e();
138
- }
139
- }
140
- }
141
- async operate(entity, operation, option) {
142
- const result = await this.rowStore.operate(entity, operation, this, option);
143
- this.opResult = this.mergeMultipleResults([this.opResult, result]);
144
- return result;
145
- }
146
- select(entity, selection, option) {
147
- return this.rowStore.select(entity, selection, this, option);
148
- }
149
- aggregate(entity, aggregation, option) {
150
- return this.rowStore.aggregate(entity, aggregation, this, option);
151
- }
152
- count(entity, selection, option) {
153
- return this.rowStore.count(entity, selection, this, option);
154
- }
155
- exec(script, txnId) {
156
- return this.rowStore.exec(script, txnId);
157
- }
158
- mergeMultipleResults(toBeMerged) {
159
- return this.rowStore.mergeMultipleResults(toBeMerged);
160
- }
161
- getCurrentTxnId() {
162
- return this.uuid;
163
- }
164
- getSchema() {
165
- return this.rowStore.getSchema();
166
- }
167
- setMessage(message) {
168
- this.message = message;
169
- }
170
- getMessage() {
171
- return this.message;
172
- }
173
- }
174
- exports.AsyncContext = AsyncContext;
175
- ;
176
- ;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AsyncContext = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const action_1 = require("../actions/action");
6
+ const assert_1 = tslib_1.__importDefault(require("assert"));
7
+ /**
8
+ * 服务器端执行的异步环境的底层抽象
9
+ */
10
+ class AsyncContext {
11
+ rowStore;
12
+ uuid;
13
+ opRecords;
14
+ scene;
15
+ headers;
16
+ clusterInfo;
17
+ opResult;
18
+ message;
19
+ events;
20
+ constructor(store) {
21
+ this.rowStore = store;
22
+ this.opRecords = [];
23
+ this.events = {
24
+ commit: [],
25
+ rollback: [],
26
+ };
27
+ this.opResult = {};
28
+ }
29
+ // 使一个上下文重新开始事务执行,清除历史数据(定时器中使用)
30
+ async restartToExecute(routine) {
31
+ const newContext = !this.uuid ? this : {
32
+ ...this,
33
+ }; // 这里可能有问题,继承的context对象中如果有对象属性会变成指针公用,但是估计目前是跑不到的。by Xc 20231215
34
+ if (newContext !== this) {
35
+ console.warn('restartToExecute跑出了非重用当前context的情况,请仔细调试');
36
+ }
37
+ newContext.opRecords = [];
38
+ newContext.events = {
39
+ commit: [],
40
+ rollback: [],
41
+ };
42
+ newContext.opResult = {};
43
+ await newContext.begin();
44
+ try {
45
+ await routine(newContext);
46
+ await newContext.commit();
47
+ }
48
+ catch (err) {
49
+ await newContext.rollback();
50
+ throw err;
51
+ }
52
+ }
53
+ getHeader(key) {
54
+ if (this.headers) {
55
+ return this.headers[key];
56
+ }
57
+ }
58
+ getScene() {
59
+ return this.scene;
60
+ }
61
+ setScene(scene) {
62
+ this.scene = scene;
63
+ }
64
+ resetEvents() {
65
+ this.events = {
66
+ commit: [],
67
+ rollback: [],
68
+ };
69
+ }
70
+ on(event, callback) {
71
+ this.uuid && this.events[event].push(callback);
72
+ }
73
+ saveOpRecord(entity, operation) {
74
+ const { action, data, filter, id } = operation;
75
+ switch (action) {
76
+ case 'create': {
77
+ this.opRecords.push({
78
+ id,
79
+ a: 'c',
80
+ e: entity,
81
+ d: data
82
+ });
83
+ break;
84
+ }
85
+ case 'remove': {
86
+ this.opRecords.push({
87
+ id,
88
+ a: 'r',
89
+ e: entity,
90
+ f: filter,
91
+ });
92
+ break;
93
+ }
94
+ default: {
95
+ (0, assert_1.default)(!action_1.readOnlyActions.includes(action));
96
+ this.opRecords.push({
97
+ id,
98
+ a: 'u',
99
+ e: entity,
100
+ d: data,
101
+ f: filter,
102
+ });
103
+ }
104
+ }
105
+ }
106
+ /**
107
+ * 一个context中不应该有并发的事务,这里将事务串行化,使用的时候千万要注意不要自己等自己
108
+ * @param options
109
+ */
110
+ async begin(options) {
111
+ if (!this.uuid) {
112
+ this.uuid = await this.rowStore.begin(options);
113
+ }
114
+ else {
115
+ (0, assert_1.default)(false);
116
+ }
117
+ }
118
+ async commit() {
119
+ if (this.uuid) {
120
+ await this.rowStore.commit(this.uuid);
121
+ const { commit: commitEvents } = this.events;
122
+ for (const e of commitEvents) {
123
+ await e();
124
+ }
125
+ this.uuid = undefined;
126
+ this.resetEvents();
127
+ this.opRecords = [];
128
+ this.opResult = {};
129
+ this.message = '';
130
+ }
131
+ }
132
+ async rollback() {
133
+ if (this.uuid) {
134
+ await this.rowStore.rollback(this.uuid);
135
+ const { rollback: rollbackEvents } = this.events;
136
+ for (const e of rollbackEvents) {
137
+ await e();
138
+ }
139
+ this.uuid = undefined;
140
+ this.opRecords = [];
141
+ this.opResult = {};
142
+ this.resetEvents();
143
+ }
144
+ }
145
+ async operate(entity, operation, option) {
146
+ const result = await this.rowStore.operate(entity, operation, this, option);
147
+ this.opResult = this.mergeMultipleResults([this.opResult, result]);
148
+ return result;
149
+ }
150
+ select(entity, selection, option) {
151
+ return this.rowStore.select(entity, selection, this, option);
152
+ }
153
+ aggregate(entity, aggregation, option) {
154
+ return this.rowStore.aggregate(entity, aggregation, this, option);
155
+ }
156
+ count(entity, selection, option) {
157
+ return this.rowStore.count(entity, selection, this, option);
158
+ }
159
+ exec(script, txnId) {
160
+ return this.rowStore.exec(script, txnId);
161
+ }
162
+ mergeMultipleResults(toBeMerged) {
163
+ return this.rowStore.mergeMultipleResults(toBeMerged);
164
+ }
165
+ getCurrentTxnId() {
166
+ return this.uuid;
167
+ }
168
+ getSchema() {
169
+ return this.rowStore.getSchema();
170
+ }
171
+ setMessage(message) {
172
+ this.message = message;
173
+ }
174
+ getMessage() {
175
+ return this.message;
176
+ }
177
+ }
178
+ exports.AsyncContext = AsyncContext;
179
+ ;
180
+ ;