@naturalcycles/db-lib 8.34.1 → 8.36.0

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.
Files changed (40) hide show
  1. package/dist/adapter/cachedb/cache.db.d.ts +9 -9
  2. package/dist/adapter/cachedb/cache.db.js +3 -1
  3. package/dist/adapter/cachedb/cache.db.model.d.ts +5 -3
  4. package/dist/adapter/file/file.db.d.ts +2 -2
  5. package/dist/adapter/inmemory/inMemory.db.d.ts +2 -2
  6. package/dist/adapter/inmemory/inMemory.db.js +6 -3
  7. package/dist/base.common.db.d.ts +2 -2
  8. package/dist/common.db.d.ts +3 -3
  9. package/dist/commondao/common.dao.d.ts +21 -21
  10. package/dist/commondao/common.dao.js +24 -22
  11. package/dist/commondao/common.dao.model.d.ts +22 -22
  12. package/dist/db.model.d.ts +2 -17
  13. package/dist/index.d.ts +4 -5
  14. package/dist/index.js +2 -4
  15. package/dist/pipeline/dbPipelineBackup.js +1 -2
  16. package/dist/pipeline/dbPipelineCopy.js +1 -2
  17. package/dist/pipeline/dbPipelineRestore.js +1 -2
  18. package/dist/query/dbQuery.d.ts +6 -6
  19. package/dist/validation/index.d.ts +3 -3
  20. package/package.json +1 -2
  21. package/src/adapter/cachedb/cache.db.model.ts +8 -7
  22. package/src/adapter/cachedb/cache.db.ts +20 -17
  23. package/src/adapter/file/file.db.ts +2 -2
  24. package/src/adapter/inmemory/inMemory.db.ts +9 -5
  25. package/src/base.common.db.ts +2 -2
  26. package/src/common.db.ts +7 -3
  27. package/src/commondao/common.dao.model.ts +31 -24
  28. package/src/commondao/common.dao.ts +78 -76
  29. package/src/db.model.ts +2 -18
  30. package/src/index.ts +2 -22
  31. package/src/pipeline/dbPipelineBackup.ts +9 -3
  32. package/src/pipeline/dbPipelineCopy.ts +2 -3
  33. package/src/pipeline/dbPipelineRestore.ts +2 -2
  34. package/src/query/dbQuery.ts +8 -7
  35. package/dist/adapter/inmemory/index.d.ts +0 -3
  36. package/dist/adapter/inmemory/index.js +0 -8
  37. package/dist/getDB.d.ts +0 -19
  38. package/dist/getDB.js +0 -32
  39. package/src/adapter/inmemory/index.ts +0 -9
  40. package/src/getDB.ts +0 -50
@@ -1,9 +0,0 @@
1
- import { CommonDB } from '../../common.db'
2
- import { InMemoryDB } from './inMemory.db'
3
-
4
- export function getDBAdapter(): CommonDB {
5
- return new InMemoryDB()
6
- }
7
-
8
- export // InMemoryDB, // no, otherwise it's double-exported, which can confuse IDEs
9
- {}
package/src/getDB.ts DELETED
@@ -1,50 +0,0 @@
1
- import { _memoFn } from '@naturalcycles/js-lib'
2
- import { secretOptional } from '@naturalcycles/nodejs-lib'
3
- import { white, yellow } from '@naturalcycles/nodejs-lib/dist/colors'
4
- import { CommonDB } from './common.db'
5
- import { CommonDBAdapter } from './db.model'
6
-
7
- /**
8
- * Returns pre-configured DB
9
- *
10
- * @param index defaults to 1
11
- *
12
- * Requires process.env.DB${index} to be set to the name of the adapter, e.g `mysql-lib` or `db-lib/adapter/inmemory`.
13
- * Requires (by most adapters) process.env.SECRET_DB${index} to contain a "connection string" to that DB. Usually a JSON.stringified object,
14
- * but depends on the adapter.
15
- */
16
- export function getDB(index = 1): CommonDB {
17
- return _getDB(index)
18
- }
19
-
20
- // Extra function to provide index=1 as default (since memo doesn't work well with default arguments)
21
- const _getDB = _memoFn((index: number) => {
22
- const libName = process.env[`DB${index}`]
23
-
24
- if (!libName) {
25
- throw new Error(
26
- `getDB(${yellow(index)}), but process.env.${white('DB' + index)} is not defined!`,
27
- )
28
- }
29
-
30
- const lib: CommonDBAdapter = require(libName)
31
-
32
- if (!lib.getDBAdapter) {
33
- throw new Error(
34
- `DB${index}=${libName}, but require('${libName}').getDBAdapter() is not defined`,
35
- )
36
- }
37
-
38
- const cfg = secretOptional(`SECRET_DB${index}`)
39
-
40
- return lib.getDBAdapter(cfg)
41
- })
42
-
43
- declare global {
44
- namespace NodeJS {
45
- interface ProcessEnv {
46
- DB1?: string
47
- DB2?: string
48
- }
49
- }
50
- }