@nocobase/data-source-manager 1.6.0-alpha.9 → 1.6.0-beta.10

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.
@@ -6,14 +6,15 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- import { CollectionOptions, ICollection, ICollectionManager, IFieldInterface, IRepository, MergeOptions } from './types';
10
9
  import { DataSource } from './data-source';
10
+ import { CollectionOptions, ICollection, ICollectionManager, IFieldInterface, IRepository, MergeOptions } from './types';
11
11
  export declare class CollectionManager implements ICollectionManager {
12
12
  dataSource: DataSource;
13
13
  protected collections: Map<string, ICollection>;
14
14
  protected repositories: Map<string, IRepository>;
15
15
  protected models: Map<string, any>;
16
16
  constructor(options?: any);
17
+ setDataSource(dataSource: DataSource): void;
17
18
  getRegisteredFieldType(type: any): void;
18
19
  getRegisteredFieldInterface(key: string): void;
19
20
  getRegisteredModel(key: string): any;
@@ -45,6 +45,9 @@ const _CollectionManager = class _CollectionManager {
45
45
  Repository: import_repository.Repository
46
46
  });
47
47
  }
48
+ setDataSource(dataSource) {
49
+ this.dataSource = dataSource;
50
+ }
48
51
  /* istanbul ignore next -- @preserve */
49
52
  getRegisteredFieldType(type) {
50
53
  }
@@ -6,11 +6,11 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- import { CollectionOptions, ICollection, ICollectionManager, IField, IRepository } from './types';
10
9
  import { CollectionField } from './collection-field';
10
+ import { CollectionOptions, ICollection, ICollectionManager, IField, IRepository } from './types';
11
11
  export declare class Collection implements ICollection {
12
12
  protected options: CollectionOptions;
13
- protected collectionManager: ICollectionManager;
13
+ collectionManager: ICollectionManager;
14
14
  repository: IRepository;
15
15
  fields: Map<string, IField>;
16
16
  constructor(options: CollectionOptions, collectionManager: ICollectionManager);
@@ -7,8 +7,11 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
  import { DataSource } from './data-source';
10
+ import { DataSourceManager } from './data-source-manager';
10
11
  export declare class DataSourceFactory {
12
+ protected dataSourceManager: DataSourceManager;
11
13
  collectionTypes: Map<string, typeof DataSource>;
14
+ constructor(dataSourceManager: DataSourceManager);
12
15
  register(type: string, dataSourceClass: typeof DataSource): void;
13
16
  getClass(type: string): typeof DataSource;
14
17
  create(type: string, options?: any): DataSource;
@@ -31,6 +31,9 @@ __export(data_source_factory_exports, {
31
31
  });
32
32
  module.exports = __toCommonJS(data_source_factory_exports);
33
33
  const _DataSourceFactory = class _DataSourceFactory {
34
+ constructor(dataSourceManager) {
35
+ this.dataSourceManager = dataSourceManager;
36
+ }
34
37
  collectionTypes = /* @__PURE__ */ new Map();
35
38
  register(type, dataSourceClass) {
36
39
  this.collectionTypes.set(type, dataSourceClass);
@@ -39,11 +42,20 @@ const _DataSourceFactory = class _DataSourceFactory {
39
42
  return this.collectionTypes.get(type);
40
43
  }
41
44
  create(type, options = {}) {
45
+ var _a;
42
46
  const klass = this.collectionTypes.get(type);
43
47
  if (!klass) {
44
48
  throw new Error(`Data source type "${type}" not found`);
45
49
  }
46
- return new klass(options);
50
+ const environment = (_a = this.dataSourceManager.options.app) == null ? void 0 : _a.environment;
51
+ const { logger, sqlLogger, ...others } = options;
52
+ const opts = { logger, sqlLogger, ...others };
53
+ if (environment) {
54
+ Object.assign(opts, environment.renderJsonTemplate(others));
55
+ }
56
+ const dataSource = new klass(opts);
57
+ dataSource.setDataSourceManager(this.dataSourceManager);
58
+ return dataSource;
47
59
  }
48
60
  };
49
61
  __name(_DataSourceFactory, "DataSourceFactory");
@@ -6,10 +6,10 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
+ import { Logger, LoggerOptions } from '@nocobase/logger';
9
10
  import { ToposortOptions } from '@nocobase/utils';
10
11
  import { DataSource } from './data-source';
11
12
  import { DataSourceFactory } from './data-source-factory';
12
- import { Logger, LoggerOptions } from '@nocobase/logger';
13
13
  type DataSourceHook = (dataSource: DataSource) => void;
14
14
  type DataSourceManagerOptions = {
15
15
  logger?: LoggerOptions | Logger;
@@ -30,12 +30,13 @@ __export(data_source_manager_exports, {
30
30
  DataSourceManager: () => DataSourceManager
31
31
  });
32
32
  module.exports = __toCommonJS(data_source_manager_exports);
33
- var import_data_source_factory = require("./data-source-factory");
34
33
  var import_logger = require("@nocobase/logger");
34
+ var import_data_source_factory = require("./data-source-factory");
35
35
  const _DataSourceManager = class _DataSourceManager {
36
36
  constructor(options = {}) {
37
37
  this.options = options;
38
38
  this.dataSources = /* @__PURE__ */ new Map();
39
+ this.factory = new import_data_source_factory.DataSourceFactory(this);
39
40
  this.middlewares = [];
40
41
  if (options.app) {
41
42
  options.app.on("beforeStop", async () => {
@@ -49,7 +50,7 @@ const _DataSourceManager = class _DataSourceManager {
49
50
  /**
50
51
  * @internal
51
52
  */
52
- factory = new import_data_source_factory.DataSourceFactory();
53
+ factory;
53
54
  middlewares = [];
54
55
  onceHooks = [];
55
56
  beforeAddHooks = [];
@@ -8,10 +8,11 @@
8
8
  */
9
9
  /// <reference types="node" />
10
10
  import { ACL } from '@nocobase/acl';
11
+ import { Logger } from '@nocobase/logger';
11
12
  import { ResourceManager } from '@nocobase/resourcer';
12
13
  import EventEmitter from 'events';
14
+ import { DataSourceManager } from './data-source-manager';
13
15
  import { ICollectionManager } from './types';
14
- import { Logger } from '@nocobase/logger';
15
16
  export type DataSourceOptions = any;
16
17
  export type LoadingProgress = {
17
18
  total: number;
@@ -22,12 +23,14 @@ export declare abstract class DataSource extends EventEmitter {
22
23
  collectionManager: ICollectionManager;
23
24
  resourceManager: ResourceManager;
24
25
  acl: ACL;
26
+ dataSourceManager: DataSourceManager;
25
27
  logger: Logger;
26
28
  constructor(options: DataSourceOptions);
27
29
  _sqlLogger: Logger;
28
30
  get sqlLogger(): Logger;
29
31
  get name(): any;
30
32
  static testConnection(options?: any): Promise<boolean>;
33
+ setDataSourceManager(dataSourceManager: DataSourceManager): void;
31
34
  setLogger(logger: Logger): void;
32
35
  setSqlLogger(logger: Logger): void;
33
36
  init(options?: DataSourceOptions): void;
@@ -42,10 +42,10 @@ __export(data_source_exports, {
42
42
  module.exports = __toCommonJS(data_source_exports);
43
43
  var import_acl = require("@nocobase/acl");
44
44
  var import_resourcer = require("@nocobase/resourcer");
45
+ var import_utils = require("@nocobase/utils");
45
46
  var import_events = __toESM(require("events"));
46
47
  var import_koa_compose = __toESM(require("koa-compose"));
47
48
  var import_load_default_actions = require("./load-default-actions");
48
- var import_utils = require("@nocobase/utils");
49
49
  const _DataSource = class _DataSource extends import_events.default {
50
50
  constructor(options) {
51
51
  super();
@@ -55,6 +55,7 @@ const _DataSource = class _DataSource extends import_events.default {
55
55
  collectionManager;
56
56
  resourceManager;
57
57
  acl;
58
+ dataSourceManager;
58
59
  logger;
59
60
  _sqlLogger;
60
61
  get sqlLogger() {
@@ -66,6 +67,9 @@ const _DataSource = class _DataSource extends import_events.default {
66
67
  static testConnection(options) {
67
68
  return Promise.resolve(true);
68
69
  }
70
+ setDataSourceManager(dataSourceManager) {
71
+ this.dataSourceManager = dataSourceManager;
72
+ }
69
73
  setLogger(logger) {
70
74
  this.logger = logger;
71
75
  }
@@ -79,6 +83,9 @@ const _DataSource = class _DataSource extends import_events.default {
79
83
  ...options.resourceManager
80
84
  });
81
85
  this.collectionManager = this.createCollectionManager(options);
86
+ if (this.collectionManager) {
87
+ this.collectionManager.setDataSource(this);
88
+ }
82
89
  this.resourceManager.registerActionHandlers((0, import_load_default_actions.loadDefaultActions)());
83
90
  if (options.acl !== false) {
84
91
  this.resourceManager.use(this.acl.middleware(), { tag: "acl", after: ["auth"] });
@@ -7,11 +7,14 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
  import { Database } from '@nocobase/database';
10
+ import { DataSource } from './data-source';
10
11
  import { CollectionOptions, ICollection, ICollectionManager, IFieldInterface, IRepository, MergeOptions } from './types';
11
12
  export declare class SequelizeCollectionManager implements ICollectionManager {
12
13
  db: Database;
13
14
  options: any;
15
+ dataSource: DataSource;
14
16
  constructor(options: any);
17
+ setDataSource(dataSource: DataSource): void;
15
18
  collectionsFilter(): any;
16
19
  createDB(options?: any): any;
17
20
  registerFieldTypes(types: Record<string, any>): void;
@@ -35,10 +35,14 @@ var import_database = require("@nocobase/database");
35
35
  const _SequelizeCollectionManager = class _SequelizeCollectionManager {
36
36
  db;
37
37
  options;
38
+ dataSource;
38
39
  constructor(options) {
39
40
  this.db = this.createDB(options);
40
41
  this.options = options;
41
42
  }
43
+ setDataSource(dataSource) {
44
+ this.dataSource = dataSource;
45
+ }
42
46
  collectionsFilter() {
43
47
  if (this.options.collectionsFilter) {
44
48
  return this.options.collectionsFilter;
package/lib/types.d.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
+ import { DataSource } from './data-source';
9
10
  export type CollectionOptions = {
10
11
  name: string;
11
12
  repository?: string;
@@ -72,6 +73,8 @@ export type MergeOptions = {
72
73
  [key: string]: any;
73
74
  };
74
75
  export interface ICollectionManager {
76
+ dataSource: DataSource;
77
+ setDataSource(dataSource: DataSource): void;
75
78
  registerFieldTypes(types: Record<string, any>): void;
76
79
  registerFieldInterfaces(interfaces: Record<string, new (options: any) => IFieldInterface>): void;
77
80
  registerFieldInterface(name: string, fieldInterface: new (options: any) => IFieldInterface): void;
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@nocobase/data-source-manager",
3
- "version": "1.6.0-alpha.9",
3
+ "version": "1.6.0-beta.10",
4
4
  "description": "",
5
5
  "license": "AGPL-3.0",
6
6
  "main": "./lib/index.js",
7
7
  "types": "./lib/index.d.ts",
8
8
  "dependencies": {
9
- "@nocobase/actions": "1.6.0-alpha.9",
10
- "@nocobase/cache": "1.6.0-alpha.9",
11
- "@nocobase/database": "1.6.0-alpha.9",
12
- "@nocobase/resourcer": "1.6.0-alpha.9",
13
- "@nocobase/utils": "1.6.0-alpha.9",
9
+ "@nocobase/actions": "1.6.0-beta.10",
10
+ "@nocobase/cache": "1.6.0-beta.10",
11
+ "@nocobase/database": "1.6.0-beta.10",
12
+ "@nocobase/resourcer": "1.6.0-beta.10",
13
+ "@nocobase/utils": "1.6.0-beta.10",
14
14
  "@types/jsonwebtoken": "^8.5.8",
15
15
  "jsonwebtoken": "^8.5.1"
16
16
  },
@@ -19,5 +19,5 @@
19
19
  "url": "git+https://github.com/nocobase/nocobase.git",
20
20
  "directory": "packages/auth"
21
21
  },
22
- "gitHead": "c6136fc6c9a2daab33fb1a20716cd9768e9a147f"
22
+ "gitHead": "72684ad7261e46b67969ecc4db0f1bcbea545a8d"
23
23
  }