@crowdin/app-project-module 1.0.2 → 1.2.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.
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable no-unused-expressions */
3
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -11,401 +10,312 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
10
  };
12
11
  Object.defineProperty(exports, "__esModule", { value: true });
13
12
  exports.SQLiteStorage = void 0;
14
- const path_1 = require("path");
15
13
  const crypto_1 = require("crypto");
14
+ const path_1 = require("path");
16
15
  const types_1 = require("../modules/integration/util/types");
17
16
  const types_2 = require("../types");
18
17
  class SQLiteStorage {
19
18
  constructor(config) {
20
- this.dbPromise = new Promise((res, rej) => {
21
- this._res = res;
22
- this._rej = rej;
23
- });
19
+ this.db = null;
24
20
  this.tables = {
25
21
  crowdin_credentials: `(
26
- id varchar not null primary key,
27
- app_secret varchar null,
28
- domain varchar null,
29
- user_id varchar null,
30
- agent_id varchar null,
31
- organization_id varchar null,
32
- base_url varchar null,
33
- access_token varchar not null,
34
- refresh_token varchar not null,
35
- expire varchar not null,
36
- type varchar not null
37
- )`,
22
+ id varchar not null primary key,
23
+ app_secret varchar null,
24
+ domain varchar null,
25
+ user_id varchar null,
26
+ agent_id varchar null,
27
+ organization_id varchar null,
28
+ base_url varchar null,
29
+ access_token varchar not null,
30
+ refresh_token varchar not null,
31
+ expire varchar not null,
32
+ type varchar not null
33
+ )`,
38
34
  integration_credentials: `(
39
- id varchar not null primary key,
40
- credentials varchar not null,
41
- crowdin_id varchar not null,
42
- managers varchar null
43
- )`,
35
+ id varchar not null primary key,
36
+ credentials varchar not null,
37
+ crowdin_id varchar not null,
38
+ managers varchar null
39
+ )`,
44
40
  sync_settings: `(
45
- id integer not null primary key autoincrement,
46
- files varchar null,
47
- integration_id varchar not null,
48
- crowdin_id varchar not null,
49
- type varchar not null,
50
- provider varchar not null
51
- )`,
41
+ id integer not null primary key autoincrement,
42
+ files varchar null,
43
+ integration_id varchar not null,
44
+ crowdin_id varchar not null,
45
+ type varchar not null,
46
+ provider varchar not null
47
+ )`,
52
48
  app_metadata: `(
53
- id varchar not null primary key,
54
- data varchar null,
55
- crowdin_id varchar null
56
- )`,
49
+ id varchar not null primary key,
50
+ data varchar null,
51
+ crowdin_id varchar null
52
+ )`,
57
53
  files_snapshot: `(
58
- id integer not null primary key autoincrement,
59
- integration_id varchar not null,
60
- crowdin_id varchar not null,
61
- files varchar null,
62
- provider varchar not null
63
- )`,
54
+ id integer not null primary key autoincrement,
55
+ integration_id varchar not null,
56
+ crowdin_id varchar not null,
57
+ files varchar null,
58
+ provider varchar not null
59
+ )`,
64
60
  webhooks: `(
65
- id integer not null primary key autoincrement,
66
- file_id varchar not null,
67
- integration_id varchar not null,
68
- crowdin_id varchar not null,
69
- provider varchar not null
70
- )`,
61
+ id integer not null primary key autoincrement,
62
+ file_id varchar not null,
63
+ integration_id varchar not null,
64
+ crowdin_id varchar not null,
65
+ provider varchar not null
66
+ )`,
71
67
  user_errors: `(
72
- id integer not null primary key autoincrement,
73
- action varchar not null,
74
- message varchar not null,
75
- data varchar null,
76
- created_at varchar not null,
77
- crowdin_id varchar not null,
78
- integration_id varchar null
79
- )`,
68
+ id integer not null primary key autoincrement,
69
+ action varchar not null,
70
+ message varchar not null,
71
+ data varchar null,
72
+ created_at varchar not null,
73
+ crowdin_id varchar not null,
74
+ integration_id varchar null
75
+ )`,
80
76
  integration_settings: `(
81
- id integer not null primary key autoincrement,
82
- integration_id varchar not null,
83
- crowdin_id varchar not null,
84
- config varchar null
85
- )`,
77
+ id integer not null primary key autoincrement,
78
+ integration_id varchar not null,
79
+ crowdin_id varchar not null,
80
+ config varchar null
81
+ )`,
86
82
  job: `(
87
- id varchar not null primary key,
88
- integration_id varchar not null,
89
- crowdin_id varchar not null,
90
- type varchar not null,
91
- title varchar null,
92
- progress integer DEFAULT 0,
93
- status varchar DEFAULT '${types_1.JobStatus.CREATED}',
94
- payload varchar null,
95
- info varchar null,
96
- data varchar null,
97
- attempt varchar DEFAULT 0,
98
- errors varchar null,
99
- processed_entities varchar null,
100
- created_at varchar not null,
101
- updated_at varchar null,
102
- finished_at varchar null
103
- )`,
83
+ id varchar not null primary key,
84
+ integration_id varchar not null,
85
+ crowdin_id varchar not null,
86
+ type varchar not null,
87
+ title varchar null,
88
+ progress integer DEFAULT 0,
89
+ status varchar DEFAULT '${types_1.JobStatus.CREATED}',
90
+ payload varchar null,
91
+ info varchar null,
92
+ data varchar null,
93
+ attempt varchar DEFAULT 0,
94
+ errors varchar null,
95
+ processed_entities varchar null,
96
+ created_at varchar not null,
97
+ updated_at varchar null,
98
+ finished_at varchar null
99
+ )`,
104
100
  translation_file_cache: `(
105
- id integer not null primary key autoincrement,
106
- integration_id varchar not null,
107
- crowdin_id varchar not null,
108
- file_id integer not null,
109
- language_id varchar not null,
110
- etag varchar
111
- )`,
101
+ id integer not null primary key autoincrement,
102
+ integration_id varchar not null,
103
+ crowdin_id varchar not null,
104
+ file_id integer not null,
105
+ language_id varchar not null,
106
+ etag varchar
107
+ )`,
112
108
  unsynced_files: `(
113
- id integer not null primary key autoincrement,
114
- integration_id varchar not null,
115
- crowdin_id varchar not null,
116
- files varchar null
117
- )`,
109
+ id integer not null primary key autoincrement,
110
+ integration_id varchar not null,
111
+ crowdin_id varchar not null,
112
+ files varchar null
113
+ )`,
118
114
  synced_data: `(
119
- id integer not null primary key autoincrement,
120
- files varchar null,
121
- integration_id varchar not null,
122
- crowdin_id varchar not null,
123
- type varchar not null,
124
- updated_at varchar null
125
- )`,
115
+ id integer not null primary key autoincrement,
116
+ files varchar null,
117
+ integration_id varchar not null,
118
+ crowdin_id varchar not null,
119
+ type varchar not null,
120
+ updated_at varchar null
121
+ )`,
126
122
  };
127
123
  this.config = config;
128
124
  }
129
- _run(query, params) {
130
- return __awaiter(this, void 0, void 0, function* () {
131
- yield new Promise((res, rej) => {
132
- var _a;
133
- //@ts-ignore
134
- (_a = this.db) === null || _a === void 0 ? void 0 : _a.run(query, params, (err) => {
135
- if (err) {
136
- rej(err);
137
- }
138
- else {
139
- res();
140
- }
141
- });
142
- });
143
- });
144
- }
145
- run(query, params) {
146
- return __awaiter(this, void 0, void 0, function* () {
147
- yield this.dbPromise;
148
- yield new Promise((res, rej) => {
149
- var _a;
150
- //@ts-ignore
151
- (_a = this.db) === null || _a === void 0 ? void 0 : _a.run(query, params, (err) => {
152
- if (err) {
153
- rej(err);
154
- }
155
- else {
156
- res();
157
- }
158
- });
159
- });
160
- });
161
- }
162
- get(query, params) {
163
- return __awaiter(this, void 0, void 0, function* () {
164
- yield this.dbPromise;
165
- return new Promise((res, rej) => {
166
- var _a;
167
- //@ts-ignore
168
- (_a = this.db) === null || _a === void 0 ? void 0 : _a.get(query, params, (err, row) => {
169
- if (err) {
170
- rej(err);
171
- }
172
- else {
173
- res(row);
174
- }
175
- });
176
- });
177
- });
178
- }
179
- each(query, params) {
180
- return __awaiter(this, void 0, void 0, function* () {
181
- yield this.dbPromise;
182
- return new Promise((res, rej) => {
183
- var _a;
184
- const result = [];
185
- (_a = this.db) === null || _a === void 0 ? void 0 : _a.each(query, params,
186
- //@ts-ignore
187
- (err, row) => {
188
- if (err) {
189
- rej(err);
190
- }
191
- else {
192
- result.push(row);
193
- }
194
- }, () => res(result));
195
- });
196
- });
197
- }
198
- removeColumns(column, tableName) {
199
- return __awaiter(this, void 0, void 0, function* () {
200
- const tableInfo = yield this.each(`PRAGMA table_info(${tableName});`, []);
201
- const exists = tableInfo.some((columnInfo) => columnInfo.name === column);
202
- if (exists) {
203
- yield this.run(`ALTER TABLE ${tableName} DROP COLUMN ${column};`, []);
204
- }
205
- });
206
- }
207
- addColumns(columns, tableName) {
208
- return __awaiter(this, void 0, void 0, function* () {
209
- const tableInfo = yield this.each(`PRAGMA table_info(${tableName});`, []);
210
- //@ts-ignore
211
- tableInfo.map((columnInfo) => __awaiter(this, void 0, void 0, function* () {
212
- const index = columns.indexOf(columnInfo.name);
213
- if (~index) {
214
- columns.splice(index, 1);
215
- }
216
- }));
217
- for (const column of columns) {
218
- yield this.run(`ALTER TABLE ${tableName} ADD COLUMN ${column} varchar null;`, []);
219
- }
220
- });
221
- }
222
- addColumn(tableName, column, defaultValue) {
223
- return __awaiter(this, void 0, void 0, function* () {
224
- const tableInfo = yield this.each(`PRAGMA table_info(${tableName});`, []);
225
- const exists = tableInfo.some((columnInfo) => columnInfo.name === column);
226
- if (!exists) {
227
- yield this.run(`ALTER TABLE ${tableName} ADD COLUMN ${column} varchar ${defaultValue};`, []);
228
- }
229
- });
230
- }
231
125
  migrate() {
232
126
  return __awaiter(this, void 0, void 0, function* () {
233
- let _connection_res;
234
- let _connection_rej;
235
- const connectionPromise = new Promise((res, rej) => {
236
- _connection_res = res;
237
- _connection_rej = rej;
238
- });
239
- const sqlite = require('sqlite3');
240
- //@ts-ignore
241
- this.db = new sqlite.Database((0, path_1.join)(this.config.dbFolder, types_2.storageFiles.SQLITE), (error) => {
242
- if (error) {
243
- _connection_rej(error);
244
- }
245
- else {
246
- _connection_res();
247
- }
248
- });
127
+ this.db = require('better-sqlite3')((0, path_1.join)(this.config.dbFolder, types_2.storageFiles.SQLITE));
249
128
  try {
250
- yield connectionPromise;
251
- for (const [tableName, tableSchema] of Object.entries(this.tables)) {
252
- yield this._run(`create table if not exists ${tableName} ${tableSchema};`, []);
253
- }
254
- if (this._res) {
255
- this._res();
129
+ for (const [tableName, schema] of Object.entries(this.tables)) {
130
+ this.db.prepare(`CREATE TABLE IF NOT EXISTS ${tableName} ${schema}`).run();
256
131
  }
257
132
  }
258
- catch (e) {
259
- this._rej && this._rej(e);
133
+ catch (error) {
134
+ console.error('Error during database migration:', error);
135
+ throw error;
260
136
  }
261
137
  });
262
138
  }
263
139
  saveCrowdinCredentials(credentials) {
264
- return this.run('INSERT INTO crowdin_credentials(id, app_secret, domain, user_id, agent_id, organization_id, base_url, access_token, refresh_token, expire, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
265
- credentials.id,
266
- credentials.appSecret,
267
- credentials.domain,
268
- credentials.userId,
269
- credentials.agentId,
270
- credentials.organizationId,
271
- credentials.baseUrl,
272
- credentials.accessToken,
273
- credentials.refreshToken,
274
- credentials.expire,
275
- credentials.type,
276
- ]);
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ this.db.prepare(`
142
+ INSERT INTO crowdin_credentials
143
+ (id, app_secret, domain, user_id, agent_id, organization_id, base_url, access_token, refresh_token, expire, type)
144
+ VALUES
145
+ (@id, @appSecret, @domain, @userId, @agentId, @organizationId, @baseUrl, @accessToken, @refreshToken, @expire, @type)
146
+ `).run(credentials);
147
+ });
277
148
  }
278
149
  updateCrowdinCredentials(credentials) {
279
- return this.run('UPDATE crowdin_credentials SET app_secret = ?, domain = ?, user_id = ?, agent_id = ?, organization_id = ?, base_url = ?, access_token = ?, refresh_token = ?, expire = ? WHERE id = ?', [
280
- credentials.appSecret,
281
- credentials.domain,
282
- credentials.userId,
283
- credentials.agentId,
284
- credentials.organizationId,
285
- credentials.baseUrl,
286
- credentials.accessToken,
287
- credentials.refreshToken,
288
- credentials.expire,
289
- credentials.id,
290
- ]);
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ this.db.prepare(`
152
+ UPDATE crowdin_credentials
153
+ SET
154
+ app_secret = @appSecret,
155
+ domain = @domain,
156
+ user_id = @userId,
157
+ agent_id = @agentId,
158
+ organization_id = @organizationId,
159
+ base_url = @baseUrl,
160
+ access_token = @accessToken,
161
+ refresh_token = @refreshToken,
162
+ expire = @expire,
163
+ type = @type
164
+ WHERE id = @id
165
+ `).run(credentials);
166
+ });
291
167
  }
292
168
  getCrowdinCredentials(id) {
293
169
  return __awaiter(this, void 0, void 0, function* () {
294
- const row = yield this.get('SELECT id, app_secret as appSecret, domain, user_id as userId, agent_id as agentId, organization_id as organizationId, base_url as baseUrl, access_token as accessToken, refresh_token as refreshToken, expire, type FROM crowdin_credentials WHERE id = ?', [id]);
295
- if (row) {
296
- return row;
297
- }
170
+ return this.db.prepare(`
171
+ SELECT id, app_secret as appSecret, domain, user_id as userId, agent_id as agentId, organization_id as organizationId, base_url as baseUrl, access_token as accessToken, refresh_token as refreshToken, expire, type
172
+ FROM crowdin_credentials
173
+ WHERE id = ?
174
+ `).get(id);
298
175
  });
299
176
  }
300
177
  getAllCrowdinCredentials() {
301
- return this.each('SELECT id, app_secret as appSecret, domain, user_id as userId, agent_id as agentId, organization_id as organizationId, base_url as baseUrl, access_token as accessToken, refresh_token as refreshToken, expire, type FROM crowdin_credentials', []);
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ return this.db.prepare(`
180
+ SELECT id, app_secret as appSecret, domain, user_id as userId, agent_id as agentId, organization_id as organizationId, base_url as baseUrl, access_token as accessToken, refresh_token as refreshToken, expire, type
181
+ FROM crowdin_credentials
182
+ `).all();
183
+ });
302
184
  }
303
185
  deleteCrowdinCredentials(id) {
304
186
  return __awaiter(this, void 0, void 0, function* () {
305
- yield this.run('DELETE FROM crowdin_credentials where id = ?', [id]);
306
- yield this.run('DELETE FROM integration_credentials where crowdin_id = ?', [id]);
307
- yield this.run('DELETE FROM sync_settings WHERE crowdin_id = ?', [id]);
308
- yield this.run('DELETE FROM app_metadata WHERE crowdin_id = ?', [id]);
309
- yield this.run('DELETE FROM files_snapshot WHERE crowdin_id = ?', [id]);
310
- yield this.run('DELETE FROM webhooks WHERE crowdin_id = ?', [id]);
311
- yield this.run('DELETE FROM user_errors WHERE crowdin_id = ?', [id]);
312
- yield this.run('DELETE FROM integration_settings WHERE crowdin_id = ?', [id]);
313
- yield this.run('DELETE FROM job WHERE crowdin_id = ?', [id]);
314
- yield this.run('DELETE FROM translation_file_cache WHERE crowdin_id = ?', [id]);
315
- yield this.run('DELETE FROM unsynced_files WHERE crowdin_id = ?', [id]);
316
- yield this.run('DELETE FROM synced_data WHERE crowdin_id = ?', [id]);
187
+ this.db.prepare('DELETE FROM crowdin_credentials where id = ?').run(id);
188
+ this.db.prepare('DELETE FROM integration_credentials where crowdin_id = ?').run(id);
189
+ this.db.prepare('DELETE FROM sync_settings WHERE crowdin_id = ?').run(id);
190
+ this.db.prepare('DELETE FROM app_metadata WHERE crowdin_id = ?').run(id);
191
+ this.db.prepare('DELETE FROM files_snapshot WHERE crowdin_id = ?').run(id);
192
+ this.db.prepare('DELETE FROM webhooks WHERE crowdin_id = ?').run(id);
193
+ this.db.prepare('DELETE FROM user_errors WHERE crowdin_id = ?').run(id);
194
+ this.db.prepare('DELETE FROM integration_settings WHERE crowdin_id = ?').run(id);
195
+ this.db.prepare('DELETE FROM job WHERE crowdin_id = ?').run(id);
196
+ this.db.prepare('DELETE FROM translation_file_cache WHERE crowdin_id = ?').run(id);
197
+ this.db.prepare('DELETE FROM unsynced_files WHERE crowdin_id = ?').run(id);
198
+ this.db.prepare('DELETE FROM synced_data WHERE crowdin_id = ?').run(id);
317
199
  });
318
200
  }
319
201
  saveIntegrationCredentials(id, credentials, crowdinId) {
320
- return this.run('INSERT INTO integration_credentials(id, credentials, crowdin_id) VALUES (?, ?, ?)', [
321
- id,
322
- credentials,
323
- crowdinId,
324
- ]);
202
+ return __awaiter(this, void 0, void 0, function* () {
203
+ this.db.prepare(`
204
+ INSERT INTO integration_credentials
205
+ (id, credentials, crowdin_id)
206
+ VALUES
207
+ (@id, @credentials, @crowdinId)
208
+ `).run({ id, credentials, crowdinId });
209
+ });
325
210
  }
326
211
  updateIntegrationCredentials(id, credentials) {
327
- return this.run('UPDATE integration_credentials SET credentials = ? WHERE id = ?', [credentials, id]);
212
+ return __awaiter(this, void 0, void 0, function* () {
213
+ this.db.prepare(`
214
+ UPDATE integration_credentials
215
+ SET credentials = @credentials
216
+ WHERE id = @id
217
+ `).run({ id, credentials });
218
+ });
328
219
  }
329
220
  updateIntegrationManagers(id, managers) {
330
- return this.run('UPDATE integration_credentials SET managers = ? WHERE id = ?', [managers, id]);
221
+ return __awaiter(this, void 0, void 0, function* () {
222
+ this.db.prepare(`
223
+ UPDATE integration_credentials
224
+ SET managers = @managers
225
+ WHERE id = @id
226
+ `).run({ id, managers });
227
+ });
331
228
  }
332
229
  getIntegrationCredentials(id) {
333
230
  return __awaiter(this, void 0, void 0, function* () {
334
- const row = yield this.get('SELECT id, credentials, crowdin_id as crowdinId, managers FROM integration_credentials WHERE id = ?', [id]);
335
- if (row) {
336
- return row;
337
- }
231
+ return this.db.prepare(`
232
+ SELECT id, credentials, crowdin_id as crowdinId, managers
233
+ FROM integration_credentials
234
+ WHERE id = ?
235
+ `).get(id);
338
236
  });
339
237
  }
340
238
  getAllIntegrationCredentials(crowdinId) {
341
- return this.each('SELECT id, credentials, crowdin_id as crowdinId, managers FROM integration_credentials WHERE crowdin_id = ?', [crowdinId]);
239
+ return __awaiter(this, void 0, void 0, function* () {
240
+ return this.db.prepare(`
241
+ SELECT id, credentials, crowdin_id as crowdinId, managers
242
+ FROM integration_credentials
243
+ WHERE crowdin_id = ?`).all(crowdinId);
244
+ });
342
245
  }
343
246
  deleteIntegrationCredentials(id) {
344
247
  return __awaiter(this, void 0, void 0, function* () {
345
- yield this.run('DELETE FROM integration_credentials where id = ?', [id]);
346
- yield this.run('DELETE FROM sync_settings where integration_id = ?', [id]);
347
- yield this.run('DELETE FROM files_snapshot where integration_id = ?', [id]);
348
- yield this.run('DELETE FROM webhooks where integration_id = ?', [id]);
349
- yield this.run('DELETE FROM user_errors where integration_id = ?', [id]);
350
- yield this.run('DELETE FROM integration_settings where integration_id = ?', [id]);
351
- yield this.run('DELETE FROM job where integration_id = ?', [id]);
352
- yield this.run('DELETE FROM translation_file_cache where integration_id = ?', [id]);
353
- yield this.run('DELETE FROM unsynced_files where integration_id = ?', [id]);
354
- yield this.run('DELETE FROM synced_data where integration_id = ?', [id]);
248
+ this.db.prepare('DELETE FROM integration_credentials where id = ?').run(id);
249
+ this.db.prepare('DELETE FROM sync_settings where integration_id = ?').run(id);
250
+ this.db.prepare('DELETE FROM files_snapshot where integration_id = ?').run(id);
251
+ this.db.prepare('DELETE FROM webhooks where integration_id = ?').run(id);
252
+ this.db.prepare('DELETE FROM user_errors where integration_id = ?').run(id);
253
+ this.db.prepare('DELETE FROM integration_settings where integration_id = ?').run(id);
254
+ this.db.prepare('DELETE FROM job where integration_id = ?').run(id);
255
+ this.db.prepare('DELETE FROM translation_file_cache where integration_id = ?').run(id);
256
+ this.db.prepare('DELETE FROM unsynced_files where integration_id = ?').run(id);
257
+ this.db.prepare('DELETE FROM synced_data where integration_id = ?').run(id);
355
258
  });
356
259
  }
357
260
  deleteAllIntegrationCredentials(crowdinId) {
358
261
  return __awaiter(this, void 0, void 0, function* () {
359
- yield this.run('DELETE FROM integration_credentials where crowdin_id = ?', [crowdinId]);
360
- yield this.run('DELETE FROM sync_settings where crowdin_id = ?', [crowdinId]);
361
- yield this.run('DELETE FROM files_snapshot where crowdin_id = ?', [crowdinId]);
362
- yield this.run('DELETE FROM webhooks where crowdin_id = ?', [crowdinId]);
363
- yield this.run('DELETE FROM user_errors where crowdin_id = ?', [crowdinId]);
364
- yield this.run('DELETE FROM job where crowdin_id = ?', [crowdinId]);
365
- yield this.run('DELETE FROM unsynced_files where crowdin_id = ?', [crowdinId]);
366
- yield this.run('DELETE FROM synced_data where crowdin_id = ?', [crowdinId]);
262
+ this.db.prepare('DELETE FROM integration_credentials where crowdin_id = ?').run(crowdinId);
263
+ this.db.prepare('DELETE FROM sync_settings where crowdin_id = ?').run(crowdinId);
264
+ this.db.prepare('DELETE FROM files_snapshot where crowdin_id = ?').run(crowdinId);
265
+ this.db.prepare('DELETE FROM webhooks where crowdin_id = ?').run(crowdinId);
266
+ this.db.prepare('DELETE FROM user_errors where crowdin_id = ?').run(crowdinId);
267
+ this.db.prepare('DELETE FROM job where crowdin_id = ?').run(crowdinId);
268
+ this.db.prepare('DELETE FROM unsynced_files where crowdin_id = ?').run(crowdinId);
269
+ this.db.prepare('DELETE FROM synced_data where crowdin_id = ?').run(crowdinId);
367
270
  });
368
271
  }
369
272
  saveMetadata(id, metadata, crowdinId) {
370
- return this.run('INSERT INTO app_metadata(id, data, crowdin_id) VALUES (?, ?, ?)', [
371
- id,
372
- JSON.stringify(metadata),
373
- crowdinId,
374
- ]);
273
+ return __awaiter(this, void 0, void 0, function* () {
274
+ this.db.prepare(`
275
+ INSERT INTO app_metadata
276
+ (id, data, crowdin_id)
277
+ VALUES
278
+ (@id, @data, @crowdinId)
279
+ `).run({ id, data: JSON.stringify(metadata), crowdinId });
280
+ });
375
281
  }
376
282
  updateMetadata(id, metadata, crowdinId) {
377
- return this.run('UPDATE app_metadata SET data = ?, crowdin_id = ? WHERE id = ?', [
378
- JSON.stringify(metadata),
379
- crowdinId,
380
- id,
381
- ]);
283
+ return __awaiter(this, void 0, void 0, function* () {
284
+ this.db.prepare(`
285
+ UPDATE app_metadata
286
+ SET data = @data
287
+ WHERE id = @id AND crowdin_id = @crowdinId
288
+ `).run({ id, data: JSON.stringify(metadata), crowdinId });
289
+ });
382
290
  }
383
291
  getMetadata(id) {
384
292
  return __awaiter(this, void 0, void 0, function* () {
385
- const row = yield this.get('SELECT data FROM app_metadata WHERE id = ?', [id]);
386
- if (row) {
387
- return JSON.parse(row.data);
388
- }
293
+ const row = this.db.prepare('SELECT data FROM app_metadata WHERE id = ?').get(id);
294
+ return row ? JSON.parse(row.data) : undefined;
389
295
  });
390
296
  }
391
297
  getAllMetadata() {
392
- return this.each('SELECT * FROM app_metadata', []);
298
+ return __awaiter(this, void 0, void 0, function* () {
299
+ return this.db.prepare('SELECT * FROM app_metadata').all();
300
+ });
393
301
  }
394
302
  deleteMetadata(id) {
395
303
  return __awaiter(this, void 0, void 0, function* () {
396
- yield this.run('DELETE FROM app_metadata where id = ?', [id]);
304
+ this.db.prepare('DELETE FROM app_metadata WHERE id = ?').run(id);
397
305
  });
398
306
  }
399
307
  getSyncSettingsByProvider(integrationId, provider) {
400
308
  return __awaiter(this, void 0, void 0, function* () {
401
- const row = yield this.get('SELECT id, files, integration_id as integrationId, crowdin_id as crowdinId, type, provider FROM sync_settings WHERE integration_id = ? AND provider = ?', [integrationId, provider]);
402
- if (row) {
403
- return row;
404
- }
309
+ return this.db.prepare(`
310
+ SELECT id, files, integration_id as integrationId, crowdin_id as crowdinId, type, provider
311
+ FROM sync_settings
312
+ WHERE integration_id = ? AND provider = ?
313
+ `).get(integrationId, provider);
405
314
  });
406
315
  }
407
316
  getSyncSettingsBySchedule(type, schedule) {
408
- return this.each(`
317
+ return __awaiter(this, void 0, void 0, function* () {
318
+ return this.db.prepare(`
409
319
  SELECT s.id, s.files, s.integration_id as integrationId, s.crowdin_id as crowdinId, s.type, s.provider
410
320
  FROM sync_settings s
411
321
  INNER JOIN integration_settings i ON s.integration_id = i.integration_id
@@ -414,307 +324,377 @@ class SQLiteStorage {
414
324
  WHEN i.config IS NULL THEN 0
415
325
  ELSE json_extract(i.config, '$.schedule') = ?
416
326
  END
417
- `, [type, schedule]);
327
+ `).all(type, schedule);
328
+ });
418
329
  }
419
330
  saveSyncSettings(files, integrationId, crowdinId, type, provider) {
420
- return this.run('INSERT INTO sync_settings(files, integration_id, crowdin_id, type, provider) VALUES (?, ?, ?, ?, ?)', [files, integrationId, crowdinId, type, provider]);
331
+ return __awaiter(this, void 0, void 0, function* () {
332
+ this.db.prepare(`
333
+ INSERT INTO sync_settings
334
+ (files, integration_id, crowdin_id, type, provider)
335
+ VALUES
336
+ (@files, @integrationId, @crowdinId, @type, @provider)
337
+ `).run({ files, integrationId, crowdinId, type, provider });
338
+ });
421
339
  }
422
340
  updateSyncSettings(files, integrationId, crowdinId, type, provider) {
423
- return this.run('UPDATE sync_settings SET files = ? WHERE integration_id = ? AND crowdin_id = ? AND type = ? AND provider = ?', [files, integrationId, crowdinId, type, provider]);
341
+ return __awaiter(this, void 0, void 0, function* () {
342
+ this.db.prepare(`
343
+ UPDATE sync_settings
344
+ SET files = @files
345
+ WHERE integration_id = @integrationId AND crowdin_id = @crowdinId AND type = @type AND provider = @provider
346
+ `).run({ files, integrationId, crowdinId, type, provider });
347
+ });
424
348
  }
425
349
  getSyncSettings(integrationId, crowdinId, type, provider) {
426
350
  return __awaiter(this, void 0, void 0, function* () {
427
- const row = yield this.get('SELECT id, files, integration_id as integrationId, crowdin_id as crowdinId, type, provider FROM sync_settings WHERE integration_id = ? AND crowdin_id = ? AND type = ? AND provider = ?', [integrationId, crowdinId, type, provider]);
428
- if (row) {
429
- return row;
430
- }
351
+ return this.db.prepare(`
352
+ SELECT id, files, integration_id as integrationId, crowdin_id as crowdinId, type, provider
353
+ FROM sync_settings
354
+ WHERE integration_id = ? AND crowdin_id = ? AND type = ? AND provider = ?
355
+ `).get(integrationId, crowdinId, type, provider);
431
356
  });
432
357
  }
433
358
  saveFilesSnapshot(files, integrationId, crowdinId, provider) {
434
- return this.run('INSERT INTO files_snapshot(files, integration_id, crowdin_id, provider) VALUES (?, ?, ?, ?)', [
435
- files,
436
- integrationId,
437
- crowdinId,
438
- provider,
439
- ]);
359
+ return __awaiter(this, void 0, void 0, function* () {
360
+ this.db.prepare(`
361
+ INSERT INTO files_snapshot
362
+ (files, integration_id, crowdin_id, provider)
363
+ VALUES
364
+ (@files, @integrationId, @crowdinId, @provider)
365
+ `).run({ files, integrationId, crowdinId, provider });
366
+ });
440
367
  }
441
368
  updateFilesSnapshot(files, integrationId, crowdinId, provider) {
442
- return this.run('UPDATE files_snapshot SET files = ? WHERE integration_id = ? AND crowdin_id = ? AND provider = ? ', [files, integrationId, crowdinId, provider]);
369
+ return __awaiter(this, void 0, void 0, function* () {
370
+ this.db.prepare(`
371
+ UPDATE files_snapshot
372
+ SET files = @files
373
+ WHERE integration_id = @integrationId AND crowdin_id = @crowdinId AND provider = @provider
374
+ `).run({ files, integrationId, crowdinId, provider });
375
+ });
443
376
  }
444
377
  getFilesSnapshot(integrationId, crowdinId, provider) {
445
378
  return __awaiter(this, void 0, void 0, function* () {
446
- const row = yield this.get('SELECT id, files, integration_id as integrationId, crowdin_id as crowdinId, provider FROM files_snapshot WHERE integration_id = ? AND crowdin_id = ? AND provider = ?', [integrationId, crowdinId, provider]);
447
- if (row) {
448
- return row;
449
- }
379
+ return this.db.prepare(`
380
+ SELECT files, integration_id as integrationId, crowdin_id as crowdinId, provider
381
+ FROM files_snapshot
382
+ WHERE integration_id = ? AND crowdin_id = ? AND provider = ?
383
+ `).get(integrationId, crowdinId, provider);
450
384
  });
451
385
  }
452
386
  getAllWebhooks(integrationId, crowdinId, provider) {
453
- return this.each('SELECT id, file_id as fileId, integration_id as integrationId, crowdin_id as crowdinId, provider FROM webhooks WHERE integration_id = ? AND crowdin_id = ? AND provider = ?', [integrationId, crowdinId, provider]);
387
+ return __awaiter(this, void 0, void 0, function* () {
388
+ return this.db.prepare(`
389
+ SELECT id, file_id as fileId, integration_id as integrationId, crowdin_id as crowdinId, provider
390
+ FROM webhooks
391
+ WHERE integration_id = ? AND crowdin_id = ? AND provider = ?
392
+ `).all(integrationId, crowdinId, provider);
393
+ });
454
394
  }
455
395
  getWebhooks(fileId, integrationId, crowdinId, provider) {
456
396
  return __awaiter(this, void 0, void 0, function* () {
457
- const row = yield this.get('SELECT id, file_id as fileId, integration_id as integrationId, crowdin_id as crowdinId, provider FROM webhooks WHERE file_id = ? AND integration_id = ? AND crowdin_id = ? AND provider = ?', [fileId, integrationId, crowdinId, provider]);
458
- if (row) {
459
- return row;
460
- }
397
+ return this.db.prepare(`
398
+ SELECT id, file_id as fileId, integration_id as integrationId, crowdin_id as crowdinId, provider
399
+ FROM webhooks
400
+ WHERE file_id = ? AND integration_id = ? AND crowdin_id = ? AND provider = ?
401
+ `).get(fileId, integrationId, crowdinId, provider);
461
402
  });
462
403
  }
463
404
  saveWebhooks(fileId, integrationId, crowdinId, provider) {
464
- return this.run('INSERT INTO webhooks(file_id, integration_id, crowdin_id, provider) VALUES (?, ?, ?, ?)', [
465
- fileId,
466
- integrationId,
467
- crowdinId,
468
- provider,
469
- ]);
405
+ return __awaiter(this, void 0, void 0, function* () {
406
+ this.db.prepare(`
407
+ INSERT INTO webhooks
408
+ (file_id, integration_id, crowdin_id, provider)
409
+ VALUES
410
+ (@fileId, @integrationId, @crowdinId, @provider)
411
+ `).run({ fileId, integrationId, crowdinId, provider });
412
+ });
470
413
  }
471
414
  deleteWebhooks(fileIds, integrationId, crowdinId, provider) {
472
415
  return __awaiter(this, void 0, void 0, function* () {
473
416
  if (!fileIds.length) {
474
417
  return;
475
418
  }
476
- const placeholders = fileIds.map(() => '?').join(',');
477
- return this.run(`DELETE FROM webhooks WHERE file_id IN (${placeholders}) AND integration_id = ? AND crowdin_id = ? AND provider = ?`, [...fileIds, integrationId, crowdinId, provider]);
419
+ this.db.prepare(`
420
+ DELETE FROM webhooks
421
+ WHERE file_id IN (${fileIds.map(() => '?').join(',')})
422
+ AND integration_id = ? AND crowdin_id = ? AND provider = ?
423
+ `).run([...fileIds, integrationId, crowdinId, provider]);
478
424
  });
479
425
  }
480
426
  getAllUserErrors(crowdinId, integrationId) {
481
- let whereIntegrationCondition = 'integration_id is NULL';
482
- const params = [crowdinId];
483
- if (integrationId) {
484
- whereIntegrationCondition = 'integration_id = ?';
485
- params.push(integrationId);
486
- }
487
- return this.each(`SELECT id, action, message, data, created_at as createdAt, integration_id as integrationId, crowdin_id as crowdinId FROM user_errors WHERE crowdin_id = ? AND ${whereIntegrationCondition}`, params);
427
+ return __awaiter(this, void 0, void 0, function* () {
428
+ let whereIntegrationCondition = 'integration_id is NULL';
429
+ const params = [crowdinId];
430
+ if (integrationId) {
431
+ whereIntegrationCondition = 'integration_id = ?';
432
+ params.push(integrationId);
433
+ }
434
+ return this.db.prepare(`
435
+ SELECT id, action, message, data, created_at as createdAt, crowdin_id as crowdinId, integration_id as integrationId
436
+ FROM user_errors
437
+ WHERE crowdin_id = ? AND ${whereIntegrationCondition}
438
+ `).all(...params);
439
+ });
488
440
  }
489
441
  saveUserError(action, message, data, createdAt, crowdinId, integrationId) {
490
- return this.run('INSERT INTO user_errors(action, message, data, created_at, integration_id, crowdin_id) VALUES (?, ?, ?, ?, ?, ?)', [action, message, data, createdAt, integrationId, crowdinId]);
442
+ return __awaiter(this, void 0, void 0, function* () {
443
+ this.db.prepare(`
444
+ INSERT INTO user_errors
445
+ (action, message, data, created_at, crowdin_id, integration_id)
446
+ VALUES
447
+ (@action, @message, @data, @createdAt, @crowdinId, @integrationId)
448
+ `).run({ action, message, data, createdAt, crowdinId, integrationId });
449
+ });
491
450
  }
492
- deleteUserErrors(createAt, crowdinId, integrationId) {
451
+ deleteUserErrors(date, crowdinId, integrationId) {
493
452
  return __awaiter(this, void 0, void 0, function* () {
494
453
  let whereIntegrationCondition = 'integration_id is NULL';
495
- const params = [createAt, crowdinId];
454
+ const params = [date, crowdinId];
496
455
  if (integrationId) {
497
456
  whereIntegrationCondition = 'integration_id = ?';
498
457
  params.push(integrationId);
499
458
  }
500
- return this.run(`DELETE FROM user_errors WHERE created_at < ? AND crowdin_id = ? AND ${whereIntegrationCondition}`, params);
459
+ this.db.prepare(`
460
+ DELETE FROM user_errors
461
+ WHERE created_at < ? AND crowdin_id = ? AND ${whereIntegrationCondition}
462
+ `).run(...params);
501
463
  });
502
464
  }
503
- deleteAllUsersErrorsOlderThan(createAt) {
465
+ deleteAllUsersErrorsOlderThan(date) {
504
466
  return __awaiter(this, void 0, void 0, function* () {
505
- yield this.run('DELETE FROM user_errors where created_at < ?', [createAt]);
467
+ this.db.prepare('DELETE FROM user_errors WHERE created_at < ?').run(date);
506
468
  });
507
469
  }
508
470
  saveIntegrationConfig(integrationId, crowdinId, config) {
509
- return this.run('INSERT INTO integration_settings(integration_id, crowdin_id, config) VALUES (?, ?, ?)', [
510
- integrationId,
511
- crowdinId,
512
- config,
513
- ]);
471
+ return __awaiter(this, void 0, void 0, function* () {
472
+ this.db.prepare(`
473
+ INSERT OR REPLACE INTO integration_settings
474
+ (integration_id, crowdin_id, config)
475
+ VALUES
476
+ (@integrationId, @crowdinId, @config)
477
+ `).run({ integrationId, crowdinId, config });
478
+ });
514
479
  }
515
480
  getAllIntegrationConfigs(crowdinId) {
516
- return this.each('SELECT config, integration_id as integrationId FROM integration_settings WHERE crowdin_id = ?', [crowdinId]);
481
+ return __awaiter(this, void 0, void 0, function* () {
482
+ return this.db.prepare(`
483
+ SELECT config, integration_id as integrationId
484
+ FROM integration_settings
485
+ WHERE crowdin_id = ?
486
+ `).all(crowdinId);
487
+ });
517
488
  }
518
489
  getIntegrationConfig(integrationId) {
519
490
  return __awaiter(this, void 0, void 0, function* () {
520
- const row = yield this.get('SELECT config FROM integration_settings WHERE integration_id = ?', [
521
- integrationId,
522
- ]);
523
- if (row) {
524
- return row;
525
- }
491
+ return this.db.prepare(`
492
+ SELECT config
493
+ FROM integration_settings
494
+ WHERE integration_id = ?
495
+ `).get(integrationId);
526
496
  });
527
497
  }
528
498
  updateIntegrationConfig(integrationId, config) {
529
- return this.run('UPDATE integration_settings SET config = ? WHERE integration_id = ?', [config, integrationId]);
499
+ return __awaiter(this, void 0, void 0, function* () {
500
+ this.db.prepare(`
501
+ UPDATE integration_settings
502
+ SET config = @config
503
+ WHERE integration_id = @integrationId
504
+ `).run({ integrationId, config });
505
+ });
530
506
  }
531
- createJob({ integrationId, crowdinId, type, title, payload }) {
507
+ createJob(params) {
532
508
  return __awaiter(this, void 0, void 0, function* () {
533
509
  const id = (0, crypto_1.randomUUID)();
534
- yield this.run(`
535
- INSERT
536
- INTO job(id, integration_id, crowdin_id, type, payload, title, created_at)
537
- VALUES (?, ?, ?, ?, ?, ?, ?)
538
- `, [id, integrationId, crowdinId, type, payload, title, Date.now().toString()]);
510
+ this.db.prepare(`
511
+ INSERT INTO job
512
+ (id, integration_id, crowdin_id, type, title, payload, created_at)
513
+ VALUES
514
+ (@id, @integrationId, @crowdinId, @type, @title, @payload, @createdAt)
515
+ `).run(Object.assign({ id, createdAt: Date.now().toString() }, params));
539
516
  return id;
540
517
  });
541
518
  }
542
519
  updateJob({ id, progress, status, info, data, attempt, errors, processedEntities, }) {
543
- const updateFields = ['updated_at = ?'];
544
- const updateParams = [Date.now().toString()];
545
- if (progress) {
546
- updateFields.push('progress = ?');
547
- updateParams.push(Math.round(progress));
548
- if (progress >= 100) {
549
- updateFields.push('finished_at = ?');
550
- updateParams.push(Date.now().toString());
520
+ return __awaiter(this, void 0, void 0, function* () {
521
+ const updateFields = ['updated_at = ?'];
522
+ const updateParams = [Date.now().toString()];
523
+ if (progress) {
524
+ updateFields.push('progress = ?');
525
+ updateParams.push(Math.round(progress));
526
+ if (progress >= 100) {
527
+ updateFields.push('finished_at = ?');
528
+ updateParams.push(Date.now().toString());
529
+ }
530
+ }
531
+ if (status) {
532
+ updateFields.push('status = ?');
533
+ updateParams.push(status);
534
+ if (!updateFields.includes('finished_at = ?') && [types_1.JobStatus.FAILED, types_1.JobStatus.CANCELED].includes(status)) {
535
+ updateFields.push('finished_at = ?');
536
+ updateParams.push(Date.now().toString());
537
+ }
551
538
  }
552
- }
553
- if (status) {
554
- updateFields.push('status = ?');
555
- updateParams.push(status);
556
- if (!updateFields.includes('finished_at = ?') && [types_1.JobStatus.FAILED, types_1.JobStatus.CANCELED].includes(status)) {
557
- updateFields.push('finished_at = ?');
558
- updateParams.push(Date.now().toString());
539
+ if (data) {
540
+ updateFields.push('data = ?');
541
+ updateParams.push(data);
559
542
  }
560
- }
561
- if (data) {
562
- updateFields.push('data = ?');
563
- updateParams.push(data);
564
- }
565
- if (info) {
566
- updateFields.push('info = ?');
567
- updateParams.push(info);
568
- }
569
- if (attempt) {
570
- updateFields.push('attempt = ?');
571
- updateParams.push(attempt);
572
- }
573
- if (errors) {
574
- updateFields.push('errors = ?');
575
- updateParams.push(JSON.stringify(errors));
576
- }
577
- if (processedEntities) {
578
- updateFields.push('processed_entities = ?');
579
- updateParams.push(processedEntities);
580
- }
581
- updateParams.push(id);
582
- const query = `
543
+ if (info) {
544
+ updateFields.push('info = ?');
545
+ updateParams.push(info);
546
+ }
547
+ if (attempt) {
548
+ updateFields.push('attempt = ?');
549
+ updateParams.push(attempt);
550
+ }
551
+ if (errors) {
552
+ updateFields.push('errors = ?');
553
+ updateParams.push(JSON.stringify(errors));
554
+ }
555
+ if (processedEntities) {
556
+ updateFields.push('processed_entities = ?');
557
+ updateParams.push(processedEntities);
558
+ }
559
+ updateParams.push(id);
560
+ const query = `
583
561
  UPDATE job
584
562
  SET ${updateFields.join(', ')}
585
563
  WHERE id = ?
586
564
  `;
587
- return this.run(query, updateParams);
588
- }
589
- getJob({ id }) {
590
- return __awaiter(this, void 0, void 0, function* () {
591
- const row = yield this.get(`
592
- SELECT id, integration_id as integrationId, crowdin_id as crowdinId, type, payload, progress, status,
593
- title, info, data, attempt, errors, processed_entities as processedEntities, created_at as createdAt, updated_at as updatedAt, finished_at as finishedAt
594
- FROM job
595
- WHERE id = ?
596
- `, [id]);
597
- if (row) {
598
- return row;
599
- }
565
+ this.db.prepare(query).run(...updateParams);
566
+ });
567
+ }
568
+ getJob(params) {
569
+ return __awaiter(this, void 0, void 0, function* () {
570
+ return this.db.prepare(`
571
+ SELECT id, integration_id as integrationId, crowdin_id as crowdinId, type, payload, progress, status,
572
+ title, info, data, attempt, errors, processed_entities as processedEntities, created_at as createdAt, updated_at as updatedAt, finished_at as finishedAt
573
+ FROM job
574
+ WHERE id = ?
575
+ `).get(params.id);
600
576
  });
601
577
  }
602
- getActiveJobs({ integrationId, crowdinId }) {
578
+ getActiveJobs(params) {
603
579
  return __awaiter(this, void 0, void 0, function* () {
604
- return this.each(`
605
- SELECT id, integration_id as integrationId, crowdin_id as crowdinId, type, payload, progress, status, title, info, data, attempt, errors, processed_entities as processedEntities, created_at as createdAt, updated_at as updatedAt, finished_at as finishedAt
606
- FROM job
607
- WHERE integration_id = ? AND crowdin_id = ? AND finished_at is NULL
608
- `, [integrationId, crowdinId]);
580
+ return this.db.prepare(`
581
+ SELECT id, integration_id as integrationId, crowdin_id as crowdinId, type, payload, progress, status, title, info, data, attempt, errors, processed_entities as processedEntities, created_at as createdAt, updated_at as updatedAt, finished_at as finishedAt
582
+ FROM job
583
+ WHERE integration_id = ? AND crowdin_id = ? AND finished_at is NULL
584
+ `).all(params.integrationId, params.crowdinId);
609
585
  });
610
586
  }
611
587
  deleteFinishedJobs() {
612
588
  return __awaiter(this, void 0, void 0, function* () {
613
- yield this.run('DELETE FROM job WHERE finished_at is not NULL', []);
589
+ this.db.prepare('DELETE FROM job WHERE finished_at IS NOT NULL').run();
614
590
  });
615
591
  }
616
592
  getAllInProgressJobs() {
617
593
  return __awaiter(this, void 0, void 0, function* () {
618
- return this.each(`
619
- SELECT id, integration_id as integrationId, crowdin_id as crowdinId, type, payload, progress, status, title, info, data, attempt, errors, processed_entities as processedEntities, created_at as createdAt, updated_at as updatedAt, finished_at as finishedAt
620
- FROM job
621
- WHERE status IN (?,?) AND finished_at is NULL
622
- `, [types_1.JobStatus.IN_PROGRESS, types_1.JobStatus.CREATED]);
594
+ return this.db.prepare(`
595
+ SELECT id, integration_id as integrationId, crowdin_id as crowdinId, type, payload, progress, status, title, info, data, attempt, errors, processed_entities as processedEntities, created_at as createdAt, updated_at as updatedAt, finished_at as finishedAt
596
+ FROM job
597
+ WHERE status IN (?,?) AND finished_at is NULL
598
+ `).all(types_1.JobStatus.IN_PROGRESS, types_1.JobStatus.CREATED);
623
599
  });
624
600
  }
625
601
  getAllJobs({ integrationId, crowdinId, limit, offset }) {
626
602
  return __awaiter(this, void 0, void 0, function* () {
627
- return this.each(`
628
- SELECT
629
- id,
630
- integration_id as integrationId,
631
- crowdin_id as crowdinId,
632
- type,
633
- payload,
634
- progress,
635
- status,
636
- title,
637
- info,
638
- data,
639
- attempt,
640
- created_at as createdAt,
641
- updated_at as updatedAt,
642
- finished_at as finishedAt
643
- FROM job
644
- WHERE integration_id = ? AND crowdin_id = ?
645
- ORDER BY created_at DESC
646
- LIMIT ? OFFSET ?
647
- `, [integrationId, crowdinId, limit, offset]);
648
- });
649
- }
650
- saveTranslationCache({ integrationId, crowdinId, fileId, languageId, etag }) {
651
- return this.run(`
652
- INSERT
653
- INTO translation_file_cache(integration_id, crowdin_id, file_id, language_id, etag)
654
- VALUES (?, ?, ?, ?, ?)
655
- `, [integrationId, crowdinId, fileId, languageId, etag]);
656
- }
657
- getFileTranslationCache({ integrationId, crowdinId, fileId, }) {
658
- return __awaiter(this, void 0, void 0, function* () {
659
- return this.each(`
660
- SELECT integration_id as integrationId, crowdin_id as crowdinId, file_id as fileId, language_id as languageId, etag
661
- FROM translation_file_cache
662
- WHERE integration_id = ? AND crowdin_id = ? AND file_id = ?
663
- `, [integrationId, crowdinId, fileId]);
664
- });
665
- }
666
- getFileTranslationCacheByLanguage({ integrationId, crowdinId, fileId, languageId, }) {
667
- return __awaiter(this, void 0, void 0, function* () {
668
- const row = yield this.get(`
669
- SELECT integration_id as integrationId, crowdin_id as crowdinId, file_id as fileId, language_id as languageId, etag
670
- FROM translation_file_cache
671
- WHERE integration_id = ? AND crowdin_id = ? AND file_id = ? AND language_id = ?
672
- `, [integrationId, crowdinId, fileId, languageId]);
673
- if (row) {
674
- return row;
675
- }
603
+ return this.db.prepare(`
604
+ SELECT
605
+ id,
606
+ integration_id as integrationId,
607
+ crowdin_id as crowdinId,
608
+ type,
609
+ payload,
610
+ progress,
611
+ status,
612
+ title,
613
+ info,
614
+ data,
615
+ attempt,
616
+ created_at as createdAt,
617
+ updated_at as updatedAt,
618
+ finished_at as finishedAt
619
+ FROM job
620
+ WHERE integration_id = ? AND crowdin_id = ?
621
+ ORDER BY created_at DESC
622
+ LIMIT ? OFFSET ?
623
+ `).all(integrationId, crowdinId, limit, offset);
676
624
  });
677
625
  }
678
- updateTranslationCache({ integrationId, crowdinId, fileId, languageId, etag, }) {
679
- return this.run(`
680
- UPDATE translation_file_cache
681
- SET etag = ?
682
- WHERE integration_id = ? AND crowdin_id = ? AND file_id = ? AND language_id = ?
683
- `, [etag, integrationId, crowdinId, fileId, languageId]);
684
- }
685
- saveUnsyncedFiles({ integrationId, crowdinId, files }) {
686
- return this.run(`
687
- INSERT
688
- INTO unsynced_files(integration_id, crowdin_id, files)
689
- VALUES (?, ?, ?)
690
- `, [integrationId, crowdinId, files]);
691
- }
692
- updateUnsyncedFiles({ integrationId, crowdinId, files }) {
693
- return this.run(`
694
- UPDATE unsynced_files
695
- SET files = ?
696
- WHERE integration_id = ? AND crowdin_id = ?
697
- `, [files, integrationId, crowdinId]);
698
- }
699
- getUnsyncedFiles({ integrationId, crowdinId }) {
700
- return __awaiter(this, void 0, void 0, function* () {
701
- const row = yield this.get(`
702
- SELECT files
703
- FROM unsynced_files
704
- WHERE integration_id = ? AND crowdin_id = ?
705
- `, [integrationId, crowdinId]);
706
- if (row) {
707
- return row;
708
- }
626
+ saveTranslationCache(params) {
627
+ return __awaiter(this, void 0, void 0, function* () {
628
+ this.db.prepare(`
629
+ INSERT INTO translation_file_cache
630
+ (integration_id, crowdin_id, file_id, language_id, etag)
631
+ VALUES
632
+ (@integrationId, @crowdinId, @fileId, @languageId, @etag)
633
+ `).run(params);
634
+ });
635
+ }
636
+ getFileTranslationCache(params) {
637
+ return __awaiter(this, void 0, void 0, function* () {
638
+ return this.db.prepare(`
639
+ SELECT integration_id as integrationId, crowdin_id as crowdinId, file_id as fileId, language_id as languageId, etag
640
+ FROM translation_file_cache
641
+ WHERE integration_id = ? AND crowdin_id = ? AND file_id = ?
642
+ `).all(params.integrationId, params.crowdinId, params.fileId);
643
+ });
644
+ }
645
+ getFileTranslationCacheByLanguage(params) {
646
+ return __awaiter(this, void 0, void 0, function* () {
647
+ return this.db.prepare(`
648
+ SELECT integration_id as integrationId, crowdin_id as crowdinId, file_id as fileId, language_id as languageId, etag
649
+ FROM translation_file_cache
650
+ WHERE integration_id = ? AND crowdin_id = ? AND file_id = ? AND language_id = ?
651
+ `).get(params.integrationId, params.crowdinId, params.fileId, params.languageId);
652
+ });
653
+ }
654
+ updateTranslationCache(params) {
655
+ return __awaiter(this, void 0, void 0, function* () {
656
+ this.db.prepare(`
657
+ UPDATE translation_file_cache
658
+ SET etag = ?
659
+ WHERE integration_id = ? AND crowdin_id = ? AND file_id = ? AND language_id = ?
660
+ `).run(params.etag, params.integrationId, params.crowdinId, params.fileId, params.languageId);
661
+ });
662
+ }
663
+ saveUnsyncedFiles(params) {
664
+ return __awaiter(this, void 0, void 0, function* () {
665
+ this.db.prepare(`
666
+ INSERT INTO unsynced_files
667
+ (integration_id, crowdin_id, files)
668
+ VALUES
669
+ (@integrationId, @crowdinId, @files)
670
+ `).run(params);
671
+ });
672
+ }
673
+ getUnsyncedFiles(params) {
674
+ return __awaiter(this, void 0, void 0, function* () {
675
+ return this.db.prepare(`
676
+ SELECT files
677
+ FROM unsynced_files
678
+ WHERE integration_id = ? AND crowdin_id = ?
679
+ `).get(params.integrationId, params.crowdinId);
680
+ });
681
+ }
682
+ updateUnsyncedFiles(params) {
683
+ return __awaiter(this, void 0, void 0, function* () {
684
+ this.db.prepare(`
685
+ UPDATE unsynced_files
686
+ SET files = ?
687
+ WHERE integration_id = ? AND crowdin_id = ?
688
+ `).run(params.files, params.integrationId, params.crowdinId);
709
689
  });
710
690
  }
711
691
  registerCustomTable(tableName, schema) {
712
692
  return __awaiter(this, void 0, void 0, function* () {
713
- const columns = Object.entries(schema)
714
- .map(([col, def]) => `${col} ${def}`)
693
+ const columnsDefinition = Object.entries(schema)
694
+ .map(([columnName, columnType]) => `${columnName} ${columnType}`)
715
695
  .join(', ');
716
- const query = `CREATE TABLE IF NOT EXISTS ${tableName} (${columns});`;
717
- yield this.run(query, []);
696
+ const createTableQuery = `CREATE TABLE IF NOT EXISTS ${tableName} (${columnsDefinition})`;
697
+ this.db.prepare(createTableQuery).run();
718
698
  });
719
699
  }
720
700
  insertRecord(tableName, data) {
@@ -724,11 +704,11 @@ class SQLiteStorage {
724
704
  .map(() => '?')
725
705
  .join(', ');
726
706
  const values = Object.values(data);
727
- const query = `INSERT INTO ${tableName} (${columns}) VALUES (${placeholders});`;
728
- return this.run(query, values);
707
+ const insertQuery = `INSERT INTO ${tableName} (${columns}) VALUES (${placeholders})`;
708
+ this.db.prepare(insertQuery).run(...values);
729
709
  });
730
710
  }
731
- selectRecords(tableName, options = {}, params = []) {
711
+ selectRecords(tableName, options = {}, params) {
732
712
  var _a;
733
713
  return __awaiter(this, void 0, void 0, function* () {
734
714
  const columns = ((_a = options.columns) === null || _a === void 0 ? void 0 : _a.length) ? options.columns.join(', ') : '*';
@@ -738,37 +718,52 @@ class SQLiteStorage {
738
718
  const limitClause = options.limit ? ` LIMIT ${options.limit}` : '';
739
719
  const offsetClause = options.offset ? ` OFFSET ${options.offset}` : '';
740
720
  const query = `SELECT ${distinctKeyword}${columns} FROM ${tableName}${whereClause}${orderByClause}${limitClause}${offsetClause};`;
741
- return this.each(query, params);
721
+ return this.db.prepare(query).all(...(params || []));
742
722
  });
743
723
  }
744
- updateRecord(tableName, data, whereClause, params = []) {
724
+ updateRecord(tableName, data, whereClause, params) {
745
725
  return __awaiter(this, void 0, void 0, function* () {
746
726
  const setClause = Object.keys(data)
747
727
  .map((key) => `${key} = ?`)
748
728
  .join(', ');
749
729
  const values = Object.values(data);
750
730
  const query = `UPDATE ${tableName} SET ${setClause} ${whereClause};`;
751
- yield this.run(query, [...values, ...params]);
731
+ this.db.prepare(query).run(...values, ...(params || []));
752
732
  });
753
733
  }
754
- deleteRecord(tableName, whereClause, params = []) {
734
+ deleteRecord(tableName, whereClause, params) {
755
735
  return __awaiter(this, void 0, void 0, function* () {
756
736
  const query = `DELETE FROM ${tableName} ${whereClause};`;
757
- yield this.run(query, params);
737
+ this.db.prepare(query).run(...(params || []));
758
738
  });
759
739
  }
760
740
  saveSyncedData(files, integrationId, crowdinId, type) {
761
- return this.run('INSERT INTO synced_data(files, integration_id, crowdin_id, type, updated_at) VALUES (?, ?, ?, ?, ?)', [files, integrationId, crowdinId, type, Date.now().toString()]);
741
+ return __awaiter(this, void 0, void 0, function* () {
742
+ this.db.prepare(`
743
+ INSERT INTO synced_data
744
+ (files, integration_id, crowdin_id, type, updated_at)
745
+ VALUES
746
+ (@files, @integrationId, @crowdinId, @type, @updatedAt)
747
+ `).run({ files, integrationId, crowdinId, type, updatedAt: Date.now().toString() });
748
+ });
762
749
  }
763
750
  updateSyncedData(files, integrationId, crowdinId, type) {
764
- return this.run('UPDATE synced_data SET files = ?, updated_at = ? WHERE integration_id = ? AND crowdin_id = ? AND type = ?', [files, Date.now().toString(), integrationId, crowdinId, type]);
751
+ return __awaiter(this, void 0, void 0, function* () {
752
+ this.db.prepare(`
753
+ UPDATE synced_data
754
+ SET files = @files, updated_at = @updatedAt
755
+ WHERE integration_id = @integrationId AND crowdin_id = @crowdinId AND type = @type
756
+ `).run({ files, integrationId, crowdinId, type, updatedAt: Date.now().toString() });
757
+ });
765
758
  }
766
759
  getSyncedData(integrationId, crowdinId, type) {
767
760
  return __awaiter(this, void 0, void 0, function* () {
768
- const row = yield this.get('SELECT id, files, integration_id as integrationId, crowdin_id as crowdinId, type, updated_at as updatedAt FROM synced_data WHERE integration_id = ? AND crowdin_id = ? AND type = ?', [integrationId, crowdinId, type]);
769
- if (row) {
770
- return row;
771
- }
761
+ const query = `
762
+ SELECT id, files, integration_id as integrationId, crowdin_id as crowdinId, type, updated_at as updatedAt
763
+ FROM synced_data
764
+ WHERE integration_id = @integrationId AND crowdin_id = @crowdinId AND type = @type
765
+ `;
766
+ return this.db.prepare(query).get({ integrationId, crowdinId, type });
772
767
  });
773
768
  }
774
769
  }