oak-backend-base 4.0.4 → 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.
@@ -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(truncate?: boolean): Promise<void>;
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
- (0, assert_1.default)(opRecordsToPublish.length === ids.length, '要推送的事件的operation数量不足,请检查确保');
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
  }
@@ -110,7 +111,8 @@ class AppLoader extends types_1.AppLoader {
110
111
  const triggers = this.requireSth('lib/triggers/index');
111
112
  const checkers = this.requireSth('lib/checkers/index');
112
113
  const { actionDefDict } = require(`${this.path}/lib/oak-app-domain/ActionDefDict`);
113
- const { triggers: adTriggers, checkers: adCheckers } = (0, IntrinsicLogics_1.makeIntrinsicLogics)(this.dbStore.getSchema(), actionDefDict);
114
+ const attrUpdateMatrix = this.requireSth('lib/configuration/attrUpdateMatrix');
115
+ const { triggers: adTriggers, checkers: adCheckers } = (0, IntrinsicLogics_1.makeIntrinsicLogics)(this.dbStore.getSchema(), actionDefDict, attrUpdateMatrix);
114
116
  triggers.forEach((trigger) => this.registerTrigger(trigger));
115
117
  adTriggers.forEach((trigger) => this.registerTrigger(trigger));
116
118
  checkers.forEach((checker) => this.dbStore.registerChecker(checker));
@@ -162,28 +164,49 @@ class AppLoader extends types_1.AppLoader {
162
164
  throw err;
163
165
  }
164
166
  }
165
- async initialize(truncate) {
167
+ async initialize() {
166
168
  await this.dbStore.initialize({ ifExists: 'dropIfNotStatic' });
167
169
  const data = this.requireSth('lib/data/index');
168
170
  const context = this.contextBuilder(this.dbStore);
171
+ context.openRootMode();
169
172
  for (const entity in data) {
170
173
  let rows = data[entity];
171
- if (entity === 'area') {
172
- // 对area暂时处理一下
173
- rows = require('./data/area.json');
174
- }
175
- if (rows.length > 0 && (!truncate || !this.dbStore.getSchema()[entity].static)) {
174
+ if (rows.length > 0) {
176
175
  await context.begin();
177
- context.openRootMode();
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
+ // 再插入所有的行
178
192
  try {
179
- await this.dbStore.operate(entity, {
180
- data: rows,
181
- action: 'create',
182
- }, context, {
183
- dontCollect: true,
184
- dontCreateOper: true,
185
- blockTrigger: true,
186
- });
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);
187
210
  await context.commit();
188
211
  console.log(`data in ${entity} initialized, ${rows.length} rows inserted`);
189
212
  }
@@ -268,7 +291,7 @@ class AppLoader extends types_1.AppLoader {
268
291
  const data = typeof actionData === 'function' ? await (actionData)() : actionData;
269
292
  result = await this.operateInWatcher(entity, {
270
293
  id: await (0, uuid_1.generateNewIdAsync)(),
271
- action,
294
+ action: action,
272
295
  data,
273
296
  filter: filter2
274
297
  }, context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-backend-base",
3
- "version": "4.0.4",
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.6",
26
- "oak-frontend-base": "~5.0.6",
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"