@naturalcycles/db-lib 8.54.2 → 8.54.4

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.
@@ -215,8 +215,7 @@ class CommonDao {
215
215
  }
216
216
  throwRequiredError(id, opt) {
217
217
  const table = opt.table || this.cfg.table;
218
- throw new js_lib_1.AppError(`DB row required, but not found: ${table}.${id}`, {
219
- code: cnst_1.DBLibError.DB_ROW_REQUIRED,
218
+ throw new js_lib_1.AppError(`DB row required, but not found in ${table}`, {
220
219
  table,
221
220
  id,
222
221
  });
@@ -227,7 +226,6 @@ class CommonDao {
227
226
  requireWriteAccess() {
228
227
  if (this.cfg.readOnly) {
229
228
  throw new js_lib_1.AppError(cnst_1.DBLibError.DAO_IS_READ_ONLY, {
230
- code: cnst_1.DBLibError.DAO_IS_READ_ONLY,
231
229
  table: this.cfg.table,
232
230
  });
233
231
  }
@@ -238,7 +236,6 @@ class CommonDao {
238
236
  requireObjectMutability(opt) {
239
237
  if (this.cfg.immutable && !opt.allowMutability) {
240
238
  throw new js_lib_1.AppError(cnst_1.DBLibError.OBJECT_IS_IMMUTABLE, {
241
- code: cnst_1.DBLibError.OBJECT_IS_IMMUTABLE,
242
239
  table: this.cfg.table,
243
240
  });
244
241
  }
@@ -249,7 +246,6 @@ class CommonDao {
249
246
  if (existing.length) {
250
247
  throw new js_lib_1.AppError(cnst_1.DBLibError.NON_UNIQUE_ID, {
251
248
  table,
252
- code: cnst_1.DBLibError.NON_UNIQUE_ID,
253
249
  ids: existing.map(i => i.id),
254
250
  });
255
251
  }
package/dist/index.d.ts CHANGED
@@ -2,7 +2,6 @@ export * from './adapter/inmemory/inMemory.db';
2
2
  export * from './adapter/inmemory/inMemoryKeyValueDB';
3
3
  export * from './adapter/inmemory/queryInMemory';
4
4
  export * from './base.common.db';
5
- export * from './cnst';
6
5
  export * from './common.db';
7
6
  export * from './commondao/common.dao';
8
7
  export * from './commondao/common.dao.model';
package/dist/index.js CHANGED
@@ -5,7 +5,6 @@ tslib_1.__exportStar(require("./adapter/inmemory/inMemory.db"), exports);
5
5
  tslib_1.__exportStar(require("./adapter/inmemory/inMemoryKeyValueDB"), exports);
6
6
  tslib_1.__exportStar(require("./adapter/inmemory/queryInMemory"), exports);
7
7
  tslib_1.__exportStar(require("./base.common.db"), exports);
8
- tslib_1.__exportStar(require("./cnst"), exports);
9
8
  tslib_1.__exportStar(require("./common.db"), exports);
10
9
  tslib_1.__exportStar(require("./commondao/common.dao"), exports);
11
10
  tslib_1.__exportStar(require("./commondao/common.dao.model"), exports);
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommonKeyValueDao = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
5
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
6
- const cnst_1 = require("../cnst");
7
6
  // todo: logging
8
7
  // todo: readonly
9
8
  class CommonKeyValueDao {
@@ -44,8 +43,7 @@ class CommonKeyValueDao {
44
43
  const [r] = await this.getByIds([id]);
45
44
  if (!r) {
46
45
  const { table } = this.cfg;
47
- throw new js_lib_1.AppError(`DB row required, but not found: ${table}.${id}`, {
48
- code: cnst_1.DBLibError.DB_ROW_REQUIRED,
46
+ throw new js_lib_1.AppError(`DB row required, but not found in ${table}`, {
49
47
  table,
50
48
  id,
51
49
  });
@@ -56,8 +54,7 @@ class CommonKeyValueDao {
56
54
  const [r] = await this.cfg.db.getByIds(this.cfg.table, [id]);
57
55
  if (!r) {
58
56
  const { table } = this.cfg;
59
- throw new js_lib_1.AppError(`DB row required, but not found: ${table}.${id}`, {
60
- code: cnst_1.DBLibError.DB_ROW_REQUIRED,
57
+ throw new js_lib_1.AppError(`DB row required, but not found in ${table}`, {
61
58
  table,
62
59
  id,
63
60
  });
@@ -44,7 +44,7 @@ async function dbPipelineBackup(opt) {
44
44
  console.log(`>> ${(0, colors_1.grey)(filePath)} started...`);
45
45
  if (emitSchemaFromDB) {
46
46
  const schema = await db.getTableSchema(table);
47
- await (0, nodejs_lib_1._writeJsonFile)(schemaFilePath, schema, { spaces: 2 });
47
+ await (0, nodejs_lib_1._writeJson)(schemaFilePath, schema, { spaces: 2 });
48
48
  console.log(`>> ${(0, colors_1.grey)(schemaFilePath)} saved (generated from DB)`);
49
49
  }
50
50
  await (0, nodejs_lib_1._pipeline)([
package/package.json CHANGED
@@ -40,7 +40,7 @@
40
40
  "engines": {
41
41
  "node": ">=18.12"
42
42
  },
43
- "version": "8.54.2",
43
+ "version": "8.54.4",
44
44
  "description": "Lowest Common Denominator API to supported Databases",
45
45
  "keywords": [
46
46
  "db",
@@ -249,8 +249,7 @@ export class CommonDao<
249
249
 
250
250
  private throwRequiredError(id: ID, opt: CommonDaoOptions): never {
251
251
  const table = opt.table || this.cfg.table
252
- throw new AppError(`DB row required, but not found: ${table}.${id}`, {
253
- code: DBLibError.DB_ROW_REQUIRED,
252
+ throw new AppError(`DB row required, but not found in ${table}`, {
254
253
  table,
255
254
  id,
256
255
  })
@@ -262,7 +261,6 @@ export class CommonDao<
262
261
  private requireWriteAccess(): void {
263
262
  if (this.cfg.readOnly) {
264
263
  throw new AppError(DBLibError.DAO_IS_READ_ONLY, {
265
- code: DBLibError.DAO_IS_READ_ONLY,
266
264
  table: this.cfg.table,
267
265
  })
268
266
  }
@@ -274,7 +272,6 @@ export class CommonDao<
274
272
  private requireObjectMutability(opt: CommonDaoOptions): void {
275
273
  if (this.cfg.immutable && !opt.allowMutability) {
276
274
  throw new AppError(DBLibError.OBJECT_IS_IMMUTABLE, {
277
- code: DBLibError.OBJECT_IS_IMMUTABLE,
278
275
  table: this.cfg.table,
279
276
  })
280
277
  }
@@ -286,7 +283,6 @@ export class CommonDao<
286
283
  if (existing.length) {
287
284
  throw new AppError(DBLibError.NON_UNIQUE_ID, {
288
285
  table,
289
- code: DBLibError.NON_UNIQUE_ID,
290
286
  ids: existing.map(i => i.id),
291
287
  })
292
288
  }
package/src/index.ts CHANGED
@@ -2,7 +2,6 @@ export * from './adapter/inmemory/inMemory.db'
2
2
  export * from './adapter/inmemory/inMemoryKeyValueDB'
3
3
  export * from './adapter/inmemory/queryInMemory'
4
4
  export * from './base.common.db'
5
- export * from './cnst'
6
5
  export * from './common.db'
7
6
  export * from './commondao/common.dao'
8
7
  export * from './commondao/common.dao.model'
@@ -5,7 +5,6 @@ import {
5
5
  ReadableTyped,
6
6
  transformMap,
7
7
  } from '@naturalcycles/nodejs-lib'
8
- import { DBLibError } from '../cnst'
9
8
  import { CommonDaoLogLevel } from '../commondao/common.dao.model'
10
9
  import { CommonDBCreateOptions } from '../db.model'
11
10
  import { CommonKeyValueDB, KeyValueDBTuple } from './commonKeyValueDB'
@@ -90,8 +89,7 @@ export class CommonKeyValueDao<T> {
90
89
 
91
90
  if (!r) {
92
91
  const { table } = this.cfg
93
- throw new AppError(`DB row required, but not found: ${table}.${id}`, {
94
- code: DBLibError.DB_ROW_REQUIRED,
92
+ throw new AppError(`DB row required, but not found in ${table}`, {
95
93
  table,
96
94
  id,
97
95
  })
@@ -105,8 +103,7 @@ export class CommonKeyValueDao<T> {
105
103
 
106
104
  if (!r) {
107
105
  const { table } = this.cfg
108
- throw new AppError(`DB row required, but not found: ${table}.${id}`, {
109
- code: DBLibError.DB_ROW_REQUIRED,
106
+ throw new AppError(`DB row required, but not found in ${table}`, {
110
107
  table,
111
108
  id,
112
109
  })
@@ -21,7 +21,7 @@ import {
21
21
  _ensureDirSync,
22
22
  _pathExistsSync,
23
23
  _ensureFileSync,
24
- _writeJsonFile,
24
+ _writeJson,
25
25
  } from '@naturalcycles/nodejs-lib'
26
26
  import { boldWhite, dimWhite, grey, yellow } from '@naturalcycles/nodejs-lib/dist/colors'
27
27
  import { CommonDB } from '../common.db'
@@ -194,7 +194,7 @@ export async function dbPipelineBackup(opt: DBPipelineBackupOptions): Promise<ND
194
194
 
195
195
  if (emitSchemaFromDB) {
196
196
  const schema = await db.getTableSchema(table)
197
- await _writeJsonFile(schemaFilePath, schema, { spaces: 2 })
197
+ await _writeJson(schemaFilePath, schema, { spaces: 2 })
198
198
  console.log(`>> ${grey(schemaFilePath)} saved (generated from DB)`)
199
199
  }
200
200