oak-backend-base 4.1.0 → 4.1.1
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/lib/AppLoader.d.ts +1 -1
- package/lib/AppLoader.js +40 -18
- package/package.json +3 -3
- package/lib/data/area.json +0 -1
package/lib/AppLoader.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt exten
|
|
|
31
31
|
result: any;
|
|
32
32
|
message?: string;
|
|
33
33
|
}>;
|
|
34
|
-
initialize(
|
|
34
|
+
initialize(): Promise<void>;
|
|
35
35
|
getStore(): DbStore<ED, Cxt>;
|
|
36
36
|
getEndpoints(prefix: string): [string, "post" | "get" | "put" | "delete", string, (params: Record<string, string>, headers: IncomingHttpHeaders, req: IncomingMessage, body?: any) => Promise<any>][];
|
|
37
37
|
protected operateInWatcher<T extends keyof ED>(entity: T, operation: ED[T]['Update'], context: Cxt): Promise<OperationResult<ED>>;
|
package/lib/AppLoader.js
CHANGED
|
@@ -11,7 +11,6 @@ const uuid_1 = require("oak-domain/lib/utils/uuid");
|
|
|
11
11
|
const types_1 = require("oak-domain/lib/types");
|
|
12
12
|
const DbStore_1 = require("./DbStore");
|
|
13
13
|
const index_1 = tslib_1.__importStar(require("oak-common-aspect/lib/index"));
|
|
14
|
-
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
15
14
|
const dependencyBuilder_1 = require("oak-domain/lib/compiler/dependencyBuilder");
|
|
16
15
|
const DataSubscriber_1 = tslib_1.__importDefault(require("./cluster/DataSubscriber"));
|
|
17
16
|
const env_1 = require("./cluster/env");
|
|
@@ -94,7 +93,9 @@ class AppLoader extends types_1.AppLoader {
|
|
|
94
93
|
Object.keys(eventOperationMap).forEach((event) => {
|
|
95
94
|
const ids = eventOperationMap[event];
|
|
96
95
|
const opRecordsToPublish = opRecords.filter((ele) => !!ele.id && ids.includes(ele.id));
|
|
97
|
-
|
|
96
|
+
if (opRecordsToPublish.length !== ids.length && process.env.NODE_ENV === 'development') {
|
|
97
|
+
console.warn('要推送的事件的operation数量不足event事件中记录的数据,请检查是否有空operation被加入了推送事件');
|
|
98
|
+
}
|
|
98
99
|
loaderThis.dataSubscriber.publishEvent(event, opRecordsToPublish, this.getSubscriberId());
|
|
99
100
|
});
|
|
100
101
|
}
|
|
@@ -163,28 +164,49 @@ class AppLoader extends types_1.AppLoader {
|
|
|
163
164
|
throw err;
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
|
-
async initialize(
|
|
167
|
+
async initialize() {
|
|
167
168
|
await this.dbStore.initialize({ ifExists: 'dropIfNotStatic' });
|
|
168
169
|
const data = this.requireSth('lib/data/index');
|
|
169
170
|
const context = this.contextBuilder(this.dbStore);
|
|
171
|
+
context.openRootMode();
|
|
170
172
|
for (const entity in data) {
|
|
171
173
|
let rows = data[entity];
|
|
172
|
-
if (
|
|
173
|
-
// 对area暂时处理一下
|
|
174
|
-
rows = require('./data/area.json');
|
|
175
|
-
}
|
|
176
|
-
if (rows.length > 0 && (!truncate || !this.dbStore.getSchema()[entity].static)) {
|
|
174
|
+
if (rows.length > 0) {
|
|
177
175
|
await context.begin();
|
|
178
|
-
|
|
176
|
+
// 如果是static的对象,只要表中有数据就pass
|
|
177
|
+
const [first] = await this.dbStore.select(entity, {
|
|
178
|
+
data: {
|
|
179
|
+
id: 1,
|
|
180
|
+
},
|
|
181
|
+
indexFrom: 0,
|
|
182
|
+
count: 1,
|
|
183
|
+
}, context, {});
|
|
184
|
+
if (this.dbStore.getSchema()[entity].static) {
|
|
185
|
+
if (first) {
|
|
186
|
+
await context.commit();
|
|
187
|
+
console.log(`data in ${entity} omitted, ${rows.length} rows passed`);
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// 再插入所有的行
|
|
179
192
|
try {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
193
|
+
const insertRows = async (idx) => {
|
|
194
|
+
const rows2 = rows.slice(idx, 1000);
|
|
195
|
+
if (rows2.length > 0) {
|
|
196
|
+
await this.dbStore.operate(entity, {
|
|
197
|
+
data: rows,
|
|
198
|
+
action: 'create',
|
|
199
|
+
}, context, {
|
|
200
|
+
dontCollect: true,
|
|
201
|
+
dontCreateOper: true,
|
|
202
|
+
blockTrigger: true,
|
|
203
|
+
});
|
|
204
|
+
if (rows2.length === 1000) {
|
|
205
|
+
await insertRows(idx + 1000);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
await insertRows(0);
|
|
188
210
|
await context.commit();
|
|
189
211
|
console.log(`data in ${entity} initialized, ${rows.length} rows inserted`);
|
|
190
212
|
}
|
|
@@ -269,7 +291,7 @@ class AppLoader extends types_1.AppLoader {
|
|
|
269
291
|
const data = typeof actionData === 'function' ? await (actionData)() : actionData;
|
|
270
292
|
result = await this.operateInWatcher(entity, {
|
|
271
293
|
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
272
|
-
action,
|
|
294
|
+
action: action,
|
|
273
295
|
data,
|
|
274
296
|
filter: filter2
|
|
275
297
|
}, context);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oak-backend-base",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "oak-backend-base",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"author": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"node-schedule": "^2.1.0",
|
|
23
23
|
"oak-common-aspect": "~3.0.0",
|
|
24
24
|
"oak-db": "~3.3.0",
|
|
25
|
-
"oak-domain": "~5.0.
|
|
26
|
-
"oak-frontend-base": "~5.1.
|
|
25
|
+
"oak-domain": "~5.0.9",
|
|
26
|
+
"oak-frontend-base": "~5.1.2",
|
|
27
27
|
"socket.io": "^4.7.2",
|
|
28
28
|
"socket.io-client": "^4.7.2",
|
|
29
29
|
"uuid": "^8.3.2"
|