@nocobase/database 2.0.22 → 2.0.23

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.
@@ -0,0 +1,11 @@
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
+ export declare class AssociationNotFoundError extends Error {
10
+ constructor(message: string);
11
+ }
@@ -0,0 +1,44 @@
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 association_not_found_error_exports = {};
29
+ __export(association_not_found_error_exports, {
30
+ AssociationNotFoundError: () => AssociationNotFoundError
31
+ });
32
+ module.exports = __toCommonJS(association_not_found_error_exports);
33
+ const _AssociationNotFoundError = class _AssociationNotFoundError extends Error {
34
+ constructor(message) {
35
+ super(message);
36
+ this.name = "AssociationNotFoundError";
37
+ }
38
+ };
39
+ __name(_AssociationNotFoundError, "AssociationNotFoundError");
40
+ let AssociationNotFoundError = _AssociationNotFoundError;
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ AssociationNotFoundError
44
+ });
@@ -22,6 +22,7 @@ export declare class OptionsParser {
22
22
  model: ModelStatic<any>;
23
23
  filterParser: FilterParser;
24
24
  context: OptionsParserContext;
25
+ associationNotFoundWarnings: string[];
25
26
  constructor(options: FindOptions, context: OptionsParserContext);
26
27
  static appendInheritInspectAttribute(include: any, collection: any): any;
27
28
  isAssociation(key: string): boolean;
@@ -44,6 +44,7 @@ var import_lodash = __toESM(require("lodash"));
44
44
  var import_sequelize = require("sequelize");
45
45
  var import_filter_parser = __toESM(require("./filter-parser"));
46
46
  var import_qs = __toESM(require("qs"));
47
+ var import_association_not_found_error = require("./errors/association-not-found-error");
47
48
  const debug = require("debug")("noco-database");
48
49
  const _OptionsParser = class _OptionsParser {
49
50
  options;
@@ -52,6 +53,7 @@ const _OptionsParser = class _OptionsParser {
52
53
  model;
53
54
  filterParser;
54
55
  context;
56
+ associationNotFoundWarnings = [];
55
57
  constructor(options, context) {
56
58
  const { collection } = context;
57
59
  this.collection = collection;
@@ -301,7 +303,7 @@ const _OptionsParser = class _OptionsParser {
301
303
  }
302
304
  const sortedAppends = import_lodash.default.sortBy(appendList, (append) => append.split(".").length);
303
305
  const setInclude = /* @__PURE__ */ __name((model, queryParams, append, parentAs) => {
304
- var _a;
306
+ var _a, _b;
305
307
  const appendWithOptions = this.parseAppendWithOptions(append);
306
308
  append = appendWithOptions.name;
307
309
  const appendFields = append.split(".");
@@ -314,7 +316,7 @@ const _OptionsParser = class _OptionsParser {
314
316
  if (appendFields.length == 2) {
315
317
  const association = associations[appendFields[0]];
316
318
  if (!association) {
317
- throw new Error(`association ${appendFields[0]} in ${model.name} not found`);
319
+ throw new import_association_not_found_error.AssociationNotFoundError(`association ${appendFields[0]} in ${model.name} not found`);
318
320
  }
319
321
  const associationModel = associations[appendFields[0]].target;
320
322
  if (associationModel.rawAttributes[appendFields[1]]) {
@@ -341,7 +343,13 @@ const _OptionsParser = class _OptionsParser {
341
343
  if (existIncludeIndex == -1) {
342
344
  const association = associations[appendAssociation];
343
345
  if (!association) {
344
- throw new Error(`association ${appendAssociation} in ${model.name} not found`);
346
+ throw new import_association_not_found_error.AssociationNotFoundError(`association ${appendAssociation} in ${model.name} not found`);
347
+ }
348
+ const targetCollectionName = (_b = this.database.getCollectionByModelName(association.target.name)) == null ? void 0 : _b.name;
349
+ if (!targetCollectionName) {
350
+ throw new import_association_not_found_error.AssociationNotFoundError(
351
+ `target collection for association ${appendAssociation} in ${model.name} not found`
352
+ );
345
353
  }
346
354
  let includeOptions = {
347
355
  association: appendAssociation,
@@ -394,7 +402,15 @@ const _OptionsParser = class _OptionsParser {
394
402
  }
395
403
  }, "setInclude");
396
404
  for (const append of sortedAppends) {
397
- setInclude(this.model, filterParams, append);
405
+ try {
406
+ setInclude(this.model, filterParams, append);
407
+ } catch (error) {
408
+ if (error instanceof import_association_not_found_error.AssociationNotFoundError) {
409
+ this.associationNotFoundWarnings.push(error.message);
410
+ continue;
411
+ }
412
+ throw error;
413
+ }
398
414
  }
399
415
  debug("filter params: %o", filterParams);
400
416
  return filterParams;
package/lib/repository.js CHANGED
@@ -647,6 +647,9 @@ const _Repository = class _Repository {
647
647
  collection: this.collection
648
648
  });
649
649
  const params = parser.toSequelizeParams({ parseSort: import_lodash2.default.isBoolean(options == null ? void 0 : options.parseSort) ? options.parseSort : true });
650
+ if (parser.associationNotFoundWarnings.length > 0) {
651
+ this.database.logger.warn(parser.associationNotFoundWarnings.join("; "));
652
+ }
650
653
  debug("sequelize query params %o", params);
651
654
  if (options.where && params.where) {
652
655
  params.where = {
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/database",
3
- "version": "2.0.22",
3
+ "version": "2.0.23",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "license": "Apache-2.0",
8
8
  "dependencies": {
9
- "@nocobase/logger": "2.0.22",
10
- "@nocobase/utils": "2.0.22",
9
+ "@nocobase/logger": "2.0.23",
10
+ "@nocobase/utils": "2.0.23",
11
11
  "async-mutex": "^0.3.2",
12
12
  "chalk": "^4.1.1",
13
13
  "cron-parser": "4.4.0",
@@ -38,5 +38,5 @@
38
38
  "url": "git+https://github.com/nocobase/nocobase.git",
39
39
  "directory": "packages/database"
40
40
  },
41
- "gitHead": "7b703580c4bb60f1e5e44c8fd685141bb8b3a47c"
41
+ "gitHead": "c96c6eb1b2320087a563acc2cb39e3d17edfdcba"
42
42
  }