@diia-inhouse/db 4.12.0 → 10.8.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.
- package/LICENCE.md +59 -59
- package/dist/cli/cleanupExpiredData.js +104 -0
- package/dist/cli/cleanupExpiredData.js.map +1 -0
- package/dist/cli/index.js +105 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/runMigration.js +73 -0
- package/dist/cli/runMigration.js.map +1 -0
- package/dist/cli/syncIndexes.js +45 -0
- package/dist/cli/syncIndexes.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/database.js +3 -0
- package/dist/interfaces/database.js.map +1 -0
- package/dist/interfaces/errors.js +5 -1
- package/dist/interfaces/errors.js.map +1 -1
- package/dist/interfaces/index.js +3 -0
- package/dist/interfaces/index.js.map +1 -1
- package/dist/interfaces/metrics.js +20 -0
- package/dist/interfaces/metrics.js.map +1 -0
- package/dist/interfaces/models/counter.js +3 -0
- package/dist/interfaces/models/counter.js.map +1 -0
- package/dist/interfaces/models/index.js +19 -0
- package/dist/interfaces/models/index.js.map +1 -0
- package/dist/mongo.js +18 -3
- package/dist/mongo.js.map +1 -1
- package/dist/postgres.js +19 -0
- package/dist/postgres.js.map +1 -0
- package/dist/postgresUtils.js +20 -0
- package/dist/postgresUtils.js.map +1 -0
- package/dist/schemas/counter.js +14 -0
- package/dist/schemas/counter.js.map +1 -0
- package/dist/{models → schemas}/encryptedStorage.js +4 -2
- package/dist/schemas/encryptedStorage.js.map +1 -0
- package/dist/schemas/index.js +20 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/statusHistoryItem.js +12 -0
- package/dist/schemas/statusHistoryItem.js.map +1 -0
- package/dist/services/counter.js +72 -0
- package/dist/services/counter.js.map +1 -0
- package/dist/services/database.js +123 -55
- package/dist/services/database.js.map +1 -1
- package/dist/services/encryptedStorage.js +136 -15
- package/dist/services/encryptedStorage.js.map +1 -1
- package/dist/services/index.js +2 -0
- package/dist/services/index.js.map +1 -1
- package/dist/services/postgresDatabase.js +25 -0
- package/dist/services/postgresDatabase.js.map +1 -0
- package/dist/tables/counter.js +12 -0
- package/dist/tables/counter.js.map +1 -0
- package/dist/tables/encryptedStorage.js +14 -0
- package/dist/tables/encryptedStorage.js.map +1 -0
- package/dist/tables/index.js +19 -0
- package/dist/tables/index.js.map +1 -0
- package/dist/types/cli/cleanupExpiredData.d.ts +11 -0
- package/dist/types/cli/index.d.ts +2 -0
- package/dist/types/cli/runMigration.d.ts +11 -0
- package/dist/types/cli/syncIndexes.d.ts +7 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/interfaces/database.d.ts +8 -0
- package/dist/types/interfaces/dbConfig.d.ts +8 -29
- package/dist/types/interfaces/errors.d.ts +5 -1
- package/dist/types/interfaces/index.d.ts +3 -25
- package/dist/types/interfaces/metrics.d.ts +20 -0
- package/dist/types/interfaces/migrateMongoConfig.d.ts +0 -24
- package/dist/types/interfaces/models/counter.d.ts +5 -0
- package/dist/types/interfaces/models/encryptedStorage.d.ts +1 -27
- package/dist/types/interfaces/models/index.d.ts +2 -0
- package/dist/types/postgres.d.ts +2 -0
- package/dist/types/postgresUtils.d.ts +26 -0
- package/dist/types/schemas/counter.d.ts +12 -0
- package/dist/types/schemas/encryptedStorage.d.ts +12 -0
- package/dist/types/schemas/index.d.ts +3 -0
- package/dist/types/schemas/statusHistoryItem.d.ts +3 -0
- package/dist/types/services/counter.d.ts +15 -0
- package/dist/types/services/database.d.ts +33 -33
- package/dist/types/services/encryptedStorage.d.ts +60 -34
- package/dist/types/services/index.d.ts +2 -0
- package/dist/types/services/postgresDatabase.d.ts +8 -0
- package/dist/types/tables/counter.d.ts +94 -0
- package/dist/types/tables/encryptedStorage.d.ts +111 -0
- package/dist/types/tables/index.d.ts +2 -0
- package/package.json +62 -60
- package/dist/models/encryptedStorage.js.map +0 -1
- package/dist/types/models/encryptedStorage.d.ts +0 -30
|
@@ -1,20 +1,130 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.EncryptedStorageService = void 0;
|
|
4
|
+
const drizzle_orm_1 = require("drizzle-orm");
|
|
7
5
|
const errors_1 = require("@diia-inhouse/errors");
|
|
8
6
|
const utils_1 = require("@diia-inhouse/utils");
|
|
9
|
-
const encryptedStorage_1 =
|
|
7
|
+
const encryptedStorage_1 = require("../tables/encryptedStorage");
|
|
8
|
+
/**
|
|
9
|
+
* EncryptedStorageService provides CRUD operations for managing encrypted storage entries
|
|
10
|
+
* in both Postgres and MongoDB databases. The service abstracts database implementation details
|
|
11
|
+
* using a strategy pattern depending on the configured database adapter type.
|
|
12
|
+
*
|
|
13
|
+
* Suitable for storing and managing sensitive data in an encrypted manner with specific expiration time.
|
|
14
|
+
*
|
|
15
|
+
* This service should be wrapped in a repository.
|
|
16
|
+
*
|
|
17
|
+
* Register this service in the DI container with the following (MongoDB) configuration (AuthService is located in @diia-inhouse/crypto):
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // src/deps.ts
|
|
20
|
+
* encryptedStorage: asClass(EncryptedStorageService, { injector: () => ({ encryptedStorageModel }) }).singleton(),
|
|
21
|
+
* auth: asClass(AuthService, { injector: () => ({ authConfig: config.auth }) }).singleton()
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // src/config.ts
|
|
26
|
+
* auth: {
|
|
27
|
+
* jwk: await envService.getSecret('JWE_SECRET_DATA_JWK'),
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // src/models/encryptedStorage.ts
|
|
33
|
+
* import { EncryptedStorage, Model, encryptedStorageSchema, model, models } from '@diia-inhouse/db'
|
|
34
|
+
*
|
|
35
|
+
* export default (models.EncryptedStorage as Model<EncryptedStorage>) || model('EncryptedStorage', encryptedStorageSchema)
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* Use the following command to generate a JWE secret data JWK:
|
|
39
|
+
* node -e "const crypto = require('crypto'); const { privateKey } = crypto.generateKeyPairSync('rsa', { modulusLength: 2048 }); const jwk = privateKey.export({ format: 'jwk' }); jwk.use = 'enc'; console.log(JSON.stringify(jwk));"
|
|
40
|
+
* ```typescript
|
|
41
|
+
* // .env.example
|
|
42
|
+
* JWE_SECRET_DATA_JWK={your-jwk-here}
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
10
45
|
class EncryptedStorageService {
|
|
11
46
|
logger;
|
|
12
47
|
auth;
|
|
13
48
|
envService;
|
|
14
|
-
|
|
49
|
+
databaseAdapter;
|
|
50
|
+
encryptedStorageModel;
|
|
51
|
+
postgresDatabase;
|
|
52
|
+
saveEntityStrategy = {
|
|
53
|
+
postgres: async (storageItem) => {
|
|
54
|
+
const result = await this.getPostgresDatabase()
|
|
55
|
+
.insert(encryptedStorage_1.encryptedStorage)
|
|
56
|
+
.values(storageItem)
|
|
57
|
+
.returning()
|
|
58
|
+
.then((rows) => rows[0]);
|
|
59
|
+
return result.id;
|
|
60
|
+
},
|
|
61
|
+
mongo: async (storageItem) => {
|
|
62
|
+
const result = await this.getModel().create(storageItem);
|
|
63
|
+
return result._id.toString();
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
updateEntityStrategy = {
|
|
67
|
+
postgres: async (id, updateData) => {
|
|
68
|
+
await this.getPostgresDatabase().update(encryptedStorage_1.encryptedStorage).set(updateData).where((0, drizzle_orm_1.eq)(encryptedStorage_1.encryptedStorage.id, id));
|
|
69
|
+
},
|
|
70
|
+
mongo: async (id, updateData) => {
|
|
71
|
+
await this.getModel().findByIdAndUpdate(id, updateData);
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
findEntityStrategy = {
|
|
75
|
+
postgres: async (id) => {
|
|
76
|
+
return await this.getPostgresDatabase()
|
|
77
|
+
.select()
|
|
78
|
+
.from(encryptedStorage_1.encryptedStorage)
|
|
79
|
+
.where((0, drizzle_orm_1.eq)(encryptedStorage_1.encryptedStorage.id, id))
|
|
80
|
+
.then((rows) => rows[0]);
|
|
81
|
+
},
|
|
82
|
+
mongo: async (id, options) => {
|
|
83
|
+
return await this.getModel().findById(id, undefined, options);
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
deleteManyStrategy = {
|
|
87
|
+
postgres: async (ids) => {
|
|
88
|
+
const result = await this.getPostgresDatabase().delete(encryptedStorage_1.encryptedStorage).where((0, drizzle_orm_1.inArray)(encryptedStorage_1.encryptedStorage.id, ids));
|
|
89
|
+
return result.rowCount;
|
|
90
|
+
},
|
|
91
|
+
mongo: async (ids) => {
|
|
92
|
+
const result = await this.getModel().deleteMany({ _id: { $in: ids } });
|
|
93
|
+
return result.deletedCount;
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
removeEntityStrategy = {
|
|
97
|
+
postgres: async (id) => {
|
|
98
|
+
return await this.getPostgresDatabase()
|
|
99
|
+
.delete(encryptedStorage_1.encryptedStorage)
|
|
100
|
+
.where((0, drizzle_orm_1.eq)(encryptedStorage_1.encryptedStorage.id, id))
|
|
101
|
+
.returning()
|
|
102
|
+
.then((rows) => rows[0]);
|
|
103
|
+
},
|
|
104
|
+
mongo: async (id) => {
|
|
105
|
+
return await this.getModel().findOneAndDelete({ _id: id });
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
findExpirationStrategy = {
|
|
109
|
+
postgres: async (id) => {
|
|
110
|
+
return await this.getPostgresDatabase()
|
|
111
|
+
.select({ expiresAt: encryptedStorage_1.encryptedStorage.expiresAt })
|
|
112
|
+
.from(encryptedStorage_1.encryptedStorage)
|
|
113
|
+
.where((0, drizzle_orm_1.eq)(encryptedStorage_1.encryptedStorage.id, id))
|
|
114
|
+
.then((rows) => rows[0].expiresAt);
|
|
115
|
+
},
|
|
116
|
+
mongo: async (id) => {
|
|
117
|
+
const result = await this.getModel().findById(id, { expiresAt: 1 });
|
|
118
|
+
return result?.expiresAt;
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
constructor(logger, auth, envService, databaseAdapter, encryptedStorageModel = null, postgresDatabase = null) {
|
|
15
122
|
this.logger = logger;
|
|
16
123
|
this.auth = auth;
|
|
17
124
|
this.envService = envService;
|
|
125
|
+
this.databaseAdapter = databaseAdapter;
|
|
126
|
+
this.encryptedStorageModel = encryptedStorageModel;
|
|
127
|
+
this.postgresDatabase = postgresDatabase;
|
|
18
128
|
}
|
|
19
129
|
async save(data, expiration) {
|
|
20
130
|
const encryptedData = await this.auth.encryptJWE(utils_1.utils.encodeObjectToBase64(data));
|
|
@@ -25,8 +135,7 @@ class EncryptedStorageService {
|
|
|
25
135
|
if (this.envService.isStage()) {
|
|
26
136
|
storageItem.source = data;
|
|
27
137
|
}
|
|
28
|
-
|
|
29
|
-
return result.id;
|
|
138
|
+
return await this.saveEntityStrategy[this.databaseAdapter](storageItem);
|
|
30
139
|
}
|
|
31
140
|
async get(id, options = {}) {
|
|
32
141
|
const storageItem = await this.getStorageItemById(id, options);
|
|
@@ -49,10 +158,10 @@ class EncryptedStorageService {
|
|
|
49
158
|
if (this.envService.isStage()) {
|
|
50
159
|
storageItem.source = data;
|
|
51
160
|
}
|
|
52
|
-
await
|
|
161
|
+
await this.updateEntityStrategy[this.databaseAdapter](id, storageItem);
|
|
53
162
|
}
|
|
54
163
|
async remove(id) {
|
|
55
|
-
const storageItem = await
|
|
164
|
+
const storageItem = await this.removeEntityStrategy[this.databaseAdapter](id);
|
|
56
165
|
if (!storageItem) {
|
|
57
166
|
this.logger.info('Encrypted data is not removed from storage: data not found', { id });
|
|
58
167
|
return;
|
|
@@ -60,31 +169,43 @@ class EncryptedStorageService {
|
|
|
60
169
|
this.logger.info('Encrypted data removed from storage', { id });
|
|
61
170
|
}
|
|
62
171
|
async deleteMany(ids) {
|
|
63
|
-
const
|
|
172
|
+
const deletedCount = await this.deleteManyStrategy[this.databaseAdapter](ids);
|
|
64
173
|
this.logger.info(`Encrypted data removed from storage: ${deletedCount}`);
|
|
65
174
|
}
|
|
66
175
|
async setExpiration(id, expiration, options = {}) {
|
|
67
176
|
const storageItem = await this.getStorageItemById(id, options);
|
|
68
177
|
storageItem.expiresAt = new Date(Date.now() + expiration);
|
|
69
|
-
await storageItem.
|
|
178
|
+
await this.updateEntityStrategy[this.databaseAdapter](id, { expiresAt: storageItem.expiresAt });
|
|
70
179
|
this.logger.info('Updated encrypted data expiration date', { id });
|
|
71
180
|
}
|
|
72
181
|
async getExpiration(id) {
|
|
73
|
-
const
|
|
74
|
-
if (!
|
|
182
|
+
const expiresAt = await this.findExpirationStrategy[this.databaseAdapter](id);
|
|
183
|
+
if (!expiresAt) {
|
|
75
184
|
this.logger.error('Encrypted data is not found in storage', { id });
|
|
76
185
|
throw new errors_1.NotFoundError('Missing data');
|
|
77
186
|
}
|
|
78
|
-
return
|
|
187
|
+
return expiresAt;
|
|
79
188
|
}
|
|
80
189
|
async getStorageItemById(id, options = {}) {
|
|
81
|
-
const storageItem = await
|
|
190
|
+
const storageItem = await this.findEntityStrategy[this.databaseAdapter](id, options);
|
|
82
191
|
if (!storageItem) {
|
|
83
192
|
this.logger.error('Encrypted data is not found in storage', { id });
|
|
84
193
|
throw new errors_1.NotFoundError('Missing data');
|
|
85
194
|
}
|
|
86
195
|
return storageItem;
|
|
87
196
|
}
|
|
197
|
+
getModel() {
|
|
198
|
+
if (!this.encryptedStorageModel) {
|
|
199
|
+
throw new Error('Encrypted storage model is not provided');
|
|
200
|
+
}
|
|
201
|
+
return this.encryptedStorageModel;
|
|
202
|
+
}
|
|
203
|
+
getPostgresDatabase() {
|
|
204
|
+
if (!this.postgresDatabase) {
|
|
205
|
+
throw new Error('Postgres database is not provided');
|
|
206
|
+
}
|
|
207
|
+
return this.postgresDatabase;
|
|
208
|
+
}
|
|
88
209
|
}
|
|
89
210
|
exports.EncryptedStorageService = EncryptedStorageService;
|
|
90
211
|
//# sourceMappingURL=encryptedStorage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encryptedStorage.js","sourceRoot":"","sources":["../../src/services/encryptedStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"encryptedStorage.js","sourceRoot":"","sources":["../../src/services/encryptedStorage.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AAKzC,iDAAoD;AAEpD,+CAA2C;AAI3C,iEAA6D;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAa,uBAAuB;IAwFX;IACA;IACA;IACA;IACA;IACA;IA5FJ,kBAAkB,GAAoF;QACnH,QAAQ,EAAE,KAAK,EAAE,WAA6B,EAAmB,EAAE;YAC/D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,mBAAmB,EAAE;iBAC1C,MAAM,CAAC,mCAAgB,CAAC;iBACxB,MAAM,CAAC,WAAW,CAAC;iBACnB,SAAS,EAAE;iBACX,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;YAE5B,OAAO,MAAM,CAAC,EAAE,CAAA;QACpB,CAAC;QACD,KAAK,EAAE,KAAK,EAAE,WAA6B,EAAmB,EAAE;YAC5D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;YAExD,OAAO,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAA;QAChC,CAAC;KACJ,CAAA;IAEgB,oBAAoB,GAGjC;QACA,QAAQ,EAAE,KAAK,EAAE,EAAU,EAAE,UAAqC,EAAiB,EAAE;YACjF,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC,MAAM,CAAC,mCAAgB,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC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EpF,IAAI,CAAC,WAAW,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wCAAwC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;YACnE,MAAM,IAAI,sBAAa,CAAC,cAAc,CAAC,CAAA;QAC3C,CAAC;QAED,OAAO,WAAW,CAAA;IACtB,CAAC;IAEO,QAAQ;QACZ,IAAI,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;QAC9D,CAAC;QAED,OAAO,IAAI,CAAC,qBAAqB,CAAA;IACrC,CAAC;IAEO,mBAAmB;QACvB,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;QACxD,CAAC;QAED,OAAO,IAAI,CAAC,gBAAgB,CAAA;IAChC,CAAC;CACJ;AA9MD,0DA8MC"}
|
package/dist/services/index.js
CHANGED
|
@@ -15,5 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./database"), exports);
|
|
18
|
+
__exportStar(require("./postgresDatabase"), exports);
|
|
18
19
|
__exportStar(require("./encryptedStorage"), exports);
|
|
20
|
+
__exportStar(require("./counter"), exports);
|
|
19
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA0B;AAE1B,qDAAkC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA0B;AAE1B,qDAAkC;AAElC,qDAAkC;AAElC,4CAAyB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PostgresDatabaseService = void 0;
|
|
4
|
+
const errors_1 = require("@diia-inhouse/errors");
|
|
5
|
+
class PostgresDatabaseService {
|
|
6
|
+
databaseAdapter;
|
|
7
|
+
postgresDatabase;
|
|
8
|
+
constructor(databaseAdapter, postgresDatabase) {
|
|
9
|
+
this.databaseAdapter = databaseAdapter;
|
|
10
|
+
this.postgresDatabase = postgresDatabase;
|
|
11
|
+
}
|
|
12
|
+
async onInit() {
|
|
13
|
+
if (this.databaseAdapter !== 'postgres') {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
await this.postgresDatabase.execute('SELECT 1');
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
throw new errors_1.DatabaseError('Failed to connect to postgres database', { err });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.PostgresDatabaseService = PostgresDatabaseService;
|
|
25
|
+
//# sourceMappingURL=postgresDatabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgresDatabase.js","sourceRoot":"","sources":["../../src/services/postgresDatabase.ts"],"names":[],"mappings":";;;AAAA,iDAAoD;AAKpD,MAAa,uBAAuB;IAEX;IACA;IAFrB,YACqB,eAAoC,EACpC,gBAAkC;QADlC,oBAAe,GAAf,eAAe,CAAqB;QACpC,qBAAgB,GAAhB,gBAAgB,CAAkB;IACpD,CAAC;IAEJ,KAAK,CAAC,MAAM;QACR,IAAI,IAAI,CAAC,eAAe,KAAK,UAAU,EAAE,CAAC;YACtC,OAAM;QACV,CAAC;QAED,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;QACnD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,IAAI,sBAAa,CAAC,wCAAwC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAA;QAC9E,CAAC;IACL,CAAC;CACJ;AAjBD,0DAiBC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.counter = void 0;
|
|
4
|
+
const pg_core_1 = require("drizzle-orm/pg-core");
|
|
5
|
+
const postgresUtils_1 = require("../postgresUtils");
|
|
6
|
+
exports.counter = (0, pg_core_1.pgTable)('counter', {
|
|
7
|
+
code: (0, pg_core_1.varchar)().notNull(),
|
|
8
|
+
value: (0, pg_core_1.integer)().notNull(),
|
|
9
|
+
date: (0, pg_core_1.timestamp)().notNull(),
|
|
10
|
+
...postgresUtils_1.timestamps,
|
|
11
|
+
}, (table) => [(0, pg_core_1.unique)('counter_code_date_idx').on(table.code, table.date)]);
|
|
12
|
+
//# sourceMappingURL=counter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"counter.js","sourceRoot":"","sources":["../../src/tables/counter.ts"],"names":[],"mappings":";;;AAAA,iDAAkF;AAElF,oDAA6C;AAEhC,QAAA,OAAO,GAAG,IAAA,iBAAO,EAC1B,SAAS,EACT;IACI,IAAI,EAAE,IAAA,iBAAO,GAAE,CAAC,OAAO,EAAE;IACzB,KAAK,EAAE,IAAA,iBAAO,GAAE,CAAC,OAAO,EAAE;IAC1B,IAAI,EAAE,IAAA,mBAAS,GAAE,CAAC,OAAO,EAAE;IAC3B,GAAG,0BAAU;CAChB,EACD,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,IAAA,gBAAM,EAAC,uBAAuB,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAC1E,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encryptedStorage = void 0;
|
|
4
|
+
const pg_core_1 = require("drizzle-orm/pg-core");
|
|
5
|
+
const types_1 = require("@diia-inhouse/types");
|
|
6
|
+
const postgresUtils_1 = require("../postgresUtils");
|
|
7
|
+
exports.encryptedStorage = (0, pg_core_1.pgTable)('encrypted_storage', {
|
|
8
|
+
id: (0, pg_core_1.uuid)('id').primaryKey().defaultRandom(),
|
|
9
|
+
data: (0, pg_core_1.text)('data').notNull(),
|
|
10
|
+
expiresAt: (0, postgresUtils_1.expiringTimestamp)('expires_at', { expireAfterSeconds: types_1.DurationS.Day }).notNull(),
|
|
11
|
+
source: (0, pg_core_1.jsonb)('source'),
|
|
12
|
+
...postgresUtils_1.timestamps,
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=encryptedStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryptedStorage.js","sourceRoot":"","sources":["../../src/tables/encryptedStorage.ts"],"names":[],"mappings":";;;AAAA,iDAAgE;AAEhE,+CAA+C;AAE/C,oDAAgE;AAEnD,QAAA,gBAAgB,GAAG,IAAA,iBAAO,EAAC,mBAAmB,EAAE;IACzD,EAAE,EAAE,IAAA,cAAI,EAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC,aAAa,EAAE;IAC3C,IAAI,EAAE,IAAA,cAAI,EAAC,MAAM,CAAC,CAAC,OAAO,EAAE;IAC5B,SAAS,EAAE,IAAA,iCAAiB,EAAC,YAAY,EAAE,EAAE,kBAAkB,EAAE,iBAAS,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE;IAC3F,MAAM,EAAE,IAAA,eAAK,EAAC,QAAQ,CAAC;IACvB,GAAG,0BAAU;CAChB,CAAC,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./counter"), exports);
|
|
18
|
+
__exportStar(require("./encryptedStorage"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tables/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAyB;AAEzB,qDAAkC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Logger } from '@diia-inhouse/types';
|
|
2
|
+
export declare class CleanupExpiredDataCommand {
|
|
3
|
+
private readonly logger;
|
|
4
|
+
constructor(logger: Logger);
|
|
5
|
+
run(filePath: string): Promise<void>;
|
|
6
|
+
private loadSchema;
|
|
7
|
+
private createDbConnection;
|
|
8
|
+
private cleanupTables;
|
|
9
|
+
private findExpiringTables;
|
|
10
|
+
private isExpiringColumn;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Logger } from '@diia-inhouse/types';
|
|
2
|
+
import { mongo } from '../interfaces';
|
|
3
|
+
export declare class RunMigrationCommand {
|
|
4
|
+
private readonly logger;
|
|
5
|
+
private readonly db;
|
|
6
|
+
private readonly client;
|
|
7
|
+
private readonly changelogCollectionName;
|
|
8
|
+
constructor(logger: Logger, db: mongo.Db, client: mongo.MongoClient);
|
|
9
|
+
run(filePath: string, execDown?: boolean): Promise<void>;
|
|
10
|
+
private updateChangeLog;
|
|
11
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
2
|
+
import * as schema from '../tables';
|
|
3
|
+
export type DatabaseAdapterType = 'mongo' | 'postgres';
|
|
4
|
+
export type DerivedRepository<TRepository> = {
|
|
5
|
+
[K in keyof TRepository]: TRepository[K] extends (...args: any[]) => any ? TRepository[K] : never;
|
|
6
|
+
};
|
|
7
|
+
export type PostgresDatabase = NodePgDatabase<typeof schema>;
|
|
8
|
+
export type DatabaseAdapter<T extends DatabaseAdapterType, Repositories extends Record<DatabaseAdapterType, unknown>> = Repositories[T];
|
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
-
/// <reference types="mongoose/types/callback" />
|
|
3
|
-
/// <reference types="mongoose/types/collection" />
|
|
4
|
-
/// <reference types="mongoose/types/connection" />
|
|
5
|
-
/// <reference types="mongoose/types/cursor" />
|
|
6
|
-
/// <reference types="mongoose/types/document" />
|
|
7
|
-
/// <reference types="mongoose/types/error" />
|
|
8
|
-
/// <reference types="mongoose/types/expressions" />
|
|
9
|
-
/// <reference types="mongoose/types/helpers" />
|
|
10
|
-
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
-
/// <reference types="mongoose/types/indexes" />
|
|
12
|
-
/// <reference types="mongoose/types/models" />
|
|
13
|
-
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
-
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
-
/// <reference types="mongoose/types/populate" />
|
|
16
|
-
/// <reference types="mongoose/types/query" />
|
|
17
|
-
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
-
/// <reference types="mongoose/types/schematypes" />
|
|
19
|
-
/// <reference types="mongoose/types/session" />
|
|
20
|
-
/// <reference types="mongoose/types/types" />
|
|
21
|
-
/// <reference types="mongoose/types/utility" />
|
|
22
|
-
/// <reference types="mongoose/types/validation" />
|
|
23
|
-
/// <reference types="mongoose/types/virtuals" />
|
|
24
|
-
/// <reference types="mongoose/types/inferschematype" />
|
|
25
1
|
import mongoose, { mongo } from 'mongoose';
|
|
26
2
|
export interface ReplicaSetNodeConfig {
|
|
27
3
|
replicaHost: string;
|
|
@@ -34,18 +10,21 @@ export interface AppDbConfig {
|
|
|
34
10
|
isEnabled?: boolean;
|
|
35
11
|
user?: string;
|
|
36
12
|
password?: string;
|
|
37
|
-
database
|
|
13
|
+
database: string;
|
|
38
14
|
authSource?: string;
|
|
39
15
|
host?: string;
|
|
40
16
|
port?: number;
|
|
41
17
|
replicaSet?: string;
|
|
42
18
|
replicaSetNodes?: ReplicaSetNodeConfig[];
|
|
43
19
|
readPreference?: string;
|
|
44
|
-
indexes?: {
|
|
45
|
-
sync: boolean;
|
|
46
|
-
exitAfterSync: boolean;
|
|
47
|
-
};
|
|
48
20
|
authMechanism?: mongo.AuthMechanism;
|
|
21
|
+
metrics: {
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
buckets?: number[];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export interface PostgresDbConfig {
|
|
27
|
+
url: string;
|
|
49
28
|
}
|
|
50
29
|
export interface AppDb {
|
|
51
30
|
connection: mongoose.Connection;
|
|
@@ -32,5 +32,9 @@ export declare enum MongoDBErrorCode {
|
|
|
32
32
|
UnknownError = 8,
|
|
33
33
|
UnsupportedFormat = 12,
|
|
34
34
|
UserNotFound = 11,
|
|
35
|
-
WriteConcernError = 64
|
|
35
|
+
WriteConcernError = 64,
|
|
36
|
+
WriteConflict = 112
|
|
36
37
|
}
|
|
38
|
+
export declare const PostgresErrorCode: {
|
|
39
|
+
readonly InvalidCredentials: "28P01";
|
|
40
|
+
};
|
|
@@ -1,30 +1,8 @@
|
|
|
1
|
-
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
-
/// <reference types="mongoose/types/callback" />
|
|
3
|
-
/// <reference types="mongoose/types/collection" />
|
|
4
|
-
/// <reference types="mongoose/types/connection" />
|
|
5
|
-
/// <reference types="mongoose/types/cursor" />
|
|
6
|
-
/// <reference types="mongoose/types/document" />
|
|
7
|
-
/// <reference types="mongoose/types/error" />
|
|
8
|
-
/// <reference types="mongoose/types/expressions" />
|
|
9
|
-
/// <reference types="mongoose/types/helpers" />
|
|
10
|
-
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
-
/// <reference types="mongoose/types/indexes" />
|
|
12
|
-
/// <reference types="mongoose/types/models" />
|
|
13
|
-
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
-
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
-
/// <reference types="mongoose/types/populate" />
|
|
16
|
-
/// <reference types="mongoose/types/query" />
|
|
17
|
-
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
-
/// <reference types="mongoose/types/schematypes" />
|
|
19
|
-
/// <reference types="mongoose/types/session" />
|
|
20
|
-
/// <reference types="mongoose/types/types" />
|
|
21
|
-
/// <reference types="mongoose/types/utility" />
|
|
22
|
-
/// <reference types="mongoose/types/validation" />
|
|
23
|
-
/// <reference types="mongoose/types/virtuals" />
|
|
24
|
-
/// <reference types="mongoose" />
|
|
25
|
-
/// <reference types="mongoose/types/inferschematype" />
|
|
26
1
|
export * from 'mongoose';
|
|
2
|
+
export * from './database';
|
|
27
3
|
export * from './dbConfig';
|
|
28
4
|
export * from './errors';
|
|
29
5
|
export * from './migrateMongoConfig';
|
|
30
6
|
export * from './mongoStatus';
|
|
7
|
+
export * from './metrics';
|
|
8
|
+
export * from './models';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare enum MongodbOperationResult {
|
|
2
|
+
Successful = "successful",
|
|
3
|
+
Failed = "failed"
|
|
4
|
+
}
|
|
5
|
+
export interface DbOpLogEntry {
|
|
6
|
+
database: string;
|
|
7
|
+
collection?: string;
|
|
8
|
+
opType: string;
|
|
9
|
+
}
|
|
10
|
+
export type DbOpLog = Record<string, DbOpLogEntry>;
|
|
11
|
+
declare class MongodbOperationsLabelsMapConcrete {
|
|
12
|
+
operation: string;
|
|
13
|
+
status: MongodbOperationResult;
|
|
14
|
+
database: string;
|
|
15
|
+
collection: string;
|
|
16
|
+
}
|
|
17
|
+
export type MongodbOperationsLabelsMap = MongodbOperationsLabelsMapConcrete;
|
|
18
|
+
export declare const mongodbOperationsAllowedFields: (keyof MongodbOperationsLabelsMap)[];
|
|
19
|
+
export declare const mongodbOperationsDefaultBuckets: number[];
|
|
20
|
+
export {};
|
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
-
/// <reference types="mongoose/types/callback" />
|
|
3
|
-
/// <reference types="mongoose/types/collection" />
|
|
4
|
-
/// <reference types="mongoose/types/connection" />
|
|
5
|
-
/// <reference types="mongoose/types/cursor" />
|
|
6
|
-
/// <reference types="mongoose/types/document" />
|
|
7
|
-
/// <reference types="mongoose/types/error" />
|
|
8
|
-
/// <reference types="mongoose/types/expressions" />
|
|
9
|
-
/// <reference types="mongoose/types/helpers" />
|
|
10
|
-
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
-
/// <reference types="mongoose/types/indexes" />
|
|
12
|
-
/// <reference types="mongoose/types/models" />
|
|
13
|
-
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
-
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
-
/// <reference types="mongoose/types/populate" />
|
|
16
|
-
/// <reference types="mongoose/types/query" />
|
|
17
|
-
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
-
/// <reference types="mongoose/types/schematypes" />
|
|
19
|
-
/// <reference types="mongoose/types/session" />
|
|
20
|
-
/// <reference types="mongoose/types/types" />
|
|
21
|
-
/// <reference types="mongoose/types/utility" />
|
|
22
|
-
/// <reference types="mongoose/types/validation" />
|
|
23
|
-
/// <reference types="mongoose/types/virtuals" />
|
|
24
|
-
/// <reference types="mongoose/types/inferschematype" />
|
|
25
1
|
import { mongo } from 'mongoose';
|
|
26
2
|
export interface MigrateMongoConfig {
|
|
27
3
|
mongodb: {
|
|
@@ -1,32 +1,6 @@
|
|
|
1
|
-
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
-
/// <reference types="mongoose/types/callback" />
|
|
3
|
-
/// <reference types="mongoose/types/collection" />
|
|
4
|
-
/// <reference types="mongoose/types/connection" />
|
|
5
|
-
/// <reference types="mongoose/types/cursor" />
|
|
6
|
-
/// <reference types="mongoose/types/document" />
|
|
7
|
-
/// <reference types="mongoose/types/error" />
|
|
8
|
-
/// <reference types="mongoose/types/expressions" />
|
|
9
|
-
/// <reference types="mongoose/types/helpers" />
|
|
10
|
-
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
-
/// <reference types="mongoose/types/indexes" />
|
|
12
|
-
/// <reference types="mongoose/types/models" />
|
|
13
|
-
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
-
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
-
/// <reference types="mongoose/types/populate" />
|
|
16
|
-
/// <reference types="mongoose/types/query" />
|
|
17
|
-
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
-
/// <reference types="mongoose/types/schematypes" />
|
|
19
|
-
/// <reference types="mongoose/types/session" />
|
|
20
|
-
/// <reference types="mongoose/types/types" />
|
|
21
|
-
/// <reference types="mongoose/types/utility" />
|
|
22
|
-
/// <reference types="mongoose/types/validation" />
|
|
23
|
-
/// <reference types="mongoose/types/virtuals" />
|
|
24
|
-
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
-
import { Document } from 'mongoose';
|
|
26
1
|
export interface EncryptedStorage {
|
|
2
|
+
id?: string;
|
|
27
3
|
data: string;
|
|
28
4
|
expiresAt: Date;
|
|
29
5
|
source?: unknown;
|
|
30
6
|
}
|
|
31
|
-
export interface EncryptedStorageModel extends EncryptedStorage, Document {
|
|
32
|
-
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const timestamps: {
|
|
2
|
+
createdAt: import("drizzle-orm").NotNull<import("drizzle-orm", { with: { "resolution-mode": "import" } }).HasDefault<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"created_at">>>;
|
|
3
|
+
updatedAt: import("drizzle-orm").NotNull<import("drizzle-orm").HasDefault<import("drizzle-orm", { with: { "resolution-mode": "import" } }).HasDefault<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"updated_at">>>>;
|
|
4
|
+
};
|
|
5
|
+
export declare const expiringTimestamp: {
|
|
6
|
+
<TConfig extends Record<string, any> & {
|
|
7
|
+
expireAfterSeconds: number;
|
|
8
|
+
}>(fieldConfig: TConfig): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
9
|
+
name: "";
|
|
10
|
+
dataType: "custom";
|
|
11
|
+
columnType: "PgCustomColumn";
|
|
12
|
+
data: Date;
|
|
13
|
+
driverParam: string;
|
|
14
|
+
enumValues: undefined;
|
|
15
|
+
}>;
|
|
16
|
+
<TName extends string>(dbName: TName, fieldConfig: {
|
|
17
|
+
expireAfterSeconds: number;
|
|
18
|
+
}): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
19
|
+
name: TName;
|
|
20
|
+
dataType: "custom";
|
|
21
|
+
columnType: "PgCustomColumn";
|
|
22
|
+
data: Date;
|
|
23
|
+
driverParam: string;
|
|
24
|
+
enumValues: undefined;
|
|
25
|
+
}>;
|
|
26
|
+
};
|