@nocobase/data-source-manager 1.0.0-alpha.9 → 1.0.1-alpha.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.
@@ -11,4 +11,5 @@ export declare class CollectionField implements IField {
11
11
  options: FieldOptions;
12
12
  constructor(options: FieldOptions);
13
13
  updateOptions(options: any): void;
14
+ isRelationField(): boolean;
14
15
  }
@@ -41,6 +41,9 @@ const _CollectionField = class _CollectionField {
41
41
  ...options
42
42
  };
43
43
  }
44
+ isRelationField() {
45
+ return false;
46
+ }
44
47
  };
45
48
  __name(_CollectionField, "CollectionField");
46
49
  let CollectionField = _CollectionField;
@@ -6,8 +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 { Collection } from './collection';
10
- import { CollectionOptions, ICollection, ICollectionManager, IRepository, MergeOptions } from './types';
9
+ import { CollectionOptions, ICollection, ICollectionManager, IFieldInterface, IRepository, MergeOptions } from './types';
11
10
  export declare class CollectionManager implements ICollectionManager {
12
11
  protected collections: Map<string, ICollection>;
13
12
  protected repositories: Map<string, IRepository>;
@@ -18,7 +17,11 @@ export declare class CollectionManager implements ICollectionManager {
18
17
  getRegisteredModel(key: string): any;
19
18
  getRegisteredRepository(key: any): any;
20
19
  registerFieldTypes(): void;
21
- registerFieldInterfaces(): void;
20
+ registerFieldInterfaces(interfaces: Record<string, new (options: any) => IFieldInterface>): void;
21
+ registerFieldInterface(name: string, fieldInterface: new (options: any) => IFieldInterface): void;
22
+ getFieldInterface(name: string): {
23
+ new (options: any): IFieldInterface | undefined;
24
+ };
22
25
  registerCollectionTemplates(): void;
23
26
  registerModels(models: Record<string, any>): void;
24
27
  registerRepositories(repositories: Record<string, any>): void;
@@ -29,5 +32,5 @@ export declare class CollectionManager implements ICollectionManager {
29
32
  getCollections(): Array<ICollection>;
30
33
  getRepository(name: string, sourceId?: string | number): IRepository;
31
34
  sync(): Promise<void>;
32
- protected newCollection(options: any): Collection;
35
+ protected newCollection(options: any): ICollection;
33
36
  }
@@ -56,8 +56,15 @@ const _CollectionManager = class _CollectionManager {
56
56
  /* istanbul ignore next -- @preserve */
57
57
  registerFieldTypes() {
58
58
  }
59
- /* istanbul ignore next -- @preserve */
60
- registerFieldInterfaces() {
59
+ registerFieldInterfaces(interfaces) {
60
+ Object.keys(interfaces).forEach((key) => {
61
+ this.registerFieldInterface(key, interfaces[key]);
62
+ });
63
+ }
64
+ registerFieldInterface(name, fieldInterface) {
65
+ }
66
+ getFieldInterface(name) {
67
+ return;
61
68
  }
62
69
  /* istanbul ignore next -- @preserve */
63
70
  registerCollectionTemplates() {
@@ -41,11 +41,15 @@ function findArgs(ctx) {
41
41
  const resourceName = ctx.action.resourceName;
42
42
  const params = ctx.action.params;
43
43
  if (params.tree) {
44
- const [collectionName, associationName] = resourceName.split(".");
45
- const collection = ctx.db.getCollection(resourceName);
46
- if (collection.options.tree && !(associationName && collectionName === collection.name)) {
47
- const foreignKey = ((_a = collection.treeParentField) == null ? void 0 : _a.foreignKey) || "parentId";
48
- (0, import_utils.assign)(params, { filter: { [foreignKey]: null } }, { filter: "andMerge" });
44
+ if ((0, import_utils.isValidFilter)(params.filter)) {
45
+ params.tree = false;
46
+ } else {
47
+ const [collectionName, associationName] = resourceName.split(".");
48
+ const collection = ctx.db.getCollection(resourceName);
49
+ if (collection.options.tree && !(associationName && collectionName === collection.name)) {
50
+ const foreignKey = ((_a = collection.treeParentField) == null ? void 0 : _a.foreignKey) || "parentId";
51
+ (0, import_utils.assign)(params, { filter: { [foreignKey]: null } }, { filter: "andMerge" });
52
+ }
49
53
  }
50
54
  }
51
55
  const { tree, fields, filter, appends, except, sort } = params;
@@ -6,8 +6,8 @@
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 Database from '@nocobase/database';
10
- import { CollectionOptions, ICollection, ICollectionManager, IRepository, MergeOptions } from './types';
9
+ import { Database } from '@nocobase/database';
10
+ import { CollectionOptions, ICollection, ICollectionManager, IFieldInterface, IRepository, MergeOptions } from './types';
11
11
  export declare class SequelizeCollectionManager implements ICollectionManager {
12
12
  db: Database;
13
13
  options: any;
@@ -27,4 +27,8 @@ export declare class SequelizeCollectionManager implements ICollectionManager {
27
27
  getCollections(): import("@nocobase/database").Collection<any, any>[];
28
28
  getRepository<R = IRepository>(name: string, sourceId?: string | number): R;
29
29
  sync(): Promise<void>;
30
+ registerFieldInterface(name: string, fieldInterface: new (options: any) => IFieldInterface): void;
31
+ getFieldInterface(name: string): {
32
+ new (options: any): IFieldInterface | undefined;
33
+ };
30
34
  }
@@ -7,11 +7,9 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- var __create = Object.create;
11
10
  var __defProp = Object.defineProperty;
12
11
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
12
  var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
13
  var __hasOwnProp = Object.prototype.hasOwnProperty;
16
14
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
15
  var __export = (target, all) => {
@@ -26,21 +24,13 @@ var __copyProps = (to, from, except, desc) => {
26
24
  }
27
25
  return to;
28
26
  };
29
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
- // If the importer is in node compatibility mode or this is not an ESM
31
- // file that has been converted to a CommonJS file using a Babel-
32
- // compatible transform (i.e. "__esModule" has not been set), then set
33
- // "default" to the CommonJS "module.exports" for node compatibility.
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
28
  var sequelize_collection_manager_exports = {};
39
29
  __export(sequelize_collection_manager_exports, {
40
30
  SequelizeCollectionManager: () => SequelizeCollectionManager
41
31
  });
42
32
  module.exports = __toCommonJS(sequelize_collection_manager_exports);
43
- var import_database = __toESM(require("@nocobase/database"));
33
+ var import_database = require("@nocobase/database");
44
34
  /* istanbul ignore file -- @preserve */
45
35
  const _SequelizeCollectionManager = class _SequelizeCollectionManager {
46
36
  db;
@@ -58,10 +48,10 @@ const _SequelizeCollectionManager = class _SequelizeCollectionManager {
58
48
  };
59
49
  }
60
50
  createDB(options = {}) {
61
- if (options.database instanceof import_database.default) {
51
+ if (options.database instanceof import_database.Database) {
62
52
  return options.database;
63
53
  }
64
- return new import_database.default(options);
54
+ return new import_database.Database(options);
65
55
  }
66
56
  registerFieldTypes(types) {
67
57
  this.db.registerFieldTypes(types);
@@ -107,6 +97,12 @@ const _SequelizeCollectionManager = class _SequelizeCollectionManager {
107
97
  async sync() {
108
98
  await this.db.sync();
109
99
  }
100
+ registerFieldInterface(name, fieldInterface) {
101
+ this.db.interfaceManager.registerInterfaceType(name, fieldInterface);
102
+ }
103
+ getFieldInterface(name) {
104
+ return this.db.interfaceManager.getInterfaceType(name);
105
+ }
110
106
  };
111
107
  __name(_SequelizeCollectionManager, "SequelizeCollectionManager");
112
108
  let SequelizeCollectionManager = _SequelizeCollectionManager;
package/lib/types.d.ts CHANGED
@@ -30,7 +30,17 @@ export type FieldOptions = {
30
30
  };
31
31
  export interface IField {
32
32
  options: FieldOptions;
33
+ isRelationField(): boolean;
33
34
  }
35
+ export interface IRelationField extends IField {
36
+ targetCollection(): ICollection;
37
+ }
38
+ export interface IFieldInterface {
39
+ options: FieldOptions;
40
+ toString(value: any, ctx?: any): string;
41
+ toValue(str: string, ctx?: any): any;
42
+ }
43
+ export type FindOptions = any;
34
44
  export interface ICollection {
35
45
  repository: IRepository;
36
46
  updateOptions(options: CollectionOptions, mergeOptions?: MergeOptions): void;
@@ -45,7 +55,7 @@ export interface IModel {
45
55
  [key: string]: any;
46
56
  }
47
57
  export interface IRepository {
48
- find(options?: any): Promise<IModel[]>;
58
+ find(options?: FindOptions): Promise<IModel[]>;
49
59
  findOne(options?: any): Promise<IModel>;
50
60
  count(options?: any): Promise<Number>;
51
61
  findAndCount(options?: any): Promise<[IModel[], Number]>;
@@ -59,7 +69,9 @@ export type MergeOptions = {
59
69
  };
60
70
  export interface ICollectionManager {
61
71
  registerFieldTypes(types: Record<string, any>): void;
62
- registerFieldInterfaces(interfaces: Record<string, any>): void;
72
+ registerFieldInterfaces(interfaces: Record<string, new (options: any) => IFieldInterface>): void;
73
+ registerFieldInterface(name: string, fieldInterface: new (options: any) => IFieldInterface): void;
74
+ getFieldInterface(name: string): new (options: any) => IFieldInterface | undefined;
63
75
  registerCollectionTemplates(templates: Record<string, any>): void;
64
76
  registerModels(models: Record<string, any>): void;
65
77
  registerRepositories(repositories: Record<string, any>): void;
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@nocobase/data-source-manager",
3
- "version": "1.0.0-alpha.9",
3
+ "version": "1.0.1-alpha.3",
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.0.0-alpha.9",
10
- "@nocobase/cache": "1.0.0-alpha.9",
11
- "@nocobase/database": "1.0.0-alpha.9",
12
- "@nocobase/resourcer": "1.0.0-alpha.9",
13
- "@nocobase/utils": "1.0.0-alpha.9",
9
+ "@nocobase/actions": "1.0.1-alpha.3",
10
+ "@nocobase/cache": "1.0.1-alpha.3",
11
+ "@nocobase/database": "1.0.1-alpha.3",
12
+ "@nocobase/resourcer": "1.0.1-alpha.3",
13
+ "@nocobase/utils": "1.0.1-alpha.3",
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": "562d6ae965317098df05db756d160e03363dcec5"
22
+ "gitHead": "3b2628db4eaea8973d5364e0674850591e156211"
23
23
  }