@nocobase/data-source-manager 0.20.0-alpha.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.
Files changed (38) hide show
  1. package/LICENSE +201 -0
  2. package/lib/collection-field.d.ts +6 -0
  3. package/lib/collection-field.js +41 -0
  4. package/lib/collection-manager.d.ts +25 -0
  5. package/lib/collection-manager.js +93 -0
  6. package/lib/collection.d.ts +15 -0
  7. package/lib/collection.js +82 -0
  8. package/lib/data-source-factory.d.ts +7 -0
  9. package/lib/data-source-factory.js +45 -0
  10. package/lib/data-source-manager.d.ts +13 -0
  11. package/lib/data-source-manager.js +63 -0
  12. package/lib/data-source-with-database.d.ts +4 -0
  13. package/lib/data-source-with-database.js +15 -0
  14. package/lib/data-source.d.ts +22 -0
  15. package/lib/data-source.js +124 -0
  16. package/lib/default-actions/list.d.ts +2 -0
  17. package/lib/default-actions/list.js +90 -0
  18. package/lib/default-actions/move.d.ts +2 -0
  19. package/lib/default-actions/move.js +54 -0
  20. package/lib/default-actions/proxy-to-repository.d.ts +1 -0
  21. package/lib/default-actions/proxy-to-repository.js +54 -0
  22. package/lib/default-actions/utils.d.ts +7 -0
  23. package/lib/default-actions/utils.js +45 -0
  24. package/lib/index.d.ts +9 -0
  25. package/lib/index.js +37 -0
  26. package/lib/load-default-actions.d.ts +7 -0
  27. package/lib/load-default-actions.js +100 -0
  28. package/lib/repository.d.ts +10 -0
  29. package/lib/repository.js +61 -0
  30. package/lib/resource-manager.d.ts +3 -0
  31. package/lib/resource-manager.js +32 -0
  32. package/lib/sequelize-collection-manager.d.ts +22 -0
  33. package/lib/sequelize-collection-manager.js +106 -0
  34. package/lib/sequelize-data-source.d.ts +6 -0
  35. package/lib/sequelize-data-source.js +38 -0
  36. package/lib/types.d.ts +65 -0
  37. package/lib/types.js +15 -0
  38. package/package.json +23 -0
@@ -0,0 +1,22 @@
1
+ import Database from '@nocobase/database';
2
+ import { CollectionOptions, ICollection, ICollectionManager, IRepository, MergeOptions } from './types';
3
+ export declare class SequelizeCollectionManager implements ICollectionManager {
4
+ db: Database;
5
+ options: any;
6
+ constructor(options: any);
7
+ collectionsFilter(): any;
8
+ createDB(options?: any): any;
9
+ registerFieldTypes(types: Record<string, any>): void;
10
+ registerFieldInterfaces(): void;
11
+ registerCollectionTemplates(): void;
12
+ registerModels(models: Record<string, any>): void;
13
+ registerRepositories(repositories: Record<string, any>): void;
14
+ getRegisteredRepository(key: any): any;
15
+ defineCollection(options: CollectionOptions): import("@nocobase/database").Collection<any, any>;
16
+ extendCollection(collectionOptions: CollectionOptions, mergeOptions?: MergeOptions): ICollection;
17
+ hasCollection(name: string): boolean;
18
+ getCollection(name: string): import("@nocobase/database").Collection<any, any>;
19
+ getCollections(): import("@nocobase/database").Collection<any, any>[];
20
+ getRepository<R = IRepository>(name: string, sourceId?: string | number): R;
21
+ sync(): Promise<void>;
22
+ }
@@ -0,0 +1,106 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var sequelize_collection_manager_exports = {};
30
+ __export(sequelize_collection_manager_exports, {
31
+ SequelizeCollectionManager: () => SequelizeCollectionManager
32
+ });
33
+ module.exports = __toCommonJS(sequelize_collection_manager_exports);
34
+ var import_database = __toESM(require("@nocobase/database"));
35
+ const _SequelizeCollectionManager = class _SequelizeCollectionManager {
36
+ db;
37
+ options;
38
+ constructor(options) {
39
+ this.db = this.createDB(options);
40
+ this.options = options;
41
+ }
42
+ collectionsFilter() {
43
+ if (this.options.collectionsFilter) {
44
+ return this.options.collectionsFilter;
45
+ }
46
+ return (collection) => {
47
+ return collection.options.introspected;
48
+ };
49
+ }
50
+ createDB(options = {}) {
51
+ if (options.database instanceof import_database.default) {
52
+ return options.database;
53
+ }
54
+ return new import_database.default(options);
55
+ }
56
+ registerFieldTypes(types) {
57
+ this.db.registerFieldTypes(types);
58
+ }
59
+ registerFieldInterfaces() {
60
+ }
61
+ registerCollectionTemplates() {
62
+ }
63
+ registerModels(models) {
64
+ return this.db.registerModels(models);
65
+ }
66
+ registerRepositories(repositories) {
67
+ return this.db.registerModels(repositories);
68
+ }
69
+ getRegisteredRepository(key) {
70
+ if (typeof key !== "string") {
71
+ return key;
72
+ }
73
+ return this.db.repositories.get(key);
74
+ }
75
+ defineCollection(options) {
76
+ const collection = this.db.collection(options);
77
+ collection.model.refreshAttributes();
78
+ collection.model._findAutoIncrementAttribute();
79
+ return collection;
80
+ }
81
+ extendCollection(collectionOptions, mergeOptions) {
82
+ return this.db.extendCollection(collectionOptions, mergeOptions);
83
+ }
84
+ hasCollection(name) {
85
+ return this.db.hasCollection(name);
86
+ }
87
+ getCollection(name) {
88
+ return this.db.getCollection(name);
89
+ }
90
+ getCollections() {
91
+ const collectionsFilter = this.collectionsFilter();
92
+ return [...this.db.collections.values()].filter((collection) => collectionsFilter(collection));
93
+ }
94
+ getRepository(name, sourceId) {
95
+ return this.db.getRepository(name, sourceId);
96
+ }
97
+ async sync() {
98
+ await this.db.sync();
99
+ }
100
+ };
101
+ __name(_SequelizeCollectionManager, "SequelizeCollectionManager");
102
+ let SequelizeCollectionManager = _SequelizeCollectionManager;
103
+ // Annotate the CommonJS export names for ESM import in node:
104
+ 0 && (module.exports = {
105
+ SequelizeCollectionManager
106
+ });
@@ -0,0 +1,6 @@
1
+ import { DataSource } from './data-source';
2
+ import { SequelizeCollectionManager } from './sequelize-collection-manager';
3
+ export declare class SequelizeDataSource extends DataSource {
4
+ load(): Promise<void>;
5
+ createCollectionManager(options?: any): SequelizeCollectionManager;
6
+ }
@@ -0,0 +1,38 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var sequelize_data_source_exports = {};
20
+ __export(sequelize_data_source_exports, {
21
+ SequelizeDataSource: () => SequelizeDataSource
22
+ });
23
+ module.exports = __toCommonJS(sequelize_data_source_exports);
24
+ var import_data_source = require("./data-source");
25
+ var import_sequelize_collection_manager = require("./sequelize-collection-manager");
26
+ const _SequelizeDataSource = class _SequelizeDataSource extends import_data_source.DataSource {
27
+ async load() {
28
+ }
29
+ createCollectionManager(options) {
30
+ return new import_sequelize_collection_manager.SequelizeCollectionManager(options.collectionManager);
31
+ }
32
+ };
33
+ __name(_SequelizeDataSource, "SequelizeDataSource");
34
+ let SequelizeDataSource = _SequelizeDataSource;
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ SequelizeDataSource
38
+ });
package/lib/types.d.ts ADDED
@@ -0,0 +1,65 @@
1
+ export type CollectionOptions = {
2
+ name: string;
3
+ repository?: string;
4
+ fields: any[];
5
+ [key: string]: any;
6
+ };
7
+ export type FieldOptions = {
8
+ name: string;
9
+ field: string;
10
+ rawType: string;
11
+ type: string;
12
+ description?: string;
13
+ interface?: string;
14
+ uiSchema?: any;
15
+ possibleTypes?: string[];
16
+ defaultValue?: any;
17
+ primaryKey: boolean;
18
+ unique: boolean;
19
+ allowNull?: boolean;
20
+ autoIncrement?: boolean;
21
+ [key: string]: any;
22
+ };
23
+ export interface IField {
24
+ options: FieldOptions;
25
+ }
26
+ export interface ICollection {
27
+ repository: any;
28
+ updateOptions(options: any): void;
29
+ setField(name: string, options: any): IField;
30
+ removeField(name: string): void;
31
+ getFields(): Array<IField>;
32
+ getField(name: string): IField;
33
+ [key: string]: any;
34
+ }
35
+ export interface IModel {
36
+ [key: string]: any;
37
+ }
38
+ export interface IRepository {
39
+ find(options?: any): Promise<IModel[]>;
40
+ findOne(options?: any): Promise<IModel>;
41
+ count(options?: any): Promise<Number>;
42
+ findAndCount(options?: any): Promise<[IModel[], Number]>;
43
+ create(options: any): void;
44
+ update(options: any): void;
45
+ destroy(options: any): void;
46
+ [key: string]: any;
47
+ }
48
+ export type MergeOptions = {
49
+ [key: string]: any;
50
+ };
51
+ export interface ICollectionManager {
52
+ registerFieldTypes(types: Record<string, any>): void;
53
+ registerFieldInterfaces(interfaces: Record<string, any>): void;
54
+ registerCollectionTemplates(templates: Record<string, any>): void;
55
+ registerModels(models: Record<string, any>): void;
56
+ registerRepositories(repositories: Record<string, any>): void;
57
+ getRegisteredRepository(key: string): IRepository;
58
+ defineCollection(options: CollectionOptions): ICollection;
59
+ extendCollection(collectionOptions: CollectionOptions, mergeOptions?: MergeOptions): ICollection;
60
+ hasCollection(name: string): boolean;
61
+ getCollection(name: string): ICollection;
62
+ getCollections(): Array<ICollection>;
63
+ getRepository(name: string, sourceId?: string | number): IRepository;
64
+ sync(): Promise<void>;
65
+ }
package/lib/types.js ADDED
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var types_exports = {};
15
+ module.exports = __toCommonJS(types_exports);
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@nocobase/data-source-manager",
3
+ "version": "0.20.0-alpha.1",
4
+ "description": "",
5
+ "license": "Apache-2.0",
6
+ "main": "./lib/index.js",
7
+ "types": "./lib/index.d.ts",
8
+ "dependencies": {
9
+ "@nocobase/actions": "0.20.0-alpha.1",
10
+ "@nocobase/cache": "0.20.0-alpha.1",
11
+ "@nocobase/database": "0.20.0-alpha.1",
12
+ "@nocobase/resourcer": "0.20.0-alpha.1",
13
+ "@nocobase/utils": "0.20.0-alpha.1",
14
+ "@types/jsonwebtoken": "^8.5.8",
15
+ "jsonwebtoken": "^8.5.1"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/nocobase/nocobase.git",
20
+ "directory": "packages/auth"
21
+ },
22
+ "gitHead": "516c0b1470d77ff499f533ae6b57e4c084450ff5"
23
+ }