@nocobase/database 0.18.0-alpha.1 → 0.18.0-alpha.3

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/lib/database.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Logger } from '@nocobase/logger';
2
+ import { Logger, LoggerOptions } from '@nocobase/logger';
3
3
  import { AsyncEmitter } from '@nocobase/utils';
4
4
  import merge from 'deepmerge';
5
5
  import { EventEmitter } from 'events';
@@ -36,6 +36,7 @@ export interface IDatabaseOptions extends Options {
36
36
  migrator?: any;
37
37
  usingBigIntForId?: boolean;
38
38
  underscored?: boolean;
39
+ logger?: LoggerOptions | Logger;
39
40
  customHooks?: any;
40
41
  instanceId?: string;
41
42
  }
@@ -114,7 +115,6 @@ export declare class Database extends EventEmitter implements AsyncEmitter {
114
115
  get instanceId(): string;
115
116
  registerCollectionType(): void;
116
117
  setContext(context: any): void;
117
- setLogger(logger: Logger): void;
118
118
  sequelizeOptions(options: any): any;
119
119
  initListener(): void;
120
120
  addMigration(item: MigrationItem): void;
package/lib/database.js CHANGED
@@ -36,6 +36,7 @@ __export(database_exports, {
36
36
  extendCollection: () => extendCollection
37
37
  });
38
38
  module.exports = __toCommonJS(database_exports);
39
+ var import_logger = require("@nocobase/logger");
39
40
  var import_utils = require("@nocobase/utils");
40
41
  var import_events = require("events");
41
42
  var import_exponential_backoff = require("exponential-backoff");
@@ -157,6 +158,15 @@ const _Database = class _Database extends import_events.EventEmitter {
157
158
  },
158
159
  ...import_lodash.default.clone(options)
159
160
  };
161
+ if (options.logger) {
162
+ if (typeof options.logger["log"] === "function") {
163
+ this.logger = options.logger;
164
+ } else {
165
+ this.logger = (0, import_logger.createLogger)(options.logger);
166
+ }
167
+ } else {
168
+ this.logger = (0, import_logger.createConsoleLogger)();
169
+ }
160
170
  if (!options.instanceId) {
161
171
  this._instanceId = (0, import_nanoid.nanoid)();
162
172
  } else {
@@ -260,9 +270,6 @@ const _Database = class _Database extends import_events.EventEmitter {
260
270
  setContext(context) {
261
271
  this.context = context;
262
272
  }
263
- setLogger(logger) {
264
- this.logger = logger;
265
- }
266
273
  sequelizeOptions(options) {
267
274
  if (options.dialect === "postgres") {
268
275
  if (!options.hooks) {
@@ -572,11 +579,13 @@ const _Database = class _Database extends import_events.EventEmitter {
572
579
  const authenticate = /* @__PURE__ */ __name(async () => {
573
580
  try {
574
581
  await this.sequelize.authenticate(others);
575
- console.log("Connection has been established successfully.");
582
+ this.logger.info("Connection has been established successfully.", { method: "auth" });
576
583
  } catch (error) {
577
- console.log(`Attempt ${attemptNumber}/${retry}: Unable to connect to the database: ${error.message}`);
584
+ this.logger.warn(`Attempt ${attemptNumber}/${retry}: Unable to connect to the database: ${error.message}`, {
585
+ method: "auth"
586
+ });
578
587
  const nextDelay = startingDelay * Math.pow(timeMultiple, attemptNumber - 1);
579
- console.log(`Will retry in ${nextDelay}ms...`);
588
+ this.logger.warn(`Will retry in ${nextDelay}ms...`, { method: "auth" });
580
589
  attemptNumber++;
581
590
  throw error;
582
591
  }
@@ -147,13 +147,22 @@ const _EagerLoadingTree = class _EagerLoadingTree {
147
147
  var _a2, _b;
148
148
  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));
149
149
  });
150
- const belongsToAssociationsOnly = includeForFilter.every((include) => {
151
- const association = node.model.associations[include.association];
152
- if (!association) {
153
- return false;
150
+ const isBelongsToAssociationOnly = /* @__PURE__ */ __name((includes, model) => {
151
+ for (const include of includes) {
152
+ const association = model.associations[include.association];
153
+ if (!association) {
154
+ return false;
155
+ }
156
+ if (association.associationType != "BelongsTo") {
157
+ return false;
158
+ }
159
+ if (!isBelongsToAssociationOnly(include.include || [], association.target)) {
160
+ return false;
161
+ }
154
162
  }
155
- return association.associationType == "BelongsTo";
156
- });
163
+ return true;
164
+ }, "isBelongsToAssociationOnly");
165
+ const belongsToAssociationsOnly = isBelongsToAssociationOnly(includeForFilter, node.model);
157
166
  if (belongsToAssociationsOnly) {
158
167
  instances = await node.model.findAll({
159
168
  ...this.rootQueryOptions,
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
8
  var __export = (target, all) => {
@@ -15,12 +17,21 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
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
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var array_exports = {};
20
30
  __export(array_exports, {
21
31
  default: () => array_default
22
32
  });
23
33
  module.exports = __toCommonJS(array_exports);
34
+ var import_lodash = __toESM(require("lodash"));
24
35
  var import_sequelize = require("sequelize");
25
36
  var import_utils = require("./utils");
26
37
  const getFieldName = /* @__PURE__ */ __name((ctx) => {
@@ -89,6 +100,7 @@ var array_default = {
89
100
  },
90
101
  $anyOf(value, ctx) {
91
102
  const fieldName = getFieldName(ctx);
103
+ value = import_lodash.default.castArray(value);
92
104
  if ((0, import_utils.isPg)(ctx)) {
93
105
  const name = ctx.fullName === fieldName ? `"${ctx.model.name}"."${fieldName}"` : `"${fieldName}"`;
94
106
  return import_sequelize.Sequelize.literal(
@@ -108,6 +120,7 @@ var array_default = {
108
120
  },
109
121
  $noneOf(value, ctx) {
110
122
  let where;
123
+ value = import_lodash.default.castArray(value);
111
124
  if ((0, import_utils.isPg)(ctx)) {
112
125
  const fieldName = getFieldName(ctx);
113
126
  const name = ctx.fullName === fieldName ? `"${ctx.model.name}"."${fieldName}"` : `"${fieldName}"`;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/database",
3
- "version": "0.18.0-alpha.1",
3
+ "version": "0.18.0-alpha.3",
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": "0.18.0-alpha.1",
10
- "@nocobase/utils": "0.18.0-alpha.1",
9
+ "@nocobase/logger": "0.18.0-alpha.3",
10
+ "@nocobase/utils": "0.18.0-alpha.3",
11
11
  "async-mutex": "^0.3.2",
12
12
  "chalk": "^4.1.1",
13
13
  "cron-parser": "4.4.0",
@@ -18,6 +18,7 @@
18
18
  "flat": "^5.0.2",
19
19
  "glob": "^7.1.6",
20
20
  "graphlib": "^2.1.8",
21
+ "lodash": "^4.17.21",
21
22
  "mathjs": "^10.6.1",
22
23
  "nanoid": "^3.3.6",
23
24
  "qs": "^6.11.2",
@@ -34,5 +35,5 @@
34
35
  "url": "git+https://github.com/nocobase/nocobase.git",
35
36
  "directory": "packages/database"
36
37
  },
37
- "gitHead": "0f5f1c0a37dc397a9dc4c8eec0c4ec20fd8107b0"
38
+ "gitHead": "3d34bcd0e3aca0f485e4a2425b87bc971526634d"
38
39
  }