@nocobase/database 1.9.56 → 1.9.58

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;
@@ -294,7 +296,7 @@ const _OptionsParser = class _OptionsParser {
294
296
  }
295
297
  const sortedAppends = import_lodash.default.sortBy(appendList, (append) => append.split(".").length);
296
298
  const setInclude = /* @__PURE__ */ __name((model, queryParams, append, parentAs) => {
297
- var _a;
299
+ var _a, _b;
298
300
  const appendWithOptions = this.parseAppendWithOptions(append);
299
301
  append = appendWithOptions.name;
300
302
  const appendFields = append.split(".");
@@ -307,7 +309,7 @@ const _OptionsParser = class _OptionsParser {
307
309
  if (appendFields.length == 2) {
308
310
  const association = associations[appendFields[0]];
309
311
  if (!association) {
310
- throw new Error(`association ${appendFields[0]} in ${model.name} not found`);
312
+ throw new import_association_not_found_error.AssociationNotFoundError(`association ${appendFields[0]} in ${model.name} not found`);
311
313
  }
312
314
  const associationModel = associations[appendFields[0]].target;
313
315
  if (associationModel.rawAttributes[appendFields[1]]) {
@@ -334,7 +336,13 @@ const _OptionsParser = class _OptionsParser {
334
336
  if (existIncludeIndex == -1) {
335
337
  const association = associations[appendAssociation];
336
338
  if (!association) {
337
- throw new Error(`association ${appendAssociation} in ${model.name} not found`);
339
+ throw new import_association_not_found_error.AssociationNotFoundError(`association ${appendAssociation} in ${model.name} not found`);
340
+ }
341
+ const targetCollectionName = (_b = this.database.getCollectionByModelName(association.target.name)) == null ? void 0 : _b.name;
342
+ if (!targetCollectionName) {
343
+ throw new import_association_not_found_error.AssociationNotFoundError(
344
+ `target collection for association ${appendAssociation} in ${model.name} not found`
345
+ );
338
346
  }
339
347
  let includeOptions = {
340
348
  association: appendAssociation,
@@ -387,7 +395,15 @@ const _OptionsParser = class _OptionsParser {
387
395
  }
388
396
  }, "setInclude");
389
397
  for (const append of sortedAppends) {
390
- setInclude(this.model, filterParams, append);
398
+ try {
399
+ setInclude(this.model, filterParams, append);
400
+ } catch (error) {
401
+ if (error instanceof import_association_not_found_error.AssociationNotFoundError) {
402
+ this.associationNotFoundWarnings.push(error.message);
403
+ continue;
404
+ }
405
+ throw error;
406
+ }
391
407
  }
392
408
  debug("filter params: %o", filterParams);
393
409
  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": "1.9.56",
3
+ "version": "1.9.58",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "license": "AGPL-3.0",
8
8
  "dependencies": {
9
- "@nocobase/logger": "1.9.56",
10
- "@nocobase/utils": "1.9.56",
9
+ "@nocobase/logger": "1.9.58",
10
+ "@nocobase/utils": "1.9.58",
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": "6b8a1f7c2bd55343e3d7dee6258496176a27fb58"
41
+ "gitHead": "65b830e3ba46f4abdae6bbac29ef5d01fe64f2d9"
42
42
  }