chore: define collection debug message (#4176)

* chore: define collection debug message

* chore: safe debug log

* chore: safe debug log
This commit is contained in:
ChengLei Shao 2024-04-26 10:14:37 +08:00 committed by GitHub
parent 7748a33138
commit 12ba257cf6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 1 deletions

View File

@ -26,7 +26,8 @@
"semver": "^7.3.7",
"sequelize": "^6.26.0",
"umzug": "^3.1.1",
"uuid": "^9.0.1"
"uuid": "^9.0.1",
"safe-json-stringify": "^1.2.0"
},
"devDependencies": {
"@types/glob": "^7.2.0"

View File

@ -17,6 +17,7 @@ import { Model } from './model';
import { AdjacencyListRepository } from './repositories/tree-repository/adjacency-list-repository';
import { Repository } from './repository';
import { checkIdentifier, md5, snakeCase } from './utils';
import safeJsonStringify from 'safe-json-stringify';
export type RepositoryType = typeof Repository;
@ -275,6 +276,7 @@ export class Collection<
getFields() {
return [...this.fields.values()];
}
addField(name: string, options: FieldOptions): Field {
return this.setField(name, options);
}
@ -318,6 +320,8 @@ export class Collection<
const { database } = this.context;
database.logger.debug(`beforeSetField: ${this.name}, ${name}, ${safeJsonStringify(options)}`);
if (options.source) {
const [sourceCollectionName, sourceFieldName] = options.source.split('.');
const sourceCollection = this.db.collections.get(sourceCollectionName);

View File

@ -6,6 +6,7 @@ import { EventEmitter } from 'events';
import { backOff } from 'exponential-backoff';
import glob from 'glob';
import lodash from 'lodash';
import safeJsonStringify from 'safe-json-stringify';
import { nanoid } from 'nanoid';
import { basename, isAbsolute, resolve } from 'path';
import semver from 'semver';
@ -537,6 +538,8 @@ export class Database extends EventEmitter implements AsyncEmitter {
options.underscored = true;
}
this.logger.debug(`beforeDefineCollection: ${safeJsonStringify(options)}`);
this.emit('beforeDefineCollection', options);
const collection = this.collectionFactory.createCollection(options);

View File

@ -23240,6 +23240,11 @@ safe-buffer@5.2.1, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, s
resolved "https://registry.npmmirror.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==
safe-json-stringify@^1.2.0:
version "1.2.0"
resolved "https://registry.npmmirror.com/safe-json-stringify/-/safe-json-stringify-1.2.0.tgz#356e44bc98f1f93ce45df14bcd7c01cda86e0afd"
integrity sha512-gH8eh2nZudPQO6TytOvbxnuhYBOvDBBLW52tz5q6X58lJcd/tkmqFR+5Z9adS8aJtURSXWThWy/xJtJwixErvg==
safe-regex-test@^1.0.0:
version "1.0.0"
resolved "https://registry.npmmirror.com/safe-regex-test/-/safe-regex-test-1.0.0.tgz#793b874d524eb3640d1873aad03596db2d4f2295"