@nocobase/database 1.2.12-alpha → 1.3.0-alpha.20240710084543
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.
- package/package.json +4 -4
- package/lib/collection-factory.d.ts +0 -25
- package/lib/collection-factory.js +0 -61
- package/lib/collection-group-manager.d.ts +0 -34
- package/lib/collection-group-manager.js +0 -66
- package/lib/collection-importer.d.ts +0 -15
- package/lib/collection-importer.js +0 -83
- package/lib/collection.d.ts +0 -145
- package/lib/collection.js +0 -663
- package/lib/database-utils/index.d.ts +0 -16
- package/lib/database-utils/index.js +0 -75
- package/lib/database.d.ts +0 -228
- package/lib/database.js +0 -795
- package/lib/decorators/must-have-filter-decorator.d.ts +0 -10
- package/lib/decorators/must-have-filter-decorator.js +0 -48
- package/lib/decorators/target-collection-decorator.d.ts +0 -10
- package/lib/decorators/target-collection-decorator.js +0 -56
- package/lib/decorators/transaction-decorator.d.ts +0 -9
- package/lib/decorators/transaction-decorator.js +0 -95
- package/lib/eager-loading/eager-loading-tree.d.ts +0 -39
- package/lib/eager-loading/eager-loading-tree.js +0 -448
- package/lib/errors/identifier-error.d.ts +0 -11
- package/lib/errors/identifier-error.js +0 -44
- package/lib/errors/zero-column-table-error.d.ts +0 -10
- package/lib/errors/zero-column-table-error.js +0 -40
- package/lib/features/references-map.d.ts +0 -29
- package/lib/features/references-map.js +0 -120
- package/lib/features/referential-integrity-check.d.ts +0 -16
- package/lib/features/referential-integrity-check.js +0 -86
- package/lib/field-repository/array-field-repository.d.ts +0 -36
- package/lib/field-repository/array-field-repository.js +0 -179
- package/lib/fields/array-field.d.ts +0 -19
- package/lib/fields/array-field.js +0 -66
- package/lib/fields/belongs-to-field.d.ts +0 -25
- package/lib/fields/belongs-to-field.js +0 -166
- package/lib/fields/belongs-to-many-field.d.ts +0 -28
- package/lib/fields/belongs-to-many-field.js +0 -196
- package/lib/fields/boolean-field.d.ts +0 -16
- package/lib/fields/boolean-field.js +0 -45
- package/lib/fields/context-field.d.ts +0 -22
- package/lib/fields/context-field.js +0 -79
- package/lib/fields/date-field.d.ts +0 -21
- package/lib/fields/date-field.js +0 -73
- package/lib/fields/field.d.ts +0 -52
- package/lib/fields/field.js +0 -168
- package/lib/fields/has-inverse-field.d.ts +0 -12
- package/lib/fields/has-inverse-field.js +0 -24
- package/lib/fields/has-many-field.d.ts +0 -76
- package/lib/fields/has-many-field.js +0 -165
- package/lib/fields/has-one-field.d.ts +0 -76
- package/lib/fields/has-one-field.js +0 -159
- package/lib/fields/index.d.ts +0 -54
- package/lib/fields/index.js +0 -74
- package/lib/fields/json-field.d.ts +0 -22
- package/lib/fields/json-field.js +0 -63
- package/lib/fields/nanoid-field.d.ts +0 -22
- package/lib/fields/nanoid-field.js +0 -65
- package/lib/fields/number-field.d.ts +0 -49
- package/lib/fields/number-field.js +0 -94
- package/lib/fields/password-field.d.ts +0 -29
- package/lib/fields/password-field.js +0 -106
- package/lib/fields/radio-field.d.ts +0 -24
- package/lib/fields/radio-field.js +0 -75
- package/lib/fields/relation-field.d.ts +0 -31
- package/lib/fields/relation-field.js +0 -94
- package/lib/fields/set-field.d.ts +0 -18
- package/lib/fields/set-field.js +0 -55
- package/lib/fields/sort-field.d.ts +0 -22
- package/lib/fields/sort-field.js +0 -197
- package/lib/fields/string-field.d.ts +0 -16
- package/lib/fields/string-field.js +0 -45
- package/lib/fields/text-field.d.ts +0 -18
- package/lib/fields/text-field.js +0 -53
- package/lib/fields/time-field.d.ts +0 -16
- package/lib/fields/time-field.js +0 -45
- package/lib/fields/uid-field.d.ts +0 -21
- package/lib/fields/uid-field.js +0 -72
- package/lib/fields/uuid-field.d.ts +0 -20
- package/lib/fields/uuid-field.js +0 -63
- package/lib/fields/virtual-field.d.ts +0 -16
- package/lib/fields/virtual-field.js +0 -45
- package/lib/filter-match.d.ts +0 -9
- package/lib/filter-match.js +0 -75
- package/lib/filter-parser.d.ts +0 -29
- package/lib/filter-parser.js +0 -238
- package/lib/helpers.d.ts +0 -11
- package/lib/helpers.js +0 -182
- package/lib/index.d.ts +0 -37
- package/lib/index.js +0 -138
- package/lib/inherited-collection.d.ts +0 -22
- package/lib/inherited-collection.js +0 -147
- package/lib/inherited-map.d.ts +0 -29
- package/lib/inherited-map.js +0 -125
- package/lib/inherited-sync-runner.d.ts +0 -12
- package/lib/inherited-sync-runner.js +0 -184
- package/lib/interface-manager.d.ts +0 -17
- package/lib/interface-manager.js +0 -50
- package/lib/interfaces/base-interface.d.ts +0 -33
- package/lib/interfaces/base-interface.js +0 -80
- package/lib/interfaces/boolean-interface.d.ts +0 -13
- package/lib/interfaces/boolean-interface.js +0 -70
- package/lib/interfaces/checkboxes-interface.d.ts +0 -11
- package/lib/interfaces/checkboxes-interface.js +0 -41
- package/lib/interfaces/datetime-interface.d.ts +0 -13
- package/lib/interfaces/datetime-interface.js +0 -108
- package/lib/interfaces/index.d.ts +0 -14
- package/lib/interfaces/index.js +0 -40
- package/lib/interfaces/integer-interface.d.ts +0 -12
- package/lib/interfaces/integer-interface.js +0 -44
- package/lib/interfaces/json-interface.d.ts +0 -13
- package/lib/interfaces/json-interface.js +0 -47
- package/lib/interfaces/many-to-many-interface.d.ts +0 -11
- package/lib/interfaces/many-to-many-interface.js +0 -41
- package/lib/interfaces/many-to-one-interface.d.ts +0 -11
- package/lib/interfaces/many-to-one-interface.js +0 -41
- package/lib/interfaces/multiple-select-interface.d.ts +0 -13
- package/lib/interfaces/multiple-select-interface.js +0 -76
- package/lib/interfaces/number-interface.d.ts +0 -15
- package/lib/interfaces/number-interface.js +0 -72
- package/lib/interfaces/one-belongs-to-one-interface.d.ts +0 -11
- package/lib/interfaces/one-belongs-to-one-interface.js +0 -41
- package/lib/interfaces/one-has-one-interface.d.ts +0 -11
- package/lib/interfaces/one-has-one-interface.js +0 -41
- package/lib/interfaces/one-to-many-interface.d.ts +0 -11
- package/lib/interfaces/one-to-many-interface.js +0 -41
- package/lib/interfaces/percent-interface.d.ts +0 -13
- package/lib/interfaces/percent-interface.js +0 -55
- package/lib/interfaces/select-interface.d.ts +0 -13
- package/lib/interfaces/select-interface.js +0 -63
- package/lib/interfaces/to-many-interface.d.ts +0 -12
- package/lib/interfaces/to-many-interface.js +0 -61
- package/lib/interfaces/to-one-interface.d.ts +0 -13
- package/lib/interfaces/to-one-interface.js +0 -61
- package/lib/interfaces/utils.d.ts +0 -10
- package/lib/interfaces/utils.js +0 -72
- package/lib/listeners/adjacency-list.d.ts +0 -10
- package/lib/listeners/adjacency-list.js +0 -51
- package/lib/listeners/append-child-collection-name-after-repository-find.d.ts +0 -14
- package/lib/listeners/append-child-collection-name-after-repository-find.js +0 -75
- package/lib/listeners/index.d.ts +0 -10
- package/lib/listeners/index.js +0 -42
- package/lib/magic-attribute-model.d.ts +0 -16
- package/lib/magic-attribute-model.js +0 -213
- package/lib/migration.d.ts +0 -43
- package/lib/migration.js +0 -112
- package/lib/mock-database.d.ts +0 -33
- package/lib/mock-database.js +0 -136
- package/lib/model-hook.d.ts +0 -20
- package/lib/model-hook.js +0 -96
- package/lib/model.d.ts +0 -32
- package/lib/model.js +0 -179
- package/lib/operators/array.d.ts +0 -10
- package/lib/operators/array.js +0 -196
- package/lib/operators/association.d.ts +0 -10
- package/lib/operators/association.js +0 -44
- package/lib/operators/boolean.d.ts +0 -10
- package/lib/operators/boolean.js +0 -47
- package/lib/operators/child-collection.d.ts +0 -10
- package/lib/operators/child-collection.js +0 -77
- package/lib/operators/date.d.ts +0 -10
- package/lib/operators/date.js +0 -149
- package/lib/operators/empty.d.ts +0 -13
- package/lib/operators/empty.js +0 -102
- package/lib/operators/eq.d.ts +0 -10
- package/lib/operators/eq.js +0 -44
- package/lib/operators/index.d.ts +0 -13
- package/lib/operators/index.js +0 -63
- package/lib/operators/ne.d.ts +0 -10
- package/lib/operators/ne.js +0 -49
- package/lib/operators/notIn.d.ts +0 -10
- package/lib/operators/notIn.js +0 -42
- package/lib/operators/string.d.ts +0 -10
- package/lib/operators/string.js +0 -118
- package/lib/operators/utils.d.ts +0 -12
- package/lib/operators/utils.js +0 -53
- package/lib/options-parser.d.ts +0 -45
- package/lib/options-parser.js +0 -350
- package/lib/query-interface/mysql-query-interface.d.ts +0 -44
- package/lib/query-interface/mysql-query-interface.js +0 -134
- package/lib/query-interface/postgres-query-interface.d.ts +0 -41
- package/lib/query-interface/postgres-query-interface.js +0 -207
- package/lib/query-interface/query-interface-builder.d.ts +0 -10
- package/lib/query-interface/query-interface-builder.js +0 -55
- package/lib/query-interface/query-interface.d.ts +0 -52
- package/lib/query-interface/query-interface.js +0 -59
- package/lib/query-interface/sqlite-query-interface.d.ts +0 -44
- package/lib/query-interface/sqlite-query-interface.js +0 -141
- package/lib/relation-repository/belongs-to-many-repository.d.ts +0 -28
- package/lib/relation-repository/belongs-to-many-repository.js +0 -248
- package/lib/relation-repository/belongs-to-repository.d.ts +0 -17
- package/lib/relation-repository/belongs-to-repository.js +0 -51
- package/lib/relation-repository/hasmany-repository.d.ts +0 -21
- package/lib/relation-repository/hasmany-repository.js +0 -158
- package/lib/relation-repository/hasone-repository.d.ts +0 -17
- package/lib/relation-repository/hasone-repository.js +0 -51
- package/lib/relation-repository/multiple-relation-repository.d.ts +0 -27
- package/lib/relation-repository/multiple-relation-repository.js +0 -200
- package/lib/relation-repository/relation-repository.d.ts +0 -38
- package/lib/relation-repository/relation-repository.js +0 -175
- package/lib/relation-repository/single-relation-repository.d.ts +0 -36
- package/lib/relation-repository/single-relation-repository.js +0 -151
- package/lib/relation-repository/types.d.ts +0 -15
- package/lib/relation-repository/types.js +0 -24
- package/lib/repositories/tree-repository/adjacency-list-repository.d.ts +0 -26
- package/lib/repositories/tree-repository/adjacency-list-repository.js +0 -192
- package/lib/repositories/view-repository.d.ts +0 -11
- package/lib/repositories/view-repository.js +0 -41
- package/lib/repository.d.ts +0 -214
- package/lib/repository.js +0 -609
- package/lib/sql-parser/index.d.ts +0 -13
- package/lib/sql-parser/index.js +0 -33
- package/lib/sync-runner.d.ts +0 -41
- package/lib/sync-runner.js +0 -335
- package/lib/types.d.ts +0 -57
- package/lib/types.js +0 -24
- package/lib/update-associations.d.ts +0 -68
- package/lib/update-associations.js +0 -429
- package/lib/update-guard.d.ts +0 -36
- package/lib/update-guard.js +0 -212
- package/lib/utils.d.ts +0 -15
- package/lib/utils.js +0 -136
- package/lib/value-parsers/array-value-parser.d.ts +0 -16
- package/lib/value-parsers/array-value-parser.js +0 -67
- package/lib/value-parsers/base-value-parser.d.ts +0 -20
- package/lib/value-parsers/base-value-parser.js +0 -72
- package/lib/value-parsers/boolean-value-parser.d.ts +0 -12
- package/lib/value-parsers/boolean-value-parser.js +0 -61
- package/lib/value-parsers/date-value-parser.d.ts +0 -13
- package/lib/value-parsers/date-value-parser.js +0 -99
- package/lib/value-parsers/index.d.ts +0 -20
- package/lib/value-parsers/index.js +0 -87
- package/lib/value-parsers/json-value-parser.d.ts +0 -12
- package/lib/value-parsers/json-value-parser.js +0 -56
- package/lib/value-parsers/number-value-parser.d.ts +0 -12
- package/lib/value-parsers/number-value-parser.js +0 -67
- package/lib/value-parsers/string-value-parser.d.ts +0 -16
- package/lib/value-parsers/string-value-parser.js +0 -73
- package/lib/value-parsers/to-many-value-parser.d.ts +0 -21
- package/lib/value-parsers/to-many-value-parser.js +0 -117
- package/lib/value-parsers/to-one-value-parser.d.ts +0 -12
- package/lib/value-parsers/to-one-value-parser.js +0 -57
- package/lib/view/field-type-map.d.ts +0 -109
- package/lib/view/field-type-map.js +0 -101
- package/lib/view/view-inference.d.ts +0 -40
- package/lib/view/view-inference.js +0 -157
- package/lib/view-collection.d.ts +0 -14
- package/lib/view-collection.js +0 -54
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
import { TargetKey, Values } from '../repository';
|
|
10
|
-
import { Transactionable } from 'sequelize';
|
|
11
|
-
export type PrimaryKeyWithThroughValues = [TargetKey, Values];
|
|
12
|
-
export interface AssociatedOptions extends Transactionable {
|
|
13
|
-
tk?: TargetKey | TargetKey[] | PrimaryKeyWithThroughValues | PrimaryKeyWithThroughValues[];
|
|
14
|
-
}
|
|
15
|
-
export type setAssociationOptions = TargetKey | TargetKey[] | PrimaryKeyWithThroughValues | PrimaryKeyWithThroughValues[] | AssociatedOptions;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
-
var __copyProps = (to, from, except, desc) => {
|
|
15
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
-
for (let key of __getOwnPropNames(from))
|
|
17
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
-
var types_exports = {};
|
|
24
|
-
module.exports = __toCommonJS(types_exports);
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
import { FindOptions, Repository } from '../../repository';
|
|
10
|
-
import Database from '../../database';
|
|
11
|
-
import { Collection } from '../../collection';
|
|
12
|
-
export declare class AdjacencyListRepository extends Repository {
|
|
13
|
-
static queryParentSQL(options: {
|
|
14
|
-
db: Database;
|
|
15
|
-
nodeIds: any[];
|
|
16
|
-
collection: Collection;
|
|
17
|
-
foreignKey: string;
|
|
18
|
-
targetKey: string;
|
|
19
|
-
}): string;
|
|
20
|
-
update(options: any): Promise<any>;
|
|
21
|
-
find(options?: FindOptions & {
|
|
22
|
-
addIndex?: boolean;
|
|
23
|
-
}): Promise<any>;
|
|
24
|
-
private addIndex;
|
|
25
|
-
private querySQL;
|
|
26
|
-
}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __create = Object.create;
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
|
-
var __export = (target, all) => {
|
|
18
|
-
for (var name in all)
|
|
19
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
-
};
|
|
21
|
-
var __copyProps = (to, from, except, desc) => {
|
|
22
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
-
for (let key of __getOwnPropNames(from))
|
|
24
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
-
}
|
|
27
|
-
return to;
|
|
28
|
-
};
|
|
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
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
-
var adjacency_list_repository_exports = {};
|
|
39
|
-
__export(adjacency_list_repository_exports, {
|
|
40
|
-
AdjacencyListRepository: () => AdjacencyListRepository
|
|
41
|
-
});
|
|
42
|
-
module.exports = __toCommonJS(adjacency_list_repository_exports);
|
|
43
|
-
var import_lodash = __toESM(require("lodash"));
|
|
44
|
-
var import_repository = require("../../repository");
|
|
45
|
-
const _AdjacencyListRepository = class _AdjacencyListRepository extends import_repository.Repository {
|
|
46
|
-
static queryParentSQL(options) {
|
|
47
|
-
const { collection, db, nodeIds } = options;
|
|
48
|
-
const tableName = collection.quotedTableName();
|
|
49
|
-
const { foreignKey, targetKey } = options;
|
|
50
|
-
const foreignKeyField = collection.model.rawAttributes[foreignKey].field;
|
|
51
|
-
const targetKeyField = collection.model.rawAttributes[targetKey].field;
|
|
52
|
-
const queryInterface = db.sequelize.getQueryInterface();
|
|
53
|
-
const q = queryInterface.quoteIdentifier.bind(queryInterface);
|
|
54
|
-
return `WITH RECURSIVE cte AS (
|
|
55
|
-
SELECT ${q(targetKeyField)}, ${q(foreignKeyField)}
|
|
56
|
-
FROM ${tableName}
|
|
57
|
-
WHERE ${q(targetKeyField)} IN (${nodeIds.join(",")})
|
|
58
|
-
UNION ALL
|
|
59
|
-
SELECT t.${q(targetKeyField)}, t.${q(foreignKeyField)}
|
|
60
|
-
FROM ${tableName} AS t
|
|
61
|
-
INNER JOIN cte ON t.${q(targetKeyField)} = cte.${q(foreignKeyField)}
|
|
62
|
-
)
|
|
63
|
-
SELECT ${q(targetKeyField)} AS ${q(targetKey)}, ${q(foreignKeyField)} AS ${q(foreignKey)} FROM cte`;
|
|
64
|
-
}
|
|
65
|
-
async update(options) {
|
|
66
|
-
return super.update({
|
|
67
|
-
...options || {},
|
|
68
|
-
addIndex: false
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
async find(options = {}) {
|
|
72
|
-
var _a;
|
|
73
|
-
if (options.raw || !options.tree) {
|
|
74
|
-
return await super.find(options);
|
|
75
|
-
}
|
|
76
|
-
const collection = this.collection;
|
|
77
|
-
const primaryKey = collection.model.primaryKeyAttribute;
|
|
78
|
-
if (options.fields && !options.fields.includes(primaryKey)) {
|
|
79
|
-
options.fields.push(primaryKey);
|
|
80
|
-
}
|
|
81
|
-
const parentNodes = await super.find(options);
|
|
82
|
-
if (parentNodes.length === 0) {
|
|
83
|
-
return [];
|
|
84
|
-
}
|
|
85
|
-
const { treeParentField } = collection;
|
|
86
|
-
const foreignKey = treeParentField.options.foreignKey;
|
|
87
|
-
const childrenKey = ((_a = collection.treeChildrenField) == null ? void 0 : _a.name) ?? "children";
|
|
88
|
-
const parentIds = parentNodes.map((node) => node[primaryKey]);
|
|
89
|
-
if (parentIds.length == 0) {
|
|
90
|
-
this.database.logger.warn("parentIds is empty");
|
|
91
|
-
return parentNodes;
|
|
92
|
-
}
|
|
93
|
-
const sql = this.querySQL(parentIds, collection);
|
|
94
|
-
const childNodes = await this.database.sequelize.query(sql, {
|
|
95
|
-
type: "SELECT",
|
|
96
|
-
transaction: options.transaction
|
|
97
|
-
});
|
|
98
|
-
const childIds = childNodes.map((node) => node[primaryKey]);
|
|
99
|
-
const findChildrenOptions = {
|
|
100
|
-
...import_lodash.default.omit(options, ["limit", "offset", "filterByTk"]),
|
|
101
|
-
filter: {
|
|
102
|
-
[primaryKey]: childIds
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
if (findChildrenOptions.fields) {
|
|
106
|
-
[primaryKey, foreignKey].forEach((field) => {
|
|
107
|
-
if (!findChildrenOptions.fields.includes(field)) {
|
|
108
|
-
findChildrenOptions.fields.push(field);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
const childInstances = await super.find(findChildrenOptions);
|
|
113
|
-
const nodeMap = {};
|
|
114
|
-
childInstances.forEach((node) => {
|
|
115
|
-
if (!nodeMap[`${node[foreignKey]}`]) {
|
|
116
|
-
nodeMap[`${node[foreignKey]}`] = [];
|
|
117
|
-
}
|
|
118
|
-
nodeMap[`${node[foreignKey]}`].push(node);
|
|
119
|
-
});
|
|
120
|
-
function buildTree(parentId) {
|
|
121
|
-
const children = nodeMap[parentId];
|
|
122
|
-
if (!children) {
|
|
123
|
-
return [];
|
|
124
|
-
}
|
|
125
|
-
return children.map((child) => {
|
|
126
|
-
const childrenValues = buildTree(child.id);
|
|
127
|
-
if (childrenValues.length > 0) {
|
|
128
|
-
child.setDataValue(childrenKey, childrenValues);
|
|
129
|
-
}
|
|
130
|
-
return child;
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
__name(buildTree, "buildTree");
|
|
134
|
-
for (const parent of parentNodes) {
|
|
135
|
-
const parentId = parent[primaryKey];
|
|
136
|
-
const children = buildTree(parentId);
|
|
137
|
-
if (children.length > 0) {
|
|
138
|
-
parent.setDataValue(childrenKey, children);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
this.addIndex(parentNodes, childrenKey, options);
|
|
142
|
-
return parentNodes;
|
|
143
|
-
}
|
|
144
|
-
addIndex(treeArray, childrenKey, options) {
|
|
145
|
-
function traverse(node, index) {
|
|
146
|
-
if (node._options.includeNames && !node._options.includeNames.includes(childrenKey)) {
|
|
147
|
-
node._options.includeNames.push(childrenKey);
|
|
148
|
-
}
|
|
149
|
-
if (options.addIndex !== false) {
|
|
150
|
-
node.setDataValue("__index", `${index}`);
|
|
151
|
-
}
|
|
152
|
-
const children = node.getDataValue(childrenKey);
|
|
153
|
-
if (children && children.length === 0) {
|
|
154
|
-
node.setDataValue(childrenKey, void 0);
|
|
155
|
-
}
|
|
156
|
-
if (children && children.length > 0) {
|
|
157
|
-
children.forEach((child, i) => {
|
|
158
|
-
traverse(child, `${index}.${childrenKey}.${i}`);
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
__name(traverse, "traverse");
|
|
163
|
-
treeArray.forEach((tree, i) => {
|
|
164
|
-
traverse(tree, i);
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
querySQL(rootIds, collection) {
|
|
168
|
-
const { treeParentField } = collection;
|
|
169
|
-
const foreignKey = treeParentField.options.foreignKey;
|
|
170
|
-
const foreignKeyField = collection.model.rawAttributes[foreignKey].field;
|
|
171
|
-
const primaryKey = collection.model.primaryKeyAttribute;
|
|
172
|
-
const queryInterface = this.database.sequelize.getQueryInterface();
|
|
173
|
-
const q = queryInterface.quoteIdentifier.bind(queryInterface);
|
|
174
|
-
return `
|
|
175
|
-
WITH RECURSIVE cte AS (SELECT ${q(primaryKey)}, ${q(foreignKeyField)}, 1 AS level
|
|
176
|
-
FROM ${collection.quotedTableName()}
|
|
177
|
-
WHERE ${q(foreignKeyField)} IN (${rootIds.join(",")})
|
|
178
|
-
UNION ALL
|
|
179
|
-
SELECT t.${q(primaryKey)}, t.${q(foreignKeyField)}, cte.level + 1 AS level
|
|
180
|
-
FROM ${collection.quotedTableName()} t
|
|
181
|
-
JOIN cte ON t.${q(foreignKeyField)} = cte.${q(primaryKey)})
|
|
182
|
-
SELECT ${q(primaryKey)}, ${q(foreignKeyField)} as ${q(foreignKey)}, level
|
|
183
|
-
FROM cte
|
|
184
|
-
`;
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
__name(_AdjacencyListRepository, "AdjacencyListRepository");
|
|
188
|
-
let AdjacencyListRepository = _AdjacencyListRepository;
|
|
189
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
190
|
-
0 && (module.exports = {
|
|
191
|
-
AdjacencyListRepository
|
|
192
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
import { Repository } from '../repository';
|
|
10
|
-
export declare class ViewRepository extends Repository {
|
|
11
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
-
var __export = (target, all) => {
|
|
16
|
-
for (var name in all)
|
|
17
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
-
};
|
|
19
|
-
var __copyProps = (to, from, except, desc) => {
|
|
20
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
-
for (let key of __getOwnPropNames(from))
|
|
22
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
-
}
|
|
25
|
-
return to;
|
|
26
|
-
};
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var view_repository_exports = {};
|
|
29
|
-
__export(view_repository_exports, {
|
|
30
|
-
ViewRepository: () => ViewRepository
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(view_repository_exports);
|
|
33
|
-
var import_repository = require("../repository");
|
|
34
|
-
const _ViewRepository = class _ViewRepository extends import_repository.Repository {
|
|
35
|
-
};
|
|
36
|
-
__name(_ViewRepository, "ViewRepository");
|
|
37
|
-
let ViewRepository = _ViewRepository;
|
|
38
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
-
0 && (module.exports = {
|
|
40
|
-
ViewRepository
|
|
41
|
-
});
|
package/lib/repository.d.ts
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
/// <reference types="node" />
|
|
10
|
-
import { Association, BulkCreateOptions, CountOptions as SequelizeCountOptions, CreateOptions as SequelizeCreateOptions, DestroyOptions as SequelizeDestroyOptions, FindAndCountOptions as SequelizeAndCountOptions, FindOptions as SequelizeFindOptions, ModelStatic, Transactionable, UpdateOptions as SequelizeUpdateOptions, WhereOperators } from 'sequelize';
|
|
11
|
-
import { Collection } from './collection';
|
|
12
|
-
import { Database } from './database';
|
|
13
|
-
import { ArrayFieldRepository } from './field-repository/array-field-repository';
|
|
14
|
-
import { Model } from './model';
|
|
15
|
-
import operators from './operators';
|
|
16
|
-
import { BelongsToManyRepository } from './relation-repository/belongs-to-many-repository';
|
|
17
|
-
import { BelongsToRepository } from './relation-repository/belongs-to-repository';
|
|
18
|
-
import { HasManyRepository } from './relation-repository/hasmany-repository';
|
|
19
|
-
import { HasOneRepository } from './relation-repository/hasone-repository';
|
|
20
|
-
import { RelationRepository } from './relation-repository/relation-repository';
|
|
21
|
-
interface CreateManyOptions extends BulkCreateOptions {
|
|
22
|
-
records: Values[];
|
|
23
|
-
}
|
|
24
|
-
export { Transactionable } from 'sequelize';
|
|
25
|
-
export interface FilterAble {
|
|
26
|
-
filter: Filter;
|
|
27
|
-
}
|
|
28
|
-
export type TargetKey = string | number;
|
|
29
|
-
export type TK = TargetKey | TargetKey[];
|
|
30
|
-
type FieldValue = string | number | bigint | boolean | Date | Buffer | null | FieldValue[] | FilterWithOperator;
|
|
31
|
-
type Operators = keyof typeof operators & keyof WhereOperators;
|
|
32
|
-
export type FilterWithOperator = {
|
|
33
|
-
[key: string]: {
|
|
34
|
-
[K in Operators]: FieldValue;
|
|
35
|
-
} | FieldValue;
|
|
36
|
-
};
|
|
37
|
-
export type FilterWithValue = {
|
|
38
|
-
[key: string]: FieldValue;
|
|
39
|
-
};
|
|
40
|
-
type FilterAnd = {
|
|
41
|
-
$and: Filter[];
|
|
42
|
-
};
|
|
43
|
-
type FilterOr = {
|
|
44
|
-
$or: Filter[];
|
|
45
|
-
};
|
|
46
|
-
export type Filter = FilterWithOperator | FilterWithValue | FilterAnd | FilterOr;
|
|
47
|
-
export type Appends = string[];
|
|
48
|
-
export type Except = string[];
|
|
49
|
-
export type Fields = string[];
|
|
50
|
-
export type Sort = string[] | string;
|
|
51
|
-
export type WhiteList = string[];
|
|
52
|
-
export type BlackList = string[];
|
|
53
|
-
export type AssociationKeysToBeUpdate = string[];
|
|
54
|
-
export type Values = any;
|
|
55
|
-
export type CountOptions = Omit<SequelizeCountOptions, 'distinct' | 'where' | 'include'> & Transactionable & {
|
|
56
|
-
filter?: Filter;
|
|
57
|
-
context?: any;
|
|
58
|
-
} & FilterByTk;
|
|
59
|
-
export interface FilterByTk {
|
|
60
|
-
filterByTk?: TargetKey;
|
|
61
|
-
targetCollection?: string;
|
|
62
|
-
}
|
|
63
|
-
export type FindOptions = SequelizeFindOptions & CommonFindOptions & FilterByTk;
|
|
64
|
-
export interface CommonFindOptions extends Transactionable {
|
|
65
|
-
filter?: Filter;
|
|
66
|
-
fields?: Fields;
|
|
67
|
-
appends?: Appends;
|
|
68
|
-
except?: Except;
|
|
69
|
-
sort?: Sort;
|
|
70
|
-
context?: any;
|
|
71
|
-
tree?: boolean;
|
|
72
|
-
}
|
|
73
|
-
export type FindOneOptions = Omit<FindOptions, 'limit'> & {
|
|
74
|
-
targetCollection?: string;
|
|
75
|
-
};
|
|
76
|
-
export interface DestroyOptions extends SequelizeDestroyOptions {
|
|
77
|
-
filter?: Filter;
|
|
78
|
-
filterByTk?: TargetKey | TargetKey[];
|
|
79
|
-
truncate?: boolean;
|
|
80
|
-
context?: any;
|
|
81
|
-
}
|
|
82
|
-
type FindAndCountOptions = Omit<SequelizeAndCountOptions, 'where' | 'include' | 'order'> & CommonFindOptions;
|
|
83
|
-
export interface CreateOptions extends SequelizeCreateOptions {
|
|
84
|
-
values?: Values | Values[];
|
|
85
|
-
whitelist?: WhiteList;
|
|
86
|
-
blacklist?: BlackList;
|
|
87
|
-
updateAssociationValues?: AssociationKeysToBeUpdate;
|
|
88
|
-
context?: any;
|
|
89
|
-
}
|
|
90
|
-
export interface UpdateOptions extends Omit<SequelizeUpdateOptions, 'where'> {
|
|
91
|
-
values: Values;
|
|
92
|
-
filter?: Filter;
|
|
93
|
-
filterByTk?: TargetKey;
|
|
94
|
-
whitelist?: WhiteList;
|
|
95
|
-
blacklist?: BlackList;
|
|
96
|
-
updateAssociationValues?: AssociationKeysToBeUpdate;
|
|
97
|
-
targetCollection?: string;
|
|
98
|
-
context?: any;
|
|
99
|
-
}
|
|
100
|
-
interface UpdateManyOptions extends Omit<UpdateOptions, 'values'> {
|
|
101
|
-
records: Values[];
|
|
102
|
-
}
|
|
103
|
-
declare class RelationRepositoryBuilder<R extends RelationRepository> {
|
|
104
|
-
collection: Collection;
|
|
105
|
-
associationName: string;
|
|
106
|
-
association: Association | {
|
|
107
|
-
associationType: string;
|
|
108
|
-
};
|
|
109
|
-
builderMap: {
|
|
110
|
-
HasOne: typeof HasOneRepository;
|
|
111
|
-
BelongsTo: typeof BelongsToRepository;
|
|
112
|
-
BelongsToMany: typeof BelongsToManyRepository;
|
|
113
|
-
HasMany: typeof HasManyRepository;
|
|
114
|
-
ArrayField: typeof ArrayFieldRepository;
|
|
115
|
-
};
|
|
116
|
-
constructor(collection: Collection, associationName: string);
|
|
117
|
-
of(id: string | number): R;
|
|
118
|
-
protected builder(): {
|
|
119
|
-
HasOne: typeof HasOneRepository;
|
|
120
|
-
BelongsTo: typeof BelongsToRepository;
|
|
121
|
-
BelongsToMany: typeof BelongsToManyRepository;
|
|
122
|
-
HasMany: typeof HasManyRepository;
|
|
123
|
-
ArrayField: typeof ArrayFieldRepository;
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
export interface AggregateOptions {
|
|
127
|
-
method: 'avg' | 'count' | 'min' | 'max' | 'sum';
|
|
128
|
-
field?: string;
|
|
129
|
-
filter?: Filter;
|
|
130
|
-
distinct?: boolean;
|
|
131
|
-
}
|
|
132
|
-
interface FirstOrCreateOptions extends Transactionable {
|
|
133
|
-
filterKeys: string[];
|
|
134
|
-
values?: Values;
|
|
135
|
-
hooks?: boolean;
|
|
136
|
-
}
|
|
137
|
-
export declare class Repository<TModelAttributes extends {} = any, TCreationAttributes extends {} = TModelAttributes> {
|
|
138
|
-
database: Database;
|
|
139
|
-
collection: Collection;
|
|
140
|
-
model: ModelStatic<Model>;
|
|
141
|
-
constructor(collection: Collection);
|
|
142
|
-
static valuesToFilter(values: Values, filterKeys: Array<string>): {
|
|
143
|
-
$and: any[];
|
|
144
|
-
};
|
|
145
|
-
/**
|
|
146
|
-
* return count by filter
|
|
147
|
-
*/
|
|
148
|
-
count(countOptions?: CountOptions): Promise<number>;
|
|
149
|
-
aggregate(options: AggregateOptions & {
|
|
150
|
-
optionsTransformer?: (options: any) => any;
|
|
151
|
-
}): Promise<any>;
|
|
152
|
-
chunk(options: FindOptions & {
|
|
153
|
-
chunkSize: number;
|
|
154
|
-
callback: (rows: Model[], options: FindOptions) => Promise<void>;
|
|
155
|
-
}): Promise<void>;
|
|
156
|
-
/**
|
|
157
|
-
* find
|
|
158
|
-
* @param options
|
|
159
|
-
*/
|
|
160
|
-
find(options?: FindOptions): any;
|
|
161
|
-
/**
|
|
162
|
-
* find and count
|
|
163
|
-
* @param options
|
|
164
|
-
*/
|
|
165
|
-
findAndCount(options?: FindAndCountOptions): Promise<[Model[], number]>;
|
|
166
|
-
/**
|
|
167
|
-
* Find By Id
|
|
168
|
-
*
|
|
169
|
-
*/
|
|
170
|
-
findById(id: string | number): Promise<Model<any, any>>;
|
|
171
|
-
/**
|
|
172
|
-
* Find one record from database
|
|
173
|
-
*
|
|
174
|
-
* @param options
|
|
175
|
-
*/
|
|
176
|
-
findOne(options?: FindOneOptions): Promise<any>;
|
|
177
|
-
/**
|
|
178
|
-
* Get the first record matching the attributes or create it.
|
|
179
|
-
*/
|
|
180
|
-
firstOrCreate(options: FirstOrCreateOptions): Promise<any>;
|
|
181
|
-
updateOrCreate(options: FirstOrCreateOptions): Promise<any>;
|
|
182
|
-
/**
|
|
183
|
-
* Save instance to database
|
|
184
|
-
*
|
|
185
|
-
* @param values
|
|
186
|
-
* @param options
|
|
187
|
-
*/
|
|
188
|
-
create(options: CreateOptions): Promise<any>;
|
|
189
|
-
/**
|
|
190
|
-
* Save Many instances to database
|
|
191
|
-
*
|
|
192
|
-
* @param records
|
|
193
|
-
* @param options
|
|
194
|
-
*/
|
|
195
|
-
createMany(options: CreateManyOptions): Promise<any[]>;
|
|
196
|
-
/**
|
|
197
|
-
* Update model value
|
|
198
|
-
*
|
|
199
|
-
* @param values
|
|
200
|
-
* @param options
|
|
201
|
-
*/
|
|
202
|
-
update(options: UpdateOptions & {
|
|
203
|
-
forceUpdate?: boolean;
|
|
204
|
-
}): Promise<any>;
|
|
205
|
-
updateMany(options: UpdateManyOptions): Promise<any[]>;
|
|
206
|
-
destroy(options?: TargetKey | TargetKey[] | DestroyOptions): any;
|
|
207
|
-
/**
|
|
208
|
-
* @param association target association
|
|
209
|
-
*/
|
|
210
|
-
relation<R extends RelationRepository>(association: string): RelationRepositoryBuilder<R>;
|
|
211
|
-
buildQueryOptions(options: any): any;
|
|
212
|
-
protected parseFilter(filter: Filter, options?: any): any;
|
|
213
|
-
protected getTransaction(options: any, autoGen?: boolean): Promise<any>;
|
|
214
|
-
}
|