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