@nocobase/server 0.9.1-alpha.1 → 0.9.1-alpha.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.
@@ -89,6 +89,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
89
89
  protected plugins: Map<string, Plugin<any>>;
90
90
  listenServer: Server;
91
91
  middleware: any;
92
+ stopped: boolean;
92
93
  constructor(options: ApplicationOptions);
93
94
  get db(): Database;
94
95
  get cache(): Cache;
@@ -234,6 +234,7 @@ class Application extends _koa().default {
234
234
  this._version = void 0;
235
235
  this.plugins = new Map();
236
236
  this.listenServer = void 0;
237
+ this.stopped = false;
237
238
  this.options = options;
238
239
  this.init();
239
240
  }
@@ -346,13 +347,15 @@ class Application extends _koa().default {
346
347
  }
347
348
 
348
349
  createDatabase(options) {
349
- return new (_database().default)(_objectSpread(_objectSpread({}, options.database instanceof _database().default ? options.database.options : options.database), {}, {
350
+ const db = new (_database().default)(_objectSpread(_objectSpread({}, options.database instanceof _database().default ? options.database.options : options.database), {}, {
350
351
  migrator: {
351
352
  context: {
352
353
  app: this
353
354
  }
354
355
  }
355
356
  }));
357
+ db.setLogger(this._logger);
358
+ return db;
356
359
  }
357
360
 
358
361
  getVersion() {
@@ -515,6 +518,7 @@ class Application extends _koa().default {
515
518
  }
516
519
 
517
520
  yield _this8.emitAsync('afterStart', _this8, options);
521
+ _this8.stopped = false;
518
522
  })();
519
523
  }
520
524
 
@@ -526,6 +530,12 @@ class Application extends _koa().default {
526
530
  var _this9 = this;
527
531
 
528
532
  return _asyncToGenerator(function* () {
533
+ if (_this9.stopped) {
534
+ _this9.log.warn(`Application ${_this9.name} already stopped`);
535
+
536
+ return;
537
+ }
538
+
529
539
  yield _this9.emitAsync('beforeStop', _this9, options);
530
540
 
531
541
  try {
@@ -545,6 +555,7 @@ class Application extends _koa().default {
545
555
  }
546
556
 
547
557
  yield _this9.emitAsync('afterStop', _this9, options);
558
+ _this9.stopped = true;
548
559
  })();
549
560
  }
550
561
 
@@ -32,12 +32,13 @@ export declare class PluginManager {
32
32
  clone(): PluginManager;
33
33
  addStatic(plugin?: any, options?: any): any;
34
34
  generateClientFile(plugin: string, packageName: string): Promise<void>;
35
- add(plugin: any, options?: any, transaction?: any): any;
35
+ add(plugin: any, options?: any, transaction?: any): Promise<any>;
36
36
  load(options?: any): Promise<void>;
37
37
  install(options?: InstallOptions): Promise<void>;
38
38
  enable(name: string | string[]): Promise<void>;
39
39
  disable(name: string | string[]): Promise<void>;
40
40
  remove(name: string | string[]): Promise<void>;
41
+ static getPackageJson(packageName: string): any;
41
42
  static getPackageName(name: string): string;
42
43
  static getPluginPkgPrefix(): string[];
43
44
  static findPackage(name: string): Promise<string>;
@@ -371,7 +371,22 @@ class PluginManager {
371
371
  const t = transaction || (yield _this4.app.db.sequelize.transaction());
372
372
 
373
373
  try {
374
- const items = yield Promise.all(plugin.map(p => _this4.add(p, options, t)));
374
+ const items = [];
375
+
376
+ var _iterator3 = _createForOfIteratorHelper(plugin),
377
+ _step3;
378
+
379
+ try {
380
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
381
+ const p = _step3.value;
382
+ items.push(yield _this4.add(p, options, t));
383
+ }
384
+ } catch (err) {
385
+ _iterator3.e(err);
386
+ } finally {
387
+ _iterator3.f();
388
+ }
389
+
375
390
  yield t.commit();
376
391
  return items;
377
392
  } catch (error) {
@@ -381,9 +396,6 @@ class PluginManager {
381
396
  }
382
397
 
383
398
  const packageName = yield PluginManager.findPackage(plugin);
384
-
385
- const packageJson = require(`${packageName}/package.json`);
386
-
387
399
  yield _this4.generateClientFile(plugin, packageName);
388
400
 
389
401
  const instance = _this4.addStatic(plugin, _objectSpread(_objectSpread({}, options), {}, {
@@ -396,6 +408,7 @@ class PluginManager {
396
408
  name: plugin
397
409
  }
398
410
  });
411
+ const packageJson = PluginManager.getPackageJson(packageName);
399
412
 
400
413
  if (!model) {
401
414
  const enabled = options.enabled,
@@ -403,7 +416,7 @@ class PluginManager {
403
416
  installed = options.installed,
404
417
  others = _objectWithoutProperties(options, _excluded);
405
418
 
406
- model = yield _this4.repository.create({
419
+ yield _this4.repository.create({
407
420
  transaction,
408
421
  values: {
409
422
  name: plugin,
@@ -424,14 +437,14 @@ class PluginManager {
424
437
  var _this5 = this;
425
438
 
426
439
  return _asyncToGenerator(function* () {
427
- var _iterator3 = _createForOfIteratorHelper(_this5.plugins),
428
- _step3;
440
+ var _iterator4 = _createForOfIteratorHelper(_this5.plugins),
441
+ _step4;
429
442
 
430
443
  try {
431
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
432
- const _step3$value = _slicedToArray(_step3.value, 2),
433
- name = _step3$value[0],
434
- plugin = _step3$value[1];
444
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
445
+ const _step4$value = _slicedToArray(_step4.value, 2),
446
+ name = _step4$value[0],
447
+ plugin = _step4$value[1];
435
448
 
436
449
  if (!plugin.enabled) {
437
450
  continue;
@@ -440,19 +453,19 @@ class PluginManager {
440
453
  yield plugin.beforeLoad();
441
454
  }
442
455
  } catch (err) {
443
- _iterator3.e(err);
456
+ _iterator4.e(err);
444
457
  } finally {
445
- _iterator3.f();
458
+ _iterator4.f();
446
459
  }
447
460
 
448
- var _iterator4 = _createForOfIteratorHelper(_this5.plugins),
449
- _step4;
461
+ var _iterator5 = _createForOfIteratorHelper(_this5.plugins),
462
+ _step5;
450
463
 
451
464
  try {
452
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
453
- const _step4$value = _slicedToArray(_step4.value, 2),
454
- name = _step4$value[0],
455
- plugin = _step4$value[1];
465
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
466
+ const _step5$value = _slicedToArray(_step5.value, 2),
467
+ name = _step5$value[0],
468
+ plugin = _step5$value[1];
456
469
 
457
470
  if (!plugin.enabled) {
458
471
  continue;
@@ -463,9 +476,9 @@ class PluginManager {
463
476
  yield _this5.app.emitAsync('afterLoadPlugin', plugin, options);
464
477
  }
465
478
  } catch (err) {
466
- _iterator4.e(err);
479
+ _iterator5.e(err);
467
480
  } finally {
468
- _iterator4.f();
481
+ _iterator5.f();
469
482
  }
470
483
  })();
471
484
  }
@@ -474,14 +487,14 @@ class PluginManager {
474
487
  var _this6 = this;
475
488
 
476
489
  return _asyncToGenerator(function* () {
477
- var _iterator5 = _createForOfIteratorHelper(_this6.plugins),
478
- _step5;
490
+ var _iterator6 = _createForOfIteratorHelper(_this6.plugins),
491
+ _step6;
479
492
 
480
493
  try {
481
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
482
- const _step5$value = _slicedToArray(_step5.value, 2),
483
- name = _step5$value[0],
484
- plugin = _step5$value[1];
494
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
495
+ const _step6$value = _slicedToArray(_step6.value, 2),
496
+ name = _step6$value[0],
497
+ plugin = _step6$value[1];
485
498
 
486
499
  if (!plugin.enabled) {
487
500
  continue;
@@ -492,9 +505,9 @@ class PluginManager {
492
505
  yield _this6.app.emitAsync('afterInstallPlugin', plugin, options);
493
506
  }
494
507
  } catch (err) {
495
- _iterator5.e(err);
508
+ _iterator6.e(err);
496
509
  } finally {
497
- _iterator5.f();
510
+ _iterator6.f();
498
511
  }
499
512
  })();
500
513
  }
@@ -508,12 +521,12 @@ class PluginManager {
508
521
  yield _this7.app.reload();
509
522
  yield _this7.app.db.sync();
510
523
 
511
- var _iterator6 = _createForOfIteratorHelper(pluginNames),
512
- _step6;
524
+ var _iterator7 = _createForOfIteratorHelper(pluginNames),
525
+ _step7;
513
526
 
514
527
  try {
515
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
516
- const pluginName = _step6.value;
528
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
529
+ const pluginName = _step7.value;
517
530
 
518
531
  const plugin = _this7.app.getPlugin(pluginName);
519
532
 
@@ -525,9 +538,9 @@ class PluginManager {
525
538
  yield plugin.afterEnable();
526
539
  }
527
540
  } catch (err) {
528
- _iterator6.e(err);
541
+ _iterator7.e(err);
529
542
  } finally {
530
- _iterator6.f();
543
+ _iterator7.f();
531
544
  }
532
545
  } catch (error) {
533
546
  throw error;
@@ -543,12 +556,12 @@ class PluginManager {
543
556
  const pluginNames = yield _this8.repository.disable(name);
544
557
  yield _this8.app.reload();
545
558
 
546
- var _iterator7 = _createForOfIteratorHelper(pluginNames),
547
- _step7;
559
+ var _iterator8 = _createForOfIteratorHelper(pluginNames),
560
+ _step8;
548
561
 
549
562
  try {
550
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
551
- const pluginName = _step7.value;
563
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
564
+ const pluginName = _step8.value;
552
565
 
553
566
  const plugin = _this8.app.getPlugin(pluginName);
554
567
 
@@ -559,9 +572,9 @@ class PluginManager {
559
572
  yield plugin.afterDisable();
560
573
  }
561
574
  } catch (err) {
562
- _iterator7.e(err);
575
+ _iterator8.e(err);
563
576
  } finally {
564
- _iterator7.f();
577
+ _iterator8.f();
565
578
  }
566
579
  } catch (error) {
567
580
  throw error;
@@ -575,12 +588,12 @@ class PluginManager {
575
588
  return _asyncToGenerator(function* () {
576
589
  const pluginNames = typeof name === 'string' ? [name] : name;
577
590
 
578
- var _iterator8 = _createForOfIteratorHelper(pluginNames),
579
- _step8;
591
+ var _iterator9 = _createForOfIteratorHelper(pluginNames),
592
+ _step9;
580
593
 
581
594
  try {
582
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
583
- const pluginName = _step8.value;
595
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
596
+ const pluginName = _step9.value;
584
597
 
585
598
  const plugin = _this9.app.getPlugin(pluginName);
586
599
 
@@ -591,9 +604,9 @@ class PluginManager {
591
604
  yield plugin.remove();
592
605
  }
593
606
  } catch (err) {
594
- _iterator8.e(err);
607
+ _iterator9.e(err);
595
608
  } finally {
596
- _iterator8.f();
609
+ _iterator9.f();
597
610
  }
598
611
 
599
612
  yield _this9.repository.remove(name);
@@ -602,15 +615,19 @@ class PluginManager {
602
615
  })();
603
616
  }
604
617
 
618
+ static getPackageJson(packageName) {
619
+ return require(`${packageName}/package.json`);
620
+ }
621
+
605
622
  static getPackageName(name) {
606
623
  const prefixes = this.getPluginPkgPrefix();
607
624
 
608
- var _iterator9 = _createForOfIteratorHelper(prefixes),
609
- _step9;
625
+ var _iterator10 = _createForOfIteratorHelper(prefixes),
626
+ _step10;
610
627
 
611
628
  try {
612
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
613
- const prefix = _step9.value;
629
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
630
+ const prefix = _step10.value;
614
631
 
615
632
  try {
616
633
  require.resolve(`${prefix}${name}`);
@@ -621,9 +638,9 @@ class PluginManager {
621
638
  }
622
639
  }
623
640
  } catch (err) {
624
- _iterator9.e(err);
641
+ _iterator10.e(err);
625
642
  } finally {
626
- _iterator9.f();
643
+ _iterator10.f();
627
644
  }
628
645
 
629
646
  throw new Error(`${name} plugin does not exist`);
@@ -646,12 +663,12 @@ class PluginManager {
646
663
 
647
664
  const prefixes = _this10.getPluginPkgPrefix();
648
665
 
649
- var _iterator10 = _createForOfIteratorHelper(prefixes),
650
- _step10;
666
+ var _iterator11 = _createForOfIteratorHelper(prefixes),
667
+ _step11;
651
668
 
652
669
  try {
653
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
654
- const prefix = _step10.value;
670
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
671
+ const prefix = _step11.value;
655
672
 
656
673
  try {
657
674
  const packageName = `${prefix}${name}`;
@@ -666,9 +683,9 @@ class PluginManager {
666
683
  }
667
684
  }
668
685
  } catch (err) {
669
- _iterator10.e(err);
686
+ _iterator11.e(err);
670
687
  } finally {
671
- _iterator10.f();
688
+ _iterator11.f();
672
689
  }
673
690
  }
674
691
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "0.9.1-alpha.1",
3
+ "version": "0.9.1-alpha.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -8,11 +8,11 @@
8
8
  "@hapi/topo": "^6.0.0",
9
9
  "@koa/cors": "^3.1.0",
10
10
  "@koa/router": "^9.4.0",
11
- "@nocobase/acl": "0.9.1-alpha.1",
12
- "@nocobase/actions": "0.9.1-alpha.1",
13
- "@nocobase/database": "0.9.1-alpha.1",
14
- "@nocobase/logger": "0.9.1-alpha.1",
15
- "@nocobase/resourcer": "0.9.1-alpha.1",
11
+ "@nocobase/acl": "0.9.1-alpha.2",
12
+ "@nocobase/actions": "0.9.1-alpha.2",
13
+ "@nocobase/database": "0.9.1-alpha.2",
14
+ "@nocobase/logger": "0.9.1-alpha.2",
15
+ "@nocobase/resourcer": "0.9.1-alpha.2",
16
16
  "chalk": "^4.1.1",
17
17
  "commander": "^9.2.0",
18
18
  "find-package-json": "^1.2.0",
@@ -27,5 +27,5 @@
27
27
  "devDependencies": {
28
28
  "@types/semver": "^7.3.9"
29
29
  },
30
- "gitHead": "56cb184b00dc383b853015d525bf6e79dea92169"
30
+ "gitHead": "d588a68eca4feed4642a4cb317301011266fe5c9"
31
31
  }