@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,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 must_have_filter_decorator_exports = {};
|
|
20
|
+
__export(must_have_filter_decorator_exports, {
|
|
21
|
+
default: () => must_have_filter_decorator_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(must_have_filter_decorator_exports);
|
|
24
|
+
const mustHaveFilter = /* @__PURE__ */ __name(() => (originalMethod, context) => {
|
|
25
|
+
const oldValue = originalMethod;
|
|
26
|
+
const newMethod = /* @__PURE__ */ __name(function(...args) {
|
|
27
|
+
const options = args[0];
|
|
28
|
+
if (Array.isArray(options.values)) {
|
|
29
|
+
return oldValue.apply(this, args);
|
|
30
|
+
}
|
|
31
|
+
if (!(options == null ? void 0 : options.filter) && !(options == null ? void 0 : options.filterByTk) && !(options == null ? void 0 : options.forceUpdate)) {
|
|
32
|
+
throw new Error(`must provide filter or filterByTk for ${String(context.name)} call, or set forceUpdate to true`);
|
|
33
|
+
}
|
|
34
|
+
return oldValue.apply(this, args);
|
|
35
|
+
}, "newMethod");
|
|
36
|
+
return newMethod;
|
|
37
|
+
}, "mustHaveFilter");
|
|
38
|
+
var must_have_filter_decorator_default = mustHaveFilter;
|
|
@@ -0,0 +1,47 @@
|
|
|
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 target_collection_decorator_exports = {};
|
|
30
|
+
__export(target_collection_decorator_exports, {
|
|
31
|
+
default: () => target_collection_decorator_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(target_collection_decorator_exports);
|
|
34
|
+
var import_lodash = __toESM(require("lodash"));
|
|
35
|
+
const injectTargetCollection = /* @__PURE__ */ __name((originalMethod) => {
|
|
36
|
+
const oldValue = originalMethod;
|
|
37
|
+
const newMethod = /* @__PURE__ */ __name(function(...args) {
|
|
38
|
+
const options = args[0];
|
|
39
|
+
const values = options.values;
|
|
40
|
+
if (import_lodash.default.isPlainObject(values) && values.__collection) {
|
|
41
|
+
options.targetCollection = values.__collection;
|
|
42
|
+
}
|
|
43
|
+
return oldValue.apply(this, args);
|
|
44
|
+
}, "newMethod");
|
|
45
|
+
return newMethod;
|
|
46
|
+
}, "injectTargetCollection");
|
|
47
|
+
var target_collection_decorator_default = injectTargetCollection;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function transactionWrapperBuilder(transactionGenerator: any): (transactionInjector?: any) => (originalMethod: any, context: ClassMethodDecoratorContext) => (...args: unknown[]) => Promise<any>;
|
|
@@ -0,0 +1,88 @@
|
|
|
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 transaction_decorator_exports = {};
|
|
30
|
+
__export(transaction_decorator_exports, {
|
|
31
|
+
transactionWrapperBuilder: () => transactionWrapperBuilder
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(transaction_decorator_exports);
|
|
34
|
+
var import_lodash = __toESM(require("lodash"));
|
|
35
|
+
function transactionWrapperBuilder(transactionGenerator) {
|
|
36
|
+
return /* @__PURE__ */ __name(function transaction(transactionInjector) {
|
|
37
|
+
return (originalMethod, context) => {
|
|
38
|
+
const name = String(context.name);
|
|
39
|
+
const oldValue = originalMethod;
|
|
40
|
+
const newMethod = /* @__PURE__ */ __name(async function(...args) {
|
|
41
|
+
let transaction2;
|
|
42
|
+
let newTransaction = false;
|
|
43
|
+
if (args.length > 0 && typeof args[0] === "object") {
|
|
44
|
+
transaction2 = args[0]["transaction"];
|
|
45
|
+
}
|
|
46
|
+
if (!transaction2) {
|
|
47
|
+
transaction2 = await transactionGenerator.apply(this);
|
|
48
|
+
newTransaction = true;
|
|
49
|
+
}
|
|
50
|
+
if (newTransaction) {
|
|
51
|
+
try {
|
|
52
|
+
let callArguments;
|
|
53
|
+
if (import_lodash.default.isPlainObject(args[0])) {
|
|
54
|
+
callArguments = {
|
|
55
|
+
// @ts-ignore lodash type error
|
|
56
|
+
...args[0],
|
|
57
|
+
transaction: transaction2
|
|
58
|
+
};
|
|
59
|
+
} else if (transactionInjector) {
|
|
60
|
+
callArguments = transactionInjector(args, transaction2);
|
|
61
|
+
} else if (import_lodash.default.isNull(args[0]) || import_lodash.default.isUndefined(args[0])) {
|
|
62
|
+
callArguments = {
|
|
63
|
+
transaction: transaction2
|
|
64
|
+
};
|
|
65
|
+
} else {
|
|
66
|
+
throw new Error(`please provide transactionInjector for ${name} call`);
|
|
67
|
+
}
|
|
68
|
+
const results = await oldValue.call(this, callArguments);
|
|
69
|
+
await transaction2.commit();
|
|
70
|
+
return results;
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.error(err);
|
|
73
|
+
await transaction2.rollback();
|
|
74
|
+
throw err;
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
return oldValue.apply(this, args);
|
|
78
|
+
}
|
|
79
|
+
}, "newMethod");
|
|
80
|
+
return newMethod;
|
|
81
|
+
};
|
|
82
|
+
}, "transaction");
|
|
83
|
+
}
|
|
84
|
+
__name(transactionWrapperBuilder, "transactionWrapperBuilder");
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
transactionWrapperBuilder
|
|
88
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Association, Includeable, Model, ModelStatic, Transaction } from 'sequelize';
|
|
2
|
+
import Database from '../database';
|
|
3
|
+
interface EagerLoadingNode {
|
|
4
|
+
model: ModelStatic<any>;
|
|
5
|
+
association: Association;
|
|
6
|
+
attributes: Array<string>;
|
|
7
|
+
rawAttributes: Array<string>;
|
|
8
|
+
children: Array<EagerLoadingNode>;
|
|
9
|
+
parent?: EagerLoadingNode;
|
|
10
|
+
instances?: Array<Model>;
|
|
11
|
+
order?: any;
|
|
12
|
+
where?: any;
|
|
13
|
+
inspectInheritAttribute?: boolean;
|
|
14
|
+
includeOptions?: any;
|
|
15
|
+
}
|
|
16
|
+
export declare class EagerLoadingTree {
|
|
17
|
+
root: EagerLoadingNode;
|
|
18
|
+
db: Database;
|
|
19
|
+
private rootQueryOptions;
|
|
20
|
+
constructor(root: EagerLoadingNode);
|
|
21
|
+
static buildFromSequelizeOptions(options: {
|
|
22
|
+
model: ModelStatic<any>;
|
|
23
|
+
rootAttributes: Array<string>;
|
|
24
|
+
rootOrder?: any;
|
|
25
|
+
rootQueryOptions?: any;
|
|
26
|
+
includeOption: Includeable | Includeable[];
|
|
27
|
+
db: Database;
|
|
28
|
+
}): EagerLoadingTree;
|
|
29
|
+
load(transaction?: Transaction): Promise<{}>;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,439 @@
|
|
|
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 eager_loading_tree_exports = {};
|
|
30
|
+
__export(eager_loading_tree_exports, {
|
|
31
|
+
EagerLoadingTree: () => EagerLoadingTree
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(eager_loading_tree_exports);
|
|
34
|
+
var import_lodash = __toESM(require("lodash"));
|
|
35
|
+
var import_sequelize = require("sequelize");
|
|
36
|
+
var import_append_child_collection_name_after_repository_find = require("../listeners/append-child-collection-name-after-repository-find");
|
|
37
|
+
var import_options_parser = require("../options-parser");
|
|
38
|
+
var import_adjacency_list_repository = require("../repositories/tree-repository/adjacency-list-repository");
|
|
39
|
+
const pushAttribute = /* @__PURE__ */ __name((node, attribute) => {
|
|
40
|
+
if (import_lodash.default.isArray(node.attributes) && !node.attributes.includes(attribute)) {
|
|
41
|
+
node.attributes.push(attribute);
|
|
42
|
+
}
|
|
43
|
+
}, "pushAttribute");
|
|
44
|
+
const EagerLoadingNodeProto = {
|
|
45
|
+
afterBuild(db) {
|
|
46
|
+
const collection = db.modelCollection.get(this.model);
|
|
47
|
+
if (collection && collection.isParent()) {
|
|
48
|
+
if (!this.attributes) {
|
|
49
|
+
this.attributes = {
|
|
50
|
+
include: []
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
import_options_parser.OptionsParser.appendInheritInspectAttribute(
|
|
54
|
+
import_lodash.default.isArray(this.attributes) ? this.attributes : this.attributes.include,
|
|
55
|
+
collection
|
|
56
|
+
);
|
|
57
|
+
this.inspectInheritAttribute = true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const _EagerLoadingTree = class _EagerLoadingTree {
|
|
62
|
+
root;
|
|
63
|
+
db;
|
|
64
|
+
rootQueryOptions = {};
|
|
65
|
+
constructor(root) {
|
|
66
|
+
this.root = root;
|
|
67
|
+
}
|
|
68
|
+
static buildFromSequelizeOptions(options) {
|
|
69
|
+
const { model, rootAttributes, includeOption, db, rootQueryOptions } = options;
|
|
70
|
+
const buildNode = /* @__PURE__ */ __name((node) => {
|
|
71
|
+
Object.setPrototypeOf(node, EagerLoadingNodeProto);
|
|
72
|
+
node.afterBuild(db);
|
|
73
|
+
return node;
|
|
74
|
+
}, "buildNode");
|
|
75
|
+
const root = buildNode({
|
|
76
|
+
model,
|
|
77
|
+
association: null,
|
|
78
|
+
rawAttributes: import_lodash.default.cloneDeep(rootAttributes),
|
|
79
|
+
attributes: import_lodash.default.cloneDeep(rootAttributes),
|
|
80
|
+
order: options.rootOrder,
|
|
81
|
+
children: []
|
|
82
|
+
});
|
|
83
|
+
const traverseIncludeOption = /* @__PURE__ */ __name((includeOption2, eagerLoadingTreeParent) => {
|
|
84
|
+
const includeOptions = import_lodash.default.castArray(includeOption2);
|
|
85
|
+
if (includeOption2.length > 0) {
|
|
86
|
+
const modelPrimaryKey = eagerLoadingTreeParent.model.primaryKeyAttribute;
|
|
87
|
+
pushAttribute(eagerLoadingTreeParent, modelPrimaryKey);
|
|
88
|
+
}
|
|
89
|
+
for (const include of includeOptions) {
|
|
90
|
+
if (include.fromFilter) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const association = import_lodash.default.isString(include.association) ? eagerLoadingTreeParent.model.associations[include.association] : include.association;
|
|
94
|
+
if (!association) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
`Association "${include.association}" not found in model "${eagerLoadingTreeParent.model.name}"`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
const associationType = association.associationType;
|
|
100
|
+
const child = buildNode({
|
|
101
|
+
model: association.target,
|
|
102
|
+
association,
|
|
103
|
+
rawAttributes: import_lodash.default.cloneDeep(include.attributes),
|
|
104
|
+
attributes: import_lodash.default.cloneDeep(include.attributes),
|
|
105
|
+
parent: eagerLoadingTreeParent,
|
|
106
|
+
where: include.where,
|
|
107
|
+
children: [],
|
|
108
|
+
includeOption: include.options || {}
|
|
109
|
+
});
|
|
110
|
+
if (associationType == "HasOne" || associationType == "HasMany") {
|
|
111
|
+
const { sourceKey, foreignKey } = association;
|
|
112
|
+
pushAttribute(eagerLoadingTreeParent, sourceKey);
|
|
113
|
+
pushAttribute(child, foreignKey);
|
|
114
|
+
}
|
|
115
|
+
if (associationType == "BelongsTo") {
|
|
116
|
+
const { targetKey, foreignKey } = association;
|
|
117
|
+
pushAttribute(eagerLoadingTreeParent, foreignKey);
|
|
118
|
+
pushAttribute(child, targetKey);
|
|
119
|
+
}
|
|
120
|
+
if (associationType == "BelongsToMany") {
|
|
121
|
+
const { sourceKey } = association;
|
|
122
|
+
pushAttribute(eagerLoadingTreeParent, sourceKey);
|
|
123
|
+
}
|
|
124
|
+
eagerLoadingTreeParent.children.push(child);
|
|
125
|
+
if (include.include) {
|
|
126
|
+
traverseIncludeOption(include.include, child);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}, "traverseIncludeOption");
|
|
130
|
+
traverseIncludeOption(includeOption, root);
|
|
131
|
+
const tree = new _EagerLoadingTree(root);
|
|
132
|
+
tree.db = db;
|
|
133
|
+
tree.rootQueryOptions = rootQueryOptions;
|
|
134
|
+
return tree;
|
|
135
|
+
}
|
|
136
|
+
async load(transaction) {
|
|
137
|
+
const result = {};
|
|
138
|
+
const orderOption = /* @__PURE__ */ __name((association) => {
|
|
139
|
+
const targetModel = association.target;
|
|
140
|
+
const order = [];
|
|
141
|
+
if (targetModel.primaryKeyAttribute && targetModel.rawAttributes[targetModel.primaryKeyAttribute].autoIncrement) {
|
|
142
|
+
order.push([targetModel.primaryKeyAttribute, "ASC"]);
|
|
143
|
+
}
|
|
144
|
+
return order;
|
|
145
|
+
}, "orderOption");
|
|
146
|
+
const loadRecursive = /* @__PURE__ */ __name(async (node, ids = []) => {
|
|
147
|
+
var _a;
|
|
148
|
+
let instances = [];
|
|
149
|
+
if (!node.parent) {
|
|
150
|
+
const rootInclude = ((_a = this.rootQueryOptions) == null ? void 0 : _a.include) || node.includeOption;
|
|
151
|
+
const includeForFilter = rootInclude.filter((include) => {
|
|
152
|
+
var _a2, _b;
|
|
153
|
+
return Object.keys(include.where || {}).length > 0 || ((_b = JSON.stringify((_a2 = this.rootQueryOptions) == null ? void 0 : _a2.filter)) == null ? void 0 : _b.includes(include.association));
|
|
154
|
+
});
|
|
155
|
+
const isBelongsToAssociationOnly = /* @__PURE__ */ __name((includes, model) => {
|
|
156
|
+
for (const include of includes) {
|
|
157
|
+
const association = model.associations[include.association];
|
|
158
|
+
if (!association) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
if (association.associationType != "BelongsTo") {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
if (!isBelongsToAssociationOnly(include.include || [], association.target)) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return true;
|
|
169
|
+
}, "isBelongsToAssociationOnly");
|
|
170
|
+
const belongsToAssociationsOnly = isBelongsToAssociationOnly(includeForFilter, node.model);
|
|
171
|
+
if (belongsToAssociationsOnly) {
|
|
172
|
+
instances = await node.model.findAll({
|
|
173
|
+
...this.rootQueryOptions,
|
|
174
|
+
attributes: node.attributes,
|
|
175
|
+
distinct: true,
|
|
176
|
+
include: includeForFilter,
|
|
177
|
+
transaction
|
|
178
|
+
});
|
|
179
|
+
} else {
|
|
180
|
+
const primaryKeyField = node.model.primaryKeyField || node.model.primaryKeyAttribute;
|
|
181
|
+
if (!primaryKeyField) {
|
|
182
|
+
throw new Error(`Model ${node.model.name} does not have primary key`);
|
|
183
|
+
}
|
|
184
|
+
const ids2 = (await node.model.findAll({
|
|
185
|
+
...this.rootQueryOptions,
|
|
186
|
+
includeIgnoreAttributes: false,
|
|
187
|
+
attributes: [primaryKeyField],
|
|
188
|
+
group: `${node.model.name}.${primaryKeyField}`,
|
|
189
|
+
transaction,
|
|
190
|
+
include: includeForFilter
|
|
191
|
+
})).map((row) => {
|
|
192
|
+
return { row, pk: row[primaryKeyField] };
|
|
193
|
+
});
|
|
194
|
+
const findOptions = {
|
|
195
|
+
where: { [primaryKeyField]: ids2.map((i) => i.pk) },
|
|
196
|
+
attributes: node.attributes
|
|
197
|
+
};
|
|
198
|
+
if (node.order) {
|
|
199
|
+
findOptions["order"] = node.order;
|
|
200
|
+
}
|
|
201
|
+
instances = await node.model.findAll({
|
|
202
|
+
...findOptions,
|
|
203
|
+
transaction
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
const associations = node.model.associations;
|
|
207
|
+
for (const association of Object.keys(associations)) {
|
|
208
|
+
for (const instance of instances) {
|
|
209
|
+
delete instance[association];
|
|
210
|
+
delete instance.dataValues[association];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
} else if (ids.length > 0) {
|
|
214
|
+
const association = node.association;
|
|
215
|
+
const associationType = association.associationType;
|
|
216
|
+
let params = {};
|
|
217
|
+
const otherFindOptions = import_lodash.default.pick(node.includeOption, ["sort"]) || {};
|
|
218
|
+
const collection = this.db.modelCollection.get(node.model);
|
|
219
|
+
if (collection && !import_lodash.default.isEmpty(otherFindOptions)) {
|
|
220
|
+
const parser = new import_options_parser.OptionsParser(otherFindOptions, {
|
|
221
|
+
collection
|
|
222
|
+
});
|
|
223
|
+
params = parser.toSequelizeParams();
|
|
224
|
+
}
|
|
225
|
+
if (associationType == "HasOne" || associationType == "HasMany") {
|
|
226
|
+
const foreignKey = association.foreignKey;
|
|
227
|
+
const foreignKeyValues = node.parent.instances.map((instance) => instance.get(association.sourceKey));
|
|
228
|
+
let where = { [foreignKey]: foreignKeyValues };
|
|
229
|
+
if (node.where) {
|
|
230
|
+
where = {
|
|
231
|
+
[import_sequelize.Op.and]: [where, node.where]
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
const findOptions = {
|
|
235
|
+
where,
|
|
236
|
+
attributes: node.attributes,
|
|
237
|
+
order: params.order || orderOption(association),
|
|
238
|
+
transaction
|
|
239
|
+
};
|
|
240
|
+
instances = await node.model.findAll(findOptions);
|
|
241
|
+
}
|
|
242
|
+
if (associationType == "BelongsTo") {
|
|
243
|
+
const foreignKey = association.foreignKey;
|
|
244
|
+
const parentInstancesForeignKeyValues = node.parent.instances.map((instance) => instance.get(foreignKey));
|
|
245
|
+
const collection2 = this.db.modelCollection.get(node.model);
|
|
246
|
+
instances = await node.model.findAll({
|
|
247
|
+
transaction,
|
|
248
|
+
where: {
|
|
249
|
+
[association.targetKey]: parentInstancesForeignKeyValues
|
|
250
|
+
},
|
|
251
|
+
attributes: node.attributes
|
|
252
|
+
});
|
|
253
|
+
if (node.includeOption.recursively && instances.length > 0) {
|
|
254
|
+
const targetKey = association.targetKey;
|
|
255
|
+
const sql = import_adjacency_list_repository.AdjacencyListRepository.queryParentSQL({
|
|
256
|
+
db: this.db,
|
|
257
|
+
collection: collection2,
|
|
258
|
+
foreignKey,
|
|
259
|
+
targetKey,
|
|
260
|
+
nodeIds: instances.map((instance) => instance.get(targetKey))
|
|
261
|
+
});
|
|
262
|
+
const results = await this.db.sequelize.query(sql, {
|
|
263
|
+
type: "SELECT",
|
|
264
|
+
transaction
|
|
265
|
+
});
|
|
266
|
+
const parentInstances = await node.model.findAll({
|
|
267
|
+
transaction,
|
|
268
|
+
where: {
|
|
269
|
+
[association.targetKey]: results.map((result2) => result2[targetKey])
|
|
270
|
+
},
|
|
271
|
+
attributes: node.attributes
|
|
272
|
+
});
|
|
273
|
+
const setInstanceParent = /* @__PURE__ */ __name((instance) => {
|
|
274
|
+
const parentInstance = parentInstances.find(
|
|
275
|
+
(parentInstance2) => parentInstance2.get(targetKey) == instance.get(foreignKey)
|
|
276
|
+
);
|
|
277
|
+
if (!parentInstance) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
setInstanceParent(parentInstance);
|
|
281
|
+
instance[association.as] = instance.dataValues[association.as] = parentInstance;
|
|
282
|
+
}, "setInstanceParent");
|
|
283
|
+
for (const instance of instances) {
|
|
284
|
+
setInstanceParent(instance);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (associationType == "BelongsToMany") {
|
|
289
|
+
const foreignKeyValues = node.parent.instances.map((instance) => instance.get(association.sourceKey));
|
|
290
|
+
const hasOneOptions = {
|
|
291
|
+
as: "_pivot_",
|
|
292
|
+
foreignKey: association.otherKey,
|
|
293
|
+
sourceKey: association.targetKey
|
|
294
|
+
};
|
|
295
|
+
if (association.through.scope) {
|
|
296
|
+
hasOneOptions.scope = association.through.scope;
|
|
297
|
+
}
|
|
298
|
+
const pivotAssoc = new import_sequelize.HasOne(association.target, association.through.model, hasOneOptions);
|
|
299
|
+
instances = await node.model.findAll({
|
|
300
|
+
transaction,
|
|
301
|
+
attributes: node.attributes,
|
|
302
|
+
include: [
|
|
303
|
+
{
|
|
304
|
+
association: pivotAssoc,
|
|
305
|
+
where: {
|
|
306
|
+
[association.foreignKey]: foreignKeyValues
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
],
|
|
310
|
+
order: params.order || orderOption(association)
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
node.instances = instances;
|
|
315
|
+
for (const child of node.children) {
|
|
316
|
+
const modelPrimaryKey = node.model.primaryKeyField || node.model.primaryKeyAttribute;
|
|
317
|
+
const nodeIds = instances.map((instance) => instance.get(modelPrimaryKey));
|
|
318
|
+
await loadRecursive(child, nodeIds);
|
|
319
|
+
}
|
|
320
|
+
if (!node.parent) {
|
|
321
|
+
return;
|
|
322
|
+
} else {
|
|
323
|
+
const association = node.association;
|
|
324
|
+
const associationType = association.associationType;
|
|
325
|
+
const setParentAccessor = /* @__PURE__ */ __name((parentInstance) => {
|
|
326
|
+
const key = association.as;
|
|
327
|
+
const children = parentInstance.getDataValue(association.as);
|
|
328
|
+
if (association.isSingleAssociation) {
|
|
329
|
+
const isEmpty = !children;
|
|
330
|
+
parentInstance[key] = parentInstance.dataValues[key] = isEmpty ? null : children;
|
|
331
|
+
} else {
|
|
332
|
+
const isEmpty = !children || children.length == 0;
|
|
333
|
+
parentInstance[key] = parentInstance.dataValues[key] = isEmpty ? [] : children;
|
|
334
|
+
}
|
|
335
|
+
}, "setParentAccessor");
|
|
336
|
+
if (associationType == "HasMany" || associationType == "HasOne") {
|
|
337
|
+
const foreignKey = association.foreignKey;
|
|
338
|
+
const sourceKey = association.sourceKey;
|
|
339
|
+
for (const instance of node.instances) {
|
|
340
|
+
const parentInstance = node.parent.instances.find(
|
|
341
|
+
(parentInstance2) => parentInstance2.get(sourceKey) == instance.get(foreignKey)
|
|
342
|
+
);
|
|
343
|
+
if (parentInstance) {
|
|
344
|
+
if (associationType == "HasMany") {
|
|
345
|
+
const children = parentInstance.getDataValue(association.as);
|
|
346
|
+
if (!children) {
|
|
347
|
+
parentInstance.setDataValue(association.as, [instance]);
|
|
348
|
+
} else {
|
|
349
|
+
children.push(instance);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
if (associationType == "HasOne") {
|
|
353
|
+
const key = association.options.realAs || association.as;
|
|
354
|
+
parentInstance[key] = parentInstance.dataValues[key] = instance;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
if (associationType == "BelongsTo") {
|
|
360
|
+
const foreignKey = association.foreignKey;
|
|
361
|
+
const targetKey = association.targetKey;
|
|
362
|
+
for (const instance of node.instances) {
|
|
363
|
+
const parentInstances = node.parent.instances.filter(
|
|
364
|
+
(parentInstance) => parentInstance.get(foreignKey) == instance.get(targetKey)
|
|
365
|
+
);
|
|
366
|
+
for (const parentInstance of parentInstances) {
|
|
367
|
+
parentInstance.setDataValue(association.as, instance);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
if (associationType == "BelongsToMany") {
|
|
372
|
+
const sourceKey = association.sourceKey;
|
|
373
|
+
const foreignKey = association.foreignKey;
|
|
374
|
+
const as = association.oneFromTarget.as;
|
|
375
|
+
for (const instance of node.instances) {
|
|
376
|
+
instance[as] = instance.dataValues[as] = instance["_pivot_"];
|
|
377
|
+
delete instance.dataValues["_pivot_"];
|
|
378
|
+
delete instance["_pivot_"];
|
|
379
|
+
const parentInstance = node.parent.instances.find(
|
|
380
|
+
(parentInstance2) => parentInstance2.get(sourceKey) == instance.dataValues[as].get(foreignKey)
|
|
381
|
+
);
|
|
382
|
+
if (parentInstance) {
|
|
383
|
+
const children = parentInstance.getDataValue(association.as);
|
|
384
|
+
if (!children) {
|
|
385
|
+
parentInstance.setDataValue(association.as, [instance]);
|
|
386
|
+
} else {
|
|
387
|
+
children.push(instance);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
for (const parent of node.parent.instances) {
|
|
393
|
+
setParentAccessor(parent);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}, "loadRecursive");
|
|
397
|
+
await loadRecursive(this.root);
|
|
398
|
+
const appendChildCollectionName = (0, import_append_child_collection_name_after_repository_find.appendChildCollectionNameAfterRepositoryFind)(this.db);
|
|
399
|
+
const setInstanceAttributes = /* @__PURE__ */ __name((node) => {
|
|
400
|
+
var _a;
|
|
401
|
+
if (node.inspectInheritAttribute) {
|
|
402
|
+
appendChildCollectionName({
|
|
403
|
+
findOptions: {},
|
|
404
|
+
data: node.instances,
|
|
405
|
+
dataCollection: this.db.modelCollection.get(node.model)
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
if (((_a = node.association) == null ? void 0 : _a.as) == "_pivot_") {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const nodeRawAttributes = node.rawAttributes || [];
|
|
412
|
+
if (!import_lodash.default.isArray(nodeRawAttributes)) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
const nodeChildrenAs = node.children.map((child) => child.association.as);
|
|
416
|
+
const includeAttributes = [...nodeRawAttributes, ...nodeChildrenAs];
|
|
417
|
+
if (node.inspectInheritAttribute) {
|
|
418
|
+
includeAttributes.push("__schemaName", "__tableName", "__collection");
|
|
419
|
+
}
|
|
420
|
+
for (const instance of node.instances) {
|
|
421
|
+
instance.dataValues = import_lodash.default.pick(instance.dataValues, includeAttributes);
|
|
422
|
+
}
|
|
423
|
+
}, "setInstanceAttributes");
|
|
424
|
+
const traverse = /* @__PURE__ */ __name((node) => {
|
|
425
|
+
setInstanceAttributes(node);
|
|
426
|
+
for (const child of node.children) {
|
|
427
|
+
traverse(child);
|
|
428
|
+
}
|
|
429
|
+
}, "traverse");
|
|
430
|
+
traverse(this.root);
|
|
431
|
+
return result;
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
__name(_EagerLoadingTree, "EagerLoadingTree");
|
|
435
|
+
let EagerLoadingTree = _EagerLoadingTree;
|
|
436
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
437
|
+
0 && (module.exports = {
|
|
438
|
+
EagerLoadingTree
|
|
439
|
+
});
|