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