Просмотр исходного кода

chore: upgrades @e22m4u/repository to 0.0.21

e22m4u 2 лет назад
Родитель
Сommit
8a24d57e57

+ 2 - 1
package.json

@@ -36,7 +36,8 @@
     "mongodb": "5.8.1"
   },
   "peerDependencies": {
-    "@e22m4u/repository": "^0.0.18"
+    "@e22m4u/format": "*",
+    "@e22m4u/repository": "^0.0.21"
   },
   "devDependencies": {
     "@commitlint/cli": "^17.7.1",

+ 11 - 11
src/mongodb-adapter.js

@@ -278,7 +278,7 @@ export class MongodbAdapter extends Adapter {
     if (idColName !== 'id' && idColName !== '_id')
       throw new InvalidArgumentError(
         'MongoDB is not supporting custom names of the primary key. ' +
-          'Do use "id" as a primary key instead of %s.',
+          'Do use "id" as a primary key instead of %v.',
         idColName,
       );
     if (idColName in tableData && idColName !== '_id') {
@@ -309,7 +309,7 @@ export class MongodbAdapter extends Adapter {
       if (idColName !== 'id' && idColName !== '_id')
         throw new InvalidArgumentError(
           'MongoDB is not supporting custom names of the primary key. ' +
-            'Do use "id" as a primary key instead of %s.',
+            'Do use "id" as a primary key instead of %v.',
           idColName,
         );
       if (idColName !== '_id') {
@@ -375,7 +375,7 @@ export class MongodbAdapter extends Adapter {
     return fields.reduce((acc, field) => {
       if (!field || typeof field !== 'string')
         throw new InvalidArgumentError(
-          'A field name must be a non-empty String, but %s given.',
+          'A field name must be a non-empty String, but %v given.',
           field,
         );
       let colName = this._getColName(modelName, field);
@@ -395,7 +395,7 @@ export class MongodbAdapter extends Adapter {
   _getColName(modelName, propName) {
     if (!propName || typeof propName !== 'string')
       throw new InvalidArgumentError(
-        'A property name must be a non-empty String, but %s given.',
+        'A property name must be a non-empty String, but %v given.',
         propName,
       );
     const utils = this.get(ModelDefinitionUtils);
@@ -430,7 +430,7 @@ export class MongodbAdapter extends Adapter {
     return clause.reduce((acc, order) => {
       if (!order || typeof order !== 'string')
         throw new InvalidArgumentError(
-          'A field order must be a non-empty String, but %s given.',
+          'A field order must be a non-empty String, but %v given.',
           order,
         );
       const direction = order.match(/\s+(A|DE)SC$/);
@@ -616,7 +616,7 @@ export class MongodbAdapter extends Adapter {
           const flags = cond.flags || undefined;
           if (flags && typeof flags !== 'string')
             throw new InvalidArgumentError(
-              'RegExp flags must be a String, but %s given.',
+              'RegExp flags must be a String, but %v given.',
               cond.flags,
             );
           query[key] = {$regex: stringToRegexp(cond.regexp, flags)};
@@ -646,9 +646,9 @@ export class MongodbAdapter extends Adapter {
       if (pkType !== DataType.STRING && pkType !== DataType.ANY)
         throw new InvalidArgumentError(
           'MongoDB unable to generate primary keys of %s. ' +
-            'Do provide your own value for the %s property ' +
+            'Do provide your own value for the %v property ' +
             'or set property type to String.',
-          new String(capitalize(pkType)),
+          capitalize(pkType),
           idPropName,
         );
       delete modelData[idPropName];
@@ -682,7 +682,7 @@ export class MongodbAdapter extends Adapter {
     const table = this._getCollection(modelName);
     const {modifiedCount} = await table.replaceOne({_id: id}, tableData);
     if (modifiedCount < 1)
-      throw new InvalidArgumentError('Identifier %s is not found.', String(id));
+      throw new InvalidArgumentError('Identifier %v is not found.', String(id));
     const projection = this._buildProjection(
       modelName,
       filter && filter.fields,
@@ -709,7 +709,7 @@ export class MongodbAdapter extends Adapter {
     const table = this._getCollection(modelName);
     const {modifiedCount} = await table.updateOne({_id: id}, {$set: tableData});
     if (modifiedCount < 1)
-      throw new InvalidArgumentError('Identifier %s is not found.', String(id));
+      throw new InvalidArgumentError('Identifier %v is not found.', String(id));
     const projection = this._buildProjection(
       modelName,
       filter && filter.fields,
@@ -757,7 +757,7 @@ export class MongodbAdapter extends Adapter {
     );
     const patchedData = await table.findOne({_id: id}, {projection});
     if (!patchedData)
-      throw new InvalidArgumentError('Identifier %s is not found.', String(id));
+      throw new InvalidArgumentError('Identifier %v is not found.', String(id));
     return this._fromDatabase(modelName, patchedData);
   }
 

+ 1 - 1
src/mongodb-adapter.spec.js

@@ -1,7 +1,7 @@
-import {format} from 'util';
 import {expect} from 'chai';
 import {ObjectId} from 'mongodb';
 import {MongoClient} from 'mongodb';
+import {format} from '@e22m4u/format';
 import {Schema} from '@e22m4u/repository';
 import {Service} from '@e22m4u/repository';
 import {DataType} from '@e22m4u/repository';

+ 10 - 10
src/utils/create-mongodb-url.js

@@ -6,22 +6,22 @@ import {InvalidArgumentError} from '@e22m4u/repository';
 export function createMongodbUrl(options = {}) {
   if (!options || typeof options !== 'object' || Array.isArray(options))
     throw new InvalidArgumentError(
-      'The first argument of "createMongodbUrl" must be an Object, but %s given.',
+      'The first argument of "createMongodbUrl" must be an Object, but %v given.',
       options,
     );
   if (options.protocol && typeof options.protocol !== 'string')
     throw new InvalidArgumentError(
-      'MongoDB option "protocol" must be a string, but %s given.',
+      'MongoDB option "protocol" must be a string, but %v given.',
       options.protocol,
     );
   if (options.hostname && typeof options.hostname !== 'string')
     throw new InvalidArgumentError(
-      'MongoDB option "hostname" must be a String, but %s given.',
+      'MongoDB option "hostname" must be a String, but %v given.',
       options.hostname,
     );
   if (options.host && typeof options.host !== 'string')
     throw new InvalidArgumentError(
-      'MongoDB option "host" must be a String, but %s given.',
+      'MongoDB option "host" must be a String, but %v given.',
       options.host,
     );
   if (
@@ -30,23 +30,23 @@ export function createMongodbUrl(options = {}) {
     typeof options.port !== 'string'
   ) {
     throw new InvalidArgumentError(
-      'MongoDB option "port" must be a Number or a String, but %s given.',
+      'MongoDB option "port" must be a Number or a String, but %v given.',
       options.port,
     );
   }
   if (options.database && typeof options.database !== 'string')
     throw new InvalidArgumentError(
-      'MongoDB option "database" must be a String, but %s given.',
+      'MongoDB option "database" must be a String, but %v given.',
       options.database,
     );
   if (options.db && typeof options.db !== 'string')
     throw new InvalidArgumentError(
-      'MongoDB option "db" must be a String, but %s given.',
+      'MongoDB option "db" must be a String, but %v given.',
       options.db,
     );
   if (options.username && typeof options.username !== 'string')
     throw new InvalidArgumentError(
-      'MongoDB option "username" must be a String, but %s given.',
+      'MongoDB option "username" must be a String, but %v given.',
       options.username,
     );
   if (
@@ -55,7 +55,7 @@ export function createMongodbUrl(options = {}) {
     typeof options.password !== 'number'
   ) {
     throw new InvalidArgumentError(
-      'MongoDB option "password" must be a String or a Number, but %s given.',
+      'MongoDB option "password" must be a String or a Number, but %v given.',
       options.password,
     );
   }
@@ -65,7 +65,7 @@ export function createMongodbUrl(options = {}) {
     typeof options.pass !== 'number'
   ) {
     throw new InvalidArgumentError(
-      'MongoDB option "pass" must be a String or a Number, but %s given.',
+      'MongoDB option "pass" must be a String or a Number, but %v given.',
       options.pass,
     );
   }

+ 1 - 1
src/utils/create-mongodb-url.spec.js

@@ -1,5 +1,5 @@
-import {format} from 'util';
 import {expect} from 'chai';
+import {format} from '@e22m4u/format';
 import {createMongodbUrl} from './create-mongodb-url.js';
 
 describe('createMongodbUrl', function () {