@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.
- package/out/index.js +5 -2
- package/out/middlewares/auto-credentials-masker.js +4 -1
- package/out/modules/integration/handlers/integration-data.js +2 -0
- package/out/modules/integration/handlers/sync-settings-save.js +5 -2
- package/out/modules/integration/types.d.ts +2 -0
- package/out/modules/integration/util/cron.js +32 -7
- package/out/modules/integration/util/files.js +4 -0
- package/out/modules/integration/util/snapshot.d.ts +7 -1
- package/out/modules/integration/util/snapshot.js +15 -5
- package/out/static/ui/form.bundle.js +46368 -0
- package/out/static/ui/form.bundle.js.map +1 -0
- package/out/static/ui/main.bundle.js +9 -2
- package/out/static/ui/main.bundle.js.map +1 -1
- package/out/storage/index.d.ts +1 -1
- package/out/storage/index.js +6 -6
- package/out/storage/sqlite.d.ts +28 -38
- package/out/storage/sqlite.js +533 -538
- package/out/util/credentials-masker.d.ts +5 -1
- package/out/util/credentials-masker.js +2 -2
- package/out/views/FormPage.js +1 -1
- package/package.json +7 -13
- package/out/static/js/form.js +0 -106
package/out/storage/sqlite.js
CHANGED
|
@@ -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.
|
|
21
|
-
this._res = res;
|
|
22
|
-
this._rej = rej;
|
|
23
|
-
});
|
|
19
|
+
this.db = null;
|
|
24
20
|
this.tables = {
|
|
25
21
|
crowdin_credentials: `(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
id varchar not null primary key,
|
|
50
|
+
data varchar null,
|
|
51
|
+
crowdin_id varchar null
|
|
52
|
+
)`,
|
|
57
53
|
files_snapshot: `(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
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
|
-
|
|
251
|
-
|
|
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 (
|
|
259
|
-
|
|
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
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
|
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
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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
|
|
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
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
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
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
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
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
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 =
|
|
386
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
|
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
|
-
|
|
327
|
+
`).all(type, schedule);
|
|
328
|
+
});
|
|
418
329
|
}
|
|
419
330
|
saveSyncSettings(files, integrationId, crowdinId, type, provider) {
|
|
420
|
-
return this
|
|
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
|
|
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
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
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
|
|
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
|
-
|
|
447
|
-
|
|
448
|
-
|
|
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
|
|
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
|
-
|
|
458
|
-
|
|
459
|
-
|
|
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
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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
|
-
|
|
477
|
-
|
|
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
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
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
|
|
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(
|
|
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 = [
|
|
454
|
+
const params = [date, crowdinId];
|
|
496
455
|
if (integrationId) {
|
|
497
456
|
whereIntegrationCondition = 'integration_id = ?';
|
|
498
457
|
params.push(integrationId);
|
|
499
458
|
}
|
|
500
|
-
|
|
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(
|
|
465
|
+
deleteAllUsersErrorsOlderThan(date) {
|
|
504
466
|
return __awaiter(this, void 0, void 0, function* () {
|
|
505
|
-
|
|
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
|
|
510
|
-
|
|
511
|
-
|
|
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
|
|
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
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
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
|
|
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(
|
|
507
|
+
createJob(params) {
|
|
532
508
|
return __awaiter(this, void 0, void 0, function* () {
|
|
533
509
|
const id = (0, crypto_1.randomUUID)();
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
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
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
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
|
-
|
|
554
|
-
|
|
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
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
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
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
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(
|
|
578
|
+
getActiveJobs(params) {
|
|
603
579
|
return __awaiter(this, void 0, void 0, function* () {
|
|
604
|
-
return this.
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
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
|
-
|
|
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.
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
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.
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
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
|
-
|
|
679
|
-
return this
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
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
|
|
714
|
-
.map(([
|
|
693
|
+
const columnsDefinition = Object.entries(schema)
|
|
694
|
+
.map(([columnName, columnType]) => `${columnName} ${columnType}`)
|
|
715
695
|
.join(', ');
|
|
716
|
-
const
|
|
717
|
-
|
|
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
|
|
728
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
737
|
+
this.db.prepare(query).run(...(params || []));
|
|
758
738
|
});
|
|
759
739
|
}
|
|
760
740
|
saveSyncedData(files, integrationId, crowdinId, type) {
|
|
761
|
-
return this
|
|
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
|
|
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
|
|
769
|
-
|
|
770
|
-
|
|
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
|
}
|