@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
|
@@ -0,0 +1,939 @@
|
|
|
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.DrizzleStorage = void 0;
|
|
13
|
+
const crypto_1 = require("crypto");
|
|
14
|
+
const drizzle_orm_1 = require("drizzle-orm");
|
|
15
|
+
const types_1 = require("../../modules/integration/util/types");
|
|
16
|
+
const d1_1 = require("./d1");
|
|
17
|
+
const types_2 = require("./d1/types");
|
|
18
|
+
const postgresql_1 = require("./postgresql");
|
|
19
|
+
const sqlite_1 = require("./sqlite");
|
|
20
|
+
const SCHEMAS_MAP = {
|
|
21
|
+
sqlite: sqlite_1.SQLITE_SCHEMA,
|
|
22
|
+
postgresql: postgresql_1.POSTGRESQL_SCHEMA,
|
|
23
|
+
d1: types_2.D1_SCHEMA,
|
|
24
|
+
};
|
|
25
|
+
class DrizzleStorage {
|
|
26
|
+
// uncomment to check types
|
|
27
|
+
// db: SQLITE_DB;
|
|
28
|
+
// schema: typeof SQLITE_SCHEMA;
|
|
29
|
+
// uncomment to check types
|
|
30
|
+
// db: D1_DB;
|
|
31
|
+
// schema: typeof D1_SCHEMA;
|
|
32
|
+
constructor({ config, type, delayedMigration, }) {
|
|
33
|
+
var _a, _b, _c, _d, _e;
|
|
34
|
+
this.migrated = false;
|
|
35
|
+
let db;
|
|
36
|
+
if (type === 'd1') {
|
|
37
|
+
db = (0, d1_1.initD1)(Object.assign(Object.assign({}, config.d1Config), { additionalSchema: (_a = config.customTables) === null || _a === void 0 ? void 0 : _a.schema }));
|
|
38
|
+
this.migrationPromise = delayedMigration ? Promise.resolve() : (0, d1_1.migrateD1)(db);
|
|
39
|
+
}
|
|
40
|
+
else if (type === 'postgresql') {
|
|
41
|
+
db = (0, postgresql_1.initPostgreSQL)(config.postgreConfig, (_b = config.customTables) === null || _b === void 0 ? void 0 : _b.schema);
|
|
42
|
+
this.migrationPromise = delayedMigration
|
|
43
|
+
? Promise.resolve()
|
|
44
|
+
: (0, postgresql_1.migratePostgreSQL)({
|
|
45
|
+
db,
|
|
46
|
+
name: config.name,
|
|
47
|
+
directoryPath: config.migrateToPostgreFromSQLite ? config.dbFolder : undefined,
|
|
48
|
+
additionalMigrationFolder: (_c = config.customTables) === null || _c === void 0 ? void 0 : _c.migrationFolder,
|
|
49
|
+
});
|
|
50
|
+
this.migrated = true;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
db = (0, sqlite_1.initSqlite)(config.dbFolder, (_d = config.customTables) === null || _d === void 0 ? void 0 : _d.schema);
|
|
54
|
+
this.migrationPromise = delayedMigration
|
|
55
|
+
? Promise.resolve()
|
|
56
|
+
: (0, sqlite_1.migrateSqlite)(db, (_e = config.customTables) === null || _e === void 0 ? void 0 : _e.migrationFolder);
|
|
57
|
+
this.migrated = true;
|
|
58
|
+
}
|
|
59
|
+
// using cast here to avoid ts errors, since all drivers should have the same methods, just different clients
|
|
60
|
+
this.db = db;
|
|
61
|
+
this.schema = SCHEMAS_MAP[type];
|
|
62
|
+
this.type = type;
|
|
63
|
+
this.config = config;
|
|
64
|
+
}
|
|
65
|
+
migrateDelayed() {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
var _a, _b, _c;
|
|
68
|
+
if (!this.migrated) {
|
|
69
|
+
if (this.type === 'd1') {
|
|
70
|
+
yield (0, d1_1.migrateD1)(this.db, (_a = this.config.customTables) === null || _a === void 0 ? void 0 : _a.d1Migrations);
|
|
71
|
+
}
|
|
72
|
+
else if (this.type === 'postgresql') {
|
|
73
|
+
yield (0, postgresql_1.migratePostgreSQL)({
|
|
74
|
+
db: this.db,
|
|
75
|
+
name: this.config.name,
|
|
76
|
+
directoryPath: this.config.migrateToPostgreFromSQLite ? this.config.dbFolder : undefined,
|
|
77
|
+
additionalMigrationFolder: (_b = this.config.customTables) === null || _b === void 0 ? void 0 : _b.migrationFolder,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
yield (0, sqlite_1.migrateSqlite)(this.db, (_c = this.config.customTables) === null || _c === void 0 ? void 0 : _c.migrationFolder);
|
|
82
|
+
}
|
|
83
|
+
this.migrated = true;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
saveCrowdinCredentials(credentials) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
yield this.migrationPromise;
|
|
90
|
+
yield this.db.insert(this.schema.crowdinCredentials).values({
|
|
91
|
+
id: credentials.id,
|
|
92
|
+
app_secret: credentials.appSecret,
|
|
93
|
+
domain: credentials.domain,
|
|
94
|
+
user_id: this.toString(credentials.userId),
|
|
95
|
+
agent_id: this.toString(credentials.agentId),
|
|
96
|
+
organization_id: this.toString(credentials.organizationId),
|
|
97
|
+
base_url: credentials.baseUrl,
|
|
98
|
+
access_token: credentials.accessToken,
|
|
99
|
+
refresh_token: credentials.refreshToken,
|
|
100
|
+
expire: credentials.expire,
|
|
101
|
+
type: credentials.type,
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
updateCrowdinCredentials(credentials) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
yield this.migrationPromise;
|
|
108
|
+
yield this.db
|
|
109
|
+
.update(this.schema.crowdinCredentials)
|
|
110
|
+
.set({
|
|
111
|
+
app_secret: credentials.appSecret,
|
|
112
|
+
domain: credentials.domain,
|
|
113
|
+
user_id: this.toString(credentials.userId),
|
|
114
|
+
agent_id: this.toString(credentials.agentId),
|
|
115
|
+
organization_id: this.toString(credentials.organizationId),
|
|
116
|
+
base_url: credentials.baseUrl,
|
|
117
|
+
access_token: credentials.accessToken,
|
|
118
|
+
refresh_token: credentials.refreshToken,
|
|
119
|
+
expire: credentials.expire,
|
|
120
|
+
type: credentials.type,
|
|
121
|
+
})
|
|
122
|
+
.where((0, drizzle_orm_1.eq)(this.schema.crowdinCredentials.id, credentials.id));
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
getCrowdinCredentials(id) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
yield this.migrationPromise;
|
|
128
|
+
const item = yield this.db.query.crowdinCredentials.findFirst({
|
|
129
|
+
where: (0, drizzle_orm_1.eq)(this.schema.crowdinCredentials.id, id),
|
|
130
|
+
});
|
|
131
|
+
if (!item) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
id: item.id,
|
|
136
|
+
appSecret: item.app_secret,
|
|
137
|
+
domain: item.domain,
|
|
138
|
+
userId: this.toNumber(item.user_id),
|
|
139
|
+
agentId: this.toNumber(item.agent_id),
|
|
140
|
+
organizationId: this.toNumber(item.organization_id),
|
|
141
|
+
baseUrl: item.base_url,
|
|
142
|
+
accessToken: item.access_token,
|
|
143
|
+
refreshToken: item.refresh_token,
|
|
144
|
+
expire: item.expire,
|
|
145
|
+
type: item.type,
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
getAllCrowdinCredentials() {
|
|
150
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
yield this.migrationPromise;
|
|
152
|
+
const res = yield this.db.query.crowdinCredentials.findMany();
|
|
153
|
+
return res.map((item) => ({
|
|
154
|
+
id: item.id,
|
|
155
|
+
appSecret: item.app_secret,
|
|
156
|
+
domain: item.domain,
|
|
157
|
+
userId: this.toNumber(item.user_id),
|
|
158
|
+
agentId: this.toNumber(item.agent_id),
|
|
159
|
+
organizationId: this.toNumber(item.organization_id),
|
|
160
|
+
baseUrl: item.base_url,
|
|
161
|
+
accessToken: item.access_token,
|
|
162
|
+
refreshToken: item.refresh_token,
|
|
163
|
+
expire: item.expire,
|
|
164
|
+
type: item.type,
|
|
165
|
+
}));
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
deleteCrowdinCredentials(id) {
|
|
169
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
yield this.migrationPromise;
|
|
171
|
+
yield this.db.delete(this.schema.crowdinCredentials).where((0, drizzle_orm_1.eq)(this.schema.crowdinCredentials.id, id));
|
|
172
|
+
yield this.db
|
|
173
|
+
.delete(this.schema.integrationCredentials)
|
|
174
|
+
.where((0, drizzle_orm_1.eq)(this.schema.integrationCredentials.crowdin_id, id));
|
|
175
|
+
yield this.db.delete(this.schema.syncSettings).where((0, drizzle_orm_1.eq)(this.schema.syncSettings.crowdin_id, id));
|
|
176
|
+
yield this.db.delete(this.schema.appMetadata).where((0, drizzle_orm_1.eq)(this.schema.appMetadata.crowdin_id, id));
|
|
177
|
+
yield this.db.delete(this.schema.filesSnapshot).where((0, drizzle_orm_1.eq)(this.schema.filesSnapshot.crowdin_id, id));
|
|
178
|
+
yield this.db.delete(this.schema.webhooks).where((0, drizzle_orm_1.eq)(this.schema.webhooks.crowdin_id, id));
|
|
179
|
+
yield this.db.delete(this.schema.userErrors).where((0, drizzle_orm_1.eq)(this.schema.userErrors.crowdin_id, id));
|
|
180
|
+
yield this.db.delete(this.schema.integrationSettings).where((0, drizzle_orm_1.eq)(this.schema.integrationSettings.crowdin_id, id));
|
|
181
|
+
yield this.db.delete(this.schema.job).where((0, drizzle_orm_1.eq)(this.schema.job.crowdin_id, id));
|
|
182
|
+
yield this.db
|
|
183
|
+
.delete(this.schema.translationFileCache)
|
|
184
|
+
.where((0, drizzle_orm_1.eq)(this.schema.translationFileCache.crowdin_id, id));
|
|
185
|
+
yield this.db.delete(this.schema.unsyncedFiles).where((0, drizzle_orm_1.eq)(this.schema.unsyncedFiles.crowdin_id, id));
|
|
186
|
+
yield this.db.delete(this.schema.syncedData).where((0, drizzle_orm_1.eq)(this.schema.syncedData.crowdin_id, id));
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
saveIntegrationCredentials(id, credentials, crowdinId) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
yield this.migrationPromise;
|
|
192
|
+
yield this.db.insert(this.schema.integrationCredentials).values({
|
|
193
|
+
id,
|
|
194
|
+
credentials,
|
|
195
|
+
crowdin_id: crowdinId,
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
updateIntegrationCredentials(id, credentials) {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
yield this.migrationPromise;
|
|
202
|
+
yield this.db
|
|
203
|
+
.update(this.schema.integrationCredentials)
|
|
204
|
+
.set({ credentials })
|
|
205
|
+
.where((0, drizzle_orm_1.eq)(this.schema.integrationCredentials.id, id));
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
updateIntegrationManagers(id, managers) {
|
|
209
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
yield this.migrationPromise;
|
|
211
|
+
yield this.db
|
|
212
|
+
.update(this.schema.integrationCredentials)
|
|
213
|
+
.set({ managers })
|
|
214
|
+
.where((0, drizzle_orm_1.eq)(this.schema.integrationCredentials.id, id));
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
getIntegrationCredentials(id) {
|
|
218
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
219
|
+
yield this.migrationPromise;
|
|
220
|
+
const item = yield this.db.query.integrationCredentials.findFirst({
|
|
221
|
+
where: (0, drizzle_orm_1.eq)(this.schema.integrationCredentials.id, id),
|
|
222
|
+
});
|
|
223
|
+
if (!item) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
id: item.id,
|
|
228
|
+
credentials: item.credentials,
|
|
229
|
+
crowdinId: item.crowdin_id,
|
|
230
|
+
managers: item.managers,
|
|
231
|
+
};
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
getAllIntegrationCredentials(crowdinId) {
|
|
235
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
236
|
+
yield this.migrationPromise;
|
|
237
|
+
const res = yield this.db.query.integrationCredentials.findMany({
|
|
238
|
+
where: (0, drizzle_orm_1.eq)(this.schema.integrationCredentials.crowdin_id, crowdinId),
|
|
239
|
+
});
|
|
240
|
+
return res.map((item) => ({
|
|
241
|
+
id: item.id,
|
|
242
|
+
credentials: item.credentials,
|
|
243
|
+
crowdinId: item.crowdin_id,
|
|
244
|
+
managers: item.managers,
|
|
245
|
+
}));
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
deleteIntegrationCredentials(id) {
|
|
249
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
+
yield this.migrationPromise;
|
|
251
|
+
yield this.db.delete(this.schema.integrationCredentials).where((0, drizzle_orm_1.eq)(this.schema.integrationCredentials.id, id));
|
|
252
|
+
yield this.db.delete(this.schema.syncSettings).where((0, drizzle_orm_1.eq)(this.schema.syncSettings.integration_id, id));
|
|
253
|
+
yield this.db.delete(this.schema.filesSnapshot).where((0, drizzle_orm_1.eq)(this.schema.filesSnapshot.integration_id, id));
|
|
254
|
+
yield this.db.delete(this.schema.webhooks).where((0, drizzle_orm_1.eq)(this.schema.webhooks.integration_id, id));
|
|
255
|
+
yield this.db.delete(this.schema.userErrors).where((0, drizzle_orm_1.eq)(this.schema.userErrors.integration_id, id));
|
|
256
|
+
yield this.db
|
|
257
|
+
.delete(this.schema.integrationSettings)
|
|
258
|
+
.where((0, drizzle_orm_1.eq)(this.schema.integrationSettings.integration_id, id));
|
|
259
|
+
yield this.db.delete(this.schema.job).where((0, drizzle_orm_1.eq)(this.schema.job.integration_id, id));
|
|
260
|
+
yield this.db
|
|
261
|
+
.delete(this.schema.translationFileCache)
|
|
262
|
+
.where((0, drizzle_orm_1.eq)(this.schema.translationFileCache.integration_id, id));
|
|
263
|
+
yield this.db.delete(this.schema.unsyncedFiles).where((0, drizzle_orm_1.eq)(this.schema.unsyncedFiles.integration_id, id));
|
|
264
|
+
yield this.db.delete(this.schema.syncedData).where((0, drizzle_orm_1.eq)(this.schema.syncedData.integration_id, id));
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
deleteAllIntegrationCredentials(crowdinId) {
|
|
268
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
269
|
+
yield this.migrationPromise;
|
|
270
|
+
yield this.db
|
|
271
|
+
.delete(this.schema.integrationCredentials)
|
|
272
|
+
.where((0, drizzle_orm_1.eq)(this.schema.integrationCredentials.crowdin_id, crowdinId));
|
|
273
|
+
yield this.db.delete(this.schema.syncSettings).where((0, drizzle_orm_1.eq)(this.schema.syncSettings.crowdin_id, crowdinId));
|
|
274
|
+
yield this.db.delete(this.schema.filesSnapshot).where((0, drizzle_orm_1.eq)(this.schema.filesSnapshot.crowdin_id, crowdinId));
|
|
275
|
+
yield this.db.delete(this.schema.webhooks).where((0, drizzle_orm_1.eq)(this.schema.webhooks.crowdin_id, crowdinId));
|
|
276
|
+
yield this.db.delete(this.schema.userErrors).where((0, drizzle_orm_1.eq)(this.schema.userErrors.crowdin_id, crowdinId));
|
|
277
|
+
yield this.db
|
|
278
|
+
.delete(this.schema.integrationSettings)
|
|
279
|
+
.where((0, drizzle_orm_1.eq)(this.schema.integrationSettings.crowdin_id, crowdinId));
|
|
280
|
+
yield this.db.delete(this.schema.job).where((0, drizzle_orm_1.eq)(this.schema.job.crowdin_id, crowdinId));
|
|
281
|
+
yield this.db
|
|
282
|
+
.delete(this.schema.translationFileCache)
|
|
283
|
+
.where((0, drizzle_orm_1.eq)(this.schema.translationFileCache.crowdin_id, crowdinId));
|
|
284
|
+
yield this.db.delete(this.schema.unsyncedFiles).where((0, drizzle_orm_1.eq)(this.schema.unsyncedFiles.crowdin_id, crowdinId));
|
|
285
|
+
yield this.db.delete(this.schema.syncedData).where((0, drizzle_orm_1.eq)(this.schema.syncedData.crowdin_id, crowdinId));
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
saveMetadata(id, metadata, crowdinId) {
|
|
289
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
+
yield this.migrationPromise;
|
|
291
|
+
yield this.db.insert(this.schema.appMetadata).values({
|
|
292
|
+
id,
|
|
293
|
+
data: JSON.stringify(metadata),
|
|
294
|
+
crowdin_id: crowdinId,
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
updateMetadata(id, metadata, crowdinId) {
|
|
299
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
300
|
+
yield this.migrationPromise;
|
|
301
|
+
yield this.db
|
|
302
|
+
.update(this.schema.appMetadata)
|
|
303
|
+
.set({
|
|
304
|
+
data: JSON.stringify(metadata),
|
|
305
|
+
crowdin_id: crowdinId,
|
|
306
|
+
})
|
|
307
|
+
.where((0, drizzle_orm_1.eq)(this.schema.appMetadata.id, id));
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
getMetadata(id) {
|
|
311
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
312
|
+
yield this.migrationPromise;
|
|
313
|
+
const item = yield this.db.query.appMetadata.findFirst({
|
|
314
|
+
where: (0, drizzle_orm_1.eq)(this.schema.appMetadata.id, id),
|
|
315
|
+
});
|
|
316
|
+
if (!item) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
return JSON.parse(item.data);
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
getAllMetadata() {
|
|
323
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
324
|
+
yield this.migrationPromise;
|
|
325
|
+
const res = yield this.db.query.appMetadata.findMany();
|
|
326
|
+
return res.map((item) => ({
|
|
327
|
+
id: item.id,
|
|
328
|
+
data: JSON.parse(item.data),
|
|
329
|
+
crowdinId: item.crowdin_id,
|
|
330
|
+
}));
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
deleteMetadata(id) {
|
|
334
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
335
|
+
yield this.migrationPromise;
|
|
336
|
+
yield this.db.delete(this.schema.appMetadata).where((0, drizzle_orm_1.eq)(this.schema.appMetadata.id, id));
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
getSyncSettingsByProvider(integrationId, provider) {
|
|
340
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
341
|
+
yield this.migrationPromise;
|
|
342
|
+
const item = yield this.db.query.syncSettings.findFirst({
|
|
343
|
+
where: (0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.syncSettings.integration_id, integrationId), (0, drizzle_orm_1.eq)(this.schema.syncSettings.provider, provider)),
|
|
344
|
+
});
|
|
345
|
+
if (!item) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
return {
|
|
349
|
+
id: item.id,
|
|
350
|
+
files: item.files,
|
|
351
|
+
integrationId: item.integration_id,
|
|
352
|
+
crowdinId: item.crowdin_id,
|
|
353
|
+
type: item.type,
|
|
354
|
+
provider: item.provider,
|
|
355
|
+
};
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
getSyncSettingsBySchedule(type, schedule) {
|
|
359
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
360
|
+
if (this.type === 'postgresql') {
|
|
361
|
+
const db = this.db;
|
|
362
|
+
const query = `
|
|
363
|
+
SELECT s.id, s.files, s.integration_id as "integrationId", s.crowdin_id as "crowdinId", s.type, s.provider
|
|
364
|
+
FROM sync_settings s
|
|
365
|
+
INNER JOIN integration_settings i ON s.integration_id = i.integration_id
|
|
366
|
+
WHERE s.type = $1
|
|
367
|
+
AND CASE
|
|
368
|
+
WHEN i.config IS NULL THEN false
|
|
369
|
+
ELSE (i.config::json->>'schedule') = $2
|
|
370
|
+
END
|
|
371
|
+
`;
|
|
372
|
+
const res = yield db.$client.query(query, [type, schedule]);
|
|
373
|
+
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
374
|
+
}
|
|
375
|
+
const query = `
|
|
376
|
+
SELECT s.id, s.files, s.integration_id as integrationId, s.crowdin_id as crowdinId, s.type, s.provider
|
|
377
|
+
FROM sync_settings s
|
|
378
|
+
INNER JOIN integration_settings i ON s.integration_id = i.integration_id
|
|
379
|
+
WHERE s.type = ?
|
|
380
|
+
AND CASE
|
|
381
|
+
WHEN i.config IS NULL THEN 0
|
|
382
|
+
ELSE json_extract(i.config, '$.schedule') = ?
|
|
383
|
+
END
|
|
384
|
+
`;
|
|
385
|
+
if (this.type === 'sqlite') {
|
|
386
|
+
const db = this.db;
|
|
387
|
+
const res = db.$client.prepare(query).all(type, schedule);
|
|
388
|
+
return res;
|
|
389
|
+
}
|
|
390
|
+
if (this.type === 'd1') {
|
|
391
|
+
const db = this.db;
|
|
392
|
+
const res = yield db.$client.prepare(query).bind(type, schedule).all();
|
|
393
|
+
return res.results || [];
|
|
394
|
+
}
|
|
395
|
+
throw new Error(`Unsupported database type ${this.type}`);
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
saveSyncSettings(files, integrationId, crowdinId, type, provider) {
|
|
399
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
400
|
+
yield this.migrationPromise;
|
|
401
|
+
yield this.db.insert(this.schema.syncSettings).values({
|
|
402
|
+
files,
|
|
403
|
+
integration_id: integrationId,
|
|
404
|
+
crowdin_id: crowdinId,
|
|
405
|
+
type,
|
|
406
|
+
provider,
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
updateSyncSettings(files, integrationId, crowdinId, type, provider) {
|
|
411
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
412
|
+
yield this.migrationPromise;
|
|
413
|
+
yield this.db
|
|
414
|
+
.update(this.schema.syncSettings)
|
|
415
|
+
.set({ files })
|
|
416
|
+
.where((0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.syncSettings.integration_id, integrationId), (0, drizzle_orm_1.eq)(this.schema.syncSettings.crowdin_id, crowdinId), (0, drizzle_orm_1.eq)(this.schema.syncSettings.type, type), (0, drizzle_orm_1.eq)(this.schema.syncSettings.provider, provider)));
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
getSyncSettings(integrationId, crowdinId, type, provider) {
|
|
420
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
421
|
+
yield this.migrationPromise;
|
|
422
|
+
const item = yield this.db.query.syncSettings.findFirst({
|
|
423
|
+
where: (0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.syncSettings.integration_id, integrationId), (0, drizzle_orm_1.eq)(this.schema.syncSettings.crowdin_id, crowdinId), (0, drizzle_orm_1.eq)(this.schema.syncSettings.type, type), (0, drizzle_orm_1.eq)(this.schema.syncSettings.provider, provider)),
|
|
424
|
+
});
|
|
425
|
+
if (!item) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
return {
|
|
429
|
+
id: item.id,
|
|
430
|
+
files: item.files,
|
|
431
|
+
integrationId: item.integration_id,
|
|
432
|
+
crowdinId: item.crowdin_id,
|
|
433
|
+
type: item.type,
|
|
434
|
+
provider: item.provider,
|
|
435
|
+
};
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
saveFilesSnapshot(files, integrationId, crowdinId, provider) {
|
|
439
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
440
|
+
yield this.migrationPromise;
|
|
441
|
+
yield this.db.insert(this.schema.filesSnapshot).values({
|
|
442
|
+
files,
|
|
443
|
+
integration_id: integrationId,
|
|
444
|
+
crowdin_id: crowdinId,
|
|
445
|
+
provider,
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
updateFilesSnapshot(files, integrationId, crowdinId, provider) {
|
|
450
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
451
|
+
yield this.migrationPromise;
|
|
452
|
+
yield this.db
|
|
453
|
+
.update(this.schema.filesSnapshot)
|
|
454
|
+
.set({ files })
|
|
455
|
+
.where((0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.filesSnapshot.integration_id, integrationId), (0, drizzle_orm_1.eq)(this.schema.filesSnapshot.crowdin_id, crowdinId), (0, drizzle_orm_1.eq)(this.schema.filesSnapshot.provider, provider)));
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
getFilesSnapshot(integrationId, crowdinId, provider) {
|
|
459
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
460
|
+
yield this.migrationPromise;
|
|
461
|
+
const item = yield this.db.query.filesSnapshot.findFirst({
|
|
462
|
+
where: (0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.filesSnapshot.integration_id, integrationId), (0, drizzle_orm_1.eq)(this.schema.filesSnapshot.crowdin_id, crowdinId), (0, drizzle_orm_1.eq)(this.schema.filesSnapshot.provider, provider)),
|
|
463
|
+
});
|
|
464
|
+
if (!item) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
return {
|
|
468
|
+
id: item.id,
|
|
469
|
+
files: item.files,
|
|
470
|
+
integrationId: item.integration_id,
|
|
471
|
+
crowdinId: item.crowdin_id,
|
|
472
|
+
provider: item.provider,
|
|
473
|
+
};
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
getAllWebhooks(integrationId, crowdinId, provider) {
|
|
477
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
478
|
+
yield this.migrationPromise;
|
|
479
|
+
const items = yield this.db.query.webhooks.findMany({
|
|
480
|
+
where: (0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.webhooks.integration_id, integrationId), (0, drizzle_orm_1.eq)(this.schema.webhooks.crowdin_id, crowdinId), (0, drizzle_orm_1.eq)(this.schema.webhooks.provider, provider)),
|
|
481
|
+
});
|
|
482
|
+
return items.map((item) => ({
|
|
483
|
+
id: item.id,
|
|
484
|
+
fileId: item.file_id,
|
|
485
|
+
integrationId: item.integration_id,
|
|
486
|
+
crowdinId: item.crowdin_id,
|
|
487
|
+
provider: item.provider,
|
|
488
|
+
}));
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
getWebhooks(fileId, integrationId, crowdinId, provider) {
|
|
492
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
493
|
+
yield this.migrationPromise;
|
|
494
|
+
const item = yield this.db.query.webhooks.findFirst({
|
|
495
|
+
where: (0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.webhooks.file_id, fileId), (0, drizzle_orm_1.eq)(this.schema.webhooks.integration_id, integrationId), (0, drizzle_orm_1.eq)(this.schema.webhooks.crowdin_id, crowdinId), (0, drizzle_orm_1.eq)(this.schema.webhooks.provider, provider)),
|
|
496
|
+
});
|
|
497
|
+
if (!item) {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
return {
|
|
501
|
+
id: item.id,
|
|
502
|
+
fileId: item.file_id,
|
|
503
|
+
integrationId: item.integration_id,
|
|
504
|
+
crowdinId: item.crowdin_id,
|
|
505
|
+
provider: item.provider,
|
|
506
|
+
};
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
saveWebhooks(fileId, integrationId, crowdinId, provider) {
|
|
510
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
511
|
+
yield this.migrationPromise;
|
|
512
|
+
yield this.db.insert(this.schema.webhooks).values({
|
|
513
|
+
file_id: fileId,
|
|
514
|
+
integration_id: integrationId,
|
|
515
|
+
crowdin_id: crowdinId,
|
|
516
|
+
provider,
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
deleteWebhooks(fileIds, integrationId, crowdinId, provider) {
|
|
521
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
522
|
+
yield this.migrationPromise;
|
|
523
|
+
yield this.db
|
|
524
|
+
.delete(this.schema.webhooks)
|
|
525
|
+
.where((0, drizzle_orm_1.and)((0, drizzle_orm_1.inArray)(this.schema.webhooks.file_id, fileIds), (0, drizzle_orm_1.eq)(this.schema.webhooks.integration_id, integrationId), (0, drizzle_orm_1.eq)(this.schema.webhooks.crowdin_id, crowdinId), (0, drizzle_orm_1.eq)(this.schema.webhooks.provider, provider)));
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
getAllUserErrors(crowdinId, integrationId) {
|
|
529
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
530
|
+
yield this.migrationPromise;
|
|
531
|
+
const whereClause = integrationId
|
|
532
|
+
? (0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.userErrors.crowdin_id, crowdinId), (0, drizzle_orm_1.eq)(this.schema.userErrors.integration_id, integrationId))
|
|
533
|
+
: (0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.userErrors.crowdin_id, crowdinId), (0, drizzle_orm_1.isNull)(this.schema.userErrors.integration_id));
|
|
534
|
+
const items = yield this.db.query.userErrors.findMany({ where: whereClause });
|
|
535
|
+
return items.map((item) => ({
|
|
536
|
+
id: item.id,
|
|
537
|
+
action: item.action,
|
|
538
|
+
message: item.message,
|
|
539
|
+
data: item.data,
|
|
540
|
+
createdAt: item.created_at,
|
|
541
|
+
crowdinId: item.crowdin_id,
|
|
542
|
+
integrationId: item.integration_id,
|
|
543
|
+
}));
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
saveUserError(action, message, data, createdAt, crowdinId, integrationId) {
|
|
547
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
548
|
+
yield this.migrationPromise;
|
|
549
|
+
yield this.db.insert(this.schema.userErrors).values({
|
|
550
|
+
action,
|
|
551
|
+
message,
|
|
552
|
+
data,
|
|
553
|
+
created_at: createdAt,
|
|
554
|
+
crowdin_id: crowdinId,
|
|
555
|
+
integration_id: integrationId,
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
deleteUserErrors(createdAt, crowdinId, integrationId) {
|
|
560
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
561
|
+
yield this.migrationPromise;
|
|
562
|
+
const whereClause = integrationId
|
|
563
|
+
? (0, drizzle_orm_1.and)((0, drizzle_orm_1.lt)(this.schema.userErrors.created_at, createdAt), (0, drizzle_orm_1.eq)(this.schema.userErrors.crowdin_id, crowdinId), (0, drizzle_orm_1.eq)(this.schema.userErrors.integration_id, integrationId))
|
|
564
|
+
: (0, drizzle_orm_1.and)((0, drizzle_orm_1.lt)(this.schema.userErrors.created_at, createdAt), (0, drizzle_orm_1.eq)(this.schema.userErrors.crowdin_id, crowdinId), (0, drizzle_orm_1.isNull)(this.schema.userErrors.integration_id));
|
|
565
|
+
yield this.db.delete(this.schema.userErrors).where(whereClause);
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
deleteAllUsersErrorsOlderThan(createdAt) {
|
|
569
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
570
|
+
yield this.migrationPromise;
|
|
571
|
+
yield this.db.delete(this.schema.userErrors).where((0, drizzle_orm_1.lt)(this.schema.userErrors.created_at, createdAt));
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
saveIntegrationConfig(integrationId, crowdinId, config) {
|
|
575
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
576
|
+
yield this.migrationPromise;
|
|
577
|
+
yield this.db.insert(this.schema.integrationSettings).values({
|
|
578
|
+
integration_id: integrationId,
|
|
579
|
+
crowdin_id: crowdinId,
|
|
580
|
+
config,
|
|
581
|
+
});
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
getAllIntegrationConfigs(crowdinId) {
|
|
585
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
586
|
+
yield this.migrationPromise;
|
|
587
|
+
const items = yield this.db.query.integrationSettings.findMany({
|
|
588
|
+
where: (0, drizzle_orm_1.eq)(this.schema.integrationSettings.crowdin_id, crowdinId),
|
|
589
|
+
});
|
|
590
|
+
return items.map((item) => ({
|
|
591
|
+
id: item.id,
|
|
592
|
+
integrationId: item.integration_id,
|
|
593
|
+
crowdinId: item.crowdin_id,
|
|
594
|
+
config: item.config,
|
|
595
|
+
}));
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
getIntegrationConfig(integrationId) {
|
|
599
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
600
|
+
yield this.migrationPromise;
|
|
601
|
+
const item = yield this.db.query.integrationSettings.findFirst({
|
|
602
|
+
where: (0, drizzle_orm_1.eq)(this.schema.integrationSettings.integration_id, integrationId),
|
|
603
|
+
});
|
|
604
|
+
if (!item) {
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
return {
|
|
608
|
+
id: item.id,
|
|
609
|
+
integrationId: item.integration_id,
|
|
610
|
+
crowdinId: item.crowdin_id,
|
|
611
|
+
config: item.config,
|
|
612
|
+
};
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
updateIntegrationConfig(integrationId, config) {
|
|
616
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
617
|
+
yield this.migrationPromise;
|
|
618
|
+
yield this.db
|
|
619
|
+
.update(this.schema.integrationSettings)
|
|
620
|
+
.set({ config })
|
|
621
|
+
.where((0, drizzle_orm_1.eq)(this.schema.integrationSettings.integration_id, integrationId));
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
createJob(params) {
|
|
625
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
626
|
+
var _a;
|
|
627
|
+
yield this.migrationPromise;
|
|
628
|
+
const id = (0, crypto_1.randomUUID)();
|
|
629
|
+
yield this.db.insert(this.schema.job).values({
|
|
630
|
+
id: id,
|
|
631
|
+
integration_id: params.integrationId,
|
|
632
|
+
crowdin_id: params.crowdinId,
|
|
633
|
+
type: params.type,
|
|
634
|
+
payload: params.payload,
|
|
635
|
+
title: params.title,
|
|
636
|
+
initiated_by: (_a = params.initiatedBy) !== null && _a !== void 0 ? _a : null,
|
|
637
|
+
created_at: Date.now().toString(),
|
|
638
|
+
});
|
|
639
|
+
return id;
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
updateJob(params) {
|
|
643
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
644
|
+
yield this.migrationPromise;
|
|
645
|
+
const values = { updated_at: Date.now().toString() };
|
|
646
|
+
if (params.progress) {
|
|
647
|
+
values.progress = Math.round(params.progress);
|
|
648
|
+
if (params.progress >= 100) {
|
|
649
|
+
values.finished_at = Date.now().toString();
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
if (params.status) {
|
|
653
|
+
values.status = params.status;
|
|
654
|
+
if (!values.finished_at && [types_1.JobStatus.FAILED, types_1.JobStatus.CANCELED].includes(params.status)) {
|
|
655
|
+
values.finished_at = Date.now().toString();
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
if (params.data) {
|
|
659
|
+
values.data = params.data;
|
|
660
|
+
}
|
|
661
|
+
if (params.info) {
|
|
662
|
+
values.info = params.info;
|
|
663
|
+
}
|
|
664
|
+
if (params.attempt) {
|
|
665
|
+
values.attempt = params.attempt;
|
|
666
|
+
}
|
|
667
|
+
if (params.errors) {
|
|
668
|
+
values.errors = JSON.stringify(params.errors);
|
|
669
|
+
}
|
|
670
|
+
if (params.processedEntities) {
|
|
671
|
+
values.processed_entities = params.processedEntities;
|
|
672
|
+
}
|
|
673
|
+
yield this.db.update(this.schema.job).set(values).where((0, drizzle_orm_1.eq)(this.schema.job.id, params.id));
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
getJob(params) {
|
|
677
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
678
|
+
yield this.migrationPromise;
|
|
679
|
+
const item = yield this.db.query.job.findFirst({
|
|
680
|
+
where: (0, drizzle_orm_1.eq)(this.schema.job.id, params.id),
|
|
681
|
+
});
|
|
682
|
+
if (!item) {
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
return {
|
|
686
|
+
id: item.id,
|
|
687
|
+
integrationId: item.integration_id,
|
|
688
|
+
crowdinId: item.crowdin_id,
|
|
689
|
+
type: item.type,
|
|
690
|
+
payload: item.payload,
|
|
691
|
+
progress: item.progress,
|
|
692
|
+
status: item.status,
|
|
693
|
+
title: item.title,
|
|
694
|
+
info: item.info,
|
|
695
|
+
data: item.data,
|
|
696
|
+
attempt: item.attempt,
|
|
697
|
+
errors: item.errors,
|
|
698
|
+
processedEntities: item.processed_entities,
|
|
699
|
+
initiatedBy: item.initiated_by,
|
|
700
|
+
createdAt: this.toNumber(item.created_at),
|
|
701
|
+
updatedAt: this.toNumber(item.updated_at),
|
|
702
|
+
finishedAt: this.toNumber(item.finished_at),
|
|
703
|
+
};
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
getActiveJobs(params) {
|
|
707
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
708
|
+
yield this.migrationPromise;
|
|
709
|
+
const items = yield this.db.query.job.findMany({
|
|
710
|
+
where: (0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.job.integration_id, params.integrationId), (0, drizzle_orm_1.eq)(this.schema.job.crowdin_id, params.crowdinId), (0, drizzle_orm_1.isNull)(this.schema.job.finished_at)),
|
|
711
|
+
});
|
|
712
|
+
return items.map((item) => ({
|
|
713
|
+
id: item.id,
|
|
714
|
+
integrationId: item.integration_id,
|
|
715
|
+
crowdinId: item.crowdin_id,
|
|
716
|
+
type: item.type,
|
|
717
|
+
payload: item.payload,
|
|
718
|
+
progress: item.progress,
|
|
719
|
+
status: item.status,
|
|
720
|
+
title: item.title,
|
|
721
|
+
info: item.info,
|
|
722
|
+
data: item.data,
|
|
723
|
+
attempt: item.attempt,
|
|
724
|
+
errors: item.errors,
|
|
725
|
+
processedEntities: item.processed_entities,
|
|
726
|
+
initiatedBy: item.initiated_by,
|
|
727
|
+
createdAt: this.toNumber(item.created_at),
|
|
728
|
+
updatedAt: this.toNumber(item.updated_at),
|
|
729
|
+
finishedAt: this.toNumber(item.finished_at),
|
|
730
|
+
}));
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
deleteFinishedJobs() {
|
|
734
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
735
|
+
yield this.migrationPromise;
|
|
736
|
+
yield this.db.delete(this.schema.job).where((0, drizzle_orm_1.isNotNull)(this.schema.job.finished_at));
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
getAllInProgressJobs() {
|
|
740
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
741
|
+
yield this.migrationPromise;
|
|
742
|
+
const items = yield this.db.query.job.findMany({
|
|
743
|
+
where: (0, drizzle_orm_1.and)((0, drizzle_orm_1.isNull)(this.schema.job.finished_at), (0, drizzle_orm_1.inArray)(this.schema.job.status, [types_1.JobStatus.IN_PROGRESS, types_1.JobStatus.CREATED])),
|
|
744
|
+
});
|
|
745
|
+
return items.map((item) => ({
|
|
746
|
+
id: item.id,
|
|
747
|
+
integrationId: item.integration_id,
|
|
748
|
+
crowdinId: item.crowdin_id,
|
|
749
|
+
type: item.type,
|
|
750
|
+
payload: item.payload,
|
|
751
|
+
progress: item.progress,
|
|
752
|
+
status: item.status,
|
|
753
|
+
title: item.title,
|
|
754
|
+
info: item.info,
|
|
755
|
+
data: item.data,
|
|
756
|
+
attempt: item.attempt,
|
|
757
|
+
errors: item.errors,
|
|
758
|
+
processedEntities: item.processed_entities,
|
|
759
|
+
initiatedBy: item.initiated_by,
|
|
760
|
+
createdAt: this.toNumber(item.created_at),
|
|
761
|
+
updatedAt: this.toNumber(item.updated_at),
|
|
762
|
+
finishedAt: this.toNumber(item.finished_at),
|
|
763
|
+
}));
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
getAllJobs(params) {
|
|
767
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
768
|
+
yield this.migrationPromise;
|
|
769
|
+
const items = yield this.db.query.job.findMany({
|
|
770
|
+
where: (0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.job.integration_id, params.integrationId), (0, drizzle_orm_1.eq)(this.schema.job.crowdin_id, params.crowdinId)),
|
|
771
|
+
orderBy: (0, drizzle_orm_1.desc)(this.schema.job.created_at),
|
|
772
|
+
limit: params.limit,
|
|
773
|
+
offset: params.offset,
|
|
774
|
+
});
|
|
775
|
+
return items.map((item) => ({
|
|
776
|
+
id: item.id,
|
|
777
|
+
integrationId: item.integration_id,
|
|
778
|
+
crowdinId: item.crowdin_id,
|
|
779
|
+
type: item.type,
|
|
780
|
+
payload: item.payload,
|
|
781
|
+
progress: item.progress,
|
|
782
|
+
status: item.status,
|
|
783
|
+
title: item.title,
|
|
784
|
+
info: item.info,
|
|
785
|
+
data: item.data,
|
|
786
|
+
attempt: item.attempt,
|
|
787
|
+
errors: item.errors,
|
|
788
|
+
processedEntities: item.processed_entities,
|
|
789
|
+
initiatedBy: item.initiated_by,
|
|
790
|
+
createdAt: this.toNumber(item.created_at),
|
|
791
|
+
updatedAt: this.toNumber(item.updated_at),
|
|
792
|
+
finishedAt: this.toNumber(item.finished_at),
|
|
793
|
+
}));
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
saveTranslationCache(params) {
|
|
797
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
798
|
+
yield this.migrationPromise;
|
|
799
|
+
yield this.db.insert(this.schema.translationFileCache).values({
|
|
800
|
+
integration_id: params.integrationId,
|
|
801
|
+
crowdin_id: params.crowdinId,
|
|
802
|
+
file_id: params.fileId,
|
|
803
|
+
language_id: params.languageId,
|
|
804
|
+
etag: params.etag,
|
|
805
|
+
});
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
getFileTranslationCache(params) {
|
|
809
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
810
|
+
yield this.migrationPromise;
|
|
811
|
+
const items = yield this.db.query.translationFileCache.findMany({
|
|
812
|
+
where: (0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.translationFileCache.integration_id, params.integrationId), (0, drizzle_orm_1.eq)(this.schema.translationFileCache.crowdin_id, params.crowdinId), (0, drizzle_orm_1.eq)(this.schema.translationFileCache.file_id, params.fileId)),
|
|
813
|
+
});
|
|
814
|
+
return items.map((item) => ({
|
|
815
|
+
integrationId: item.integration_id,
|
|
816
|
+
crowdinId: item.crowdin_id,
|
|
817
|
+
fileId: item.file_id,
|
|
818
|
+
languageId: item.language_id,
|
|
819
|
+
etag: item.etag,
|
|
820
|
+
}));
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
getFileTranslationCacheByLanguage(params) {
|
|
824
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
825
|
+
yield this.migrationPromise;
|
|
826
|
+
const item = yield this.db.query.translationFileCache.findFirst({
|
|
827
|
+
where: (0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.translationFileCache.integration_id, params.integrationId), (0, drizzle_orm_1.eq)(this.schema.translationFileCache.crowdin_id, params.crowdinId), (0, drizzle_orm_1.eq)(this.schema.translationFileCache.file_id, params.fileId), (0, drizzle_orm_1.eq)(this.schema.translationFileCache.language_id, params.languageId)),
|
|
828
|
+
});
|
|
829
|
+
if (!item) {
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
return {
|
|
833
|
+
integrationId: item.integration_id,
|
|
834
|
+
crowdinId: item.crowdin_id,
|
|
835
|
+
fileId: item.file_id,
|
|
836
|
+
languageId: item.language_id,
|
|
837
|
+
etag: item.etag,
|
|
838
|
+
};
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
updateTranslationCache(params) {
|
|
842
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
843
|
+
yield this.migrationPromise;
|
|
844
|
+
yield this.db
|
|
845
|
+
.update(this.schema.translationFileCache)
|
|
846
|
+
.set({ etag: params.etag })
|
|
847
|
+
.where((0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.translationFileCache.integration_id, params.integrationId), (0, drizzle_orm_1.eq)(this.schema.translationFileCache.crowdin_id, params.crowdinId), (0, drizzle_orm_1.eq)(this.schema.translationFileCache.file_id, params.fileId), (0, drizzle_orm_1.eq)(this.schema.translationFileCache.language_id, params.languageId)));
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
saveUnsyncedFiles(params) {
|
|
851
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
852
|
+
yield this.migrationPromise;
|
|
853
|
+
yield this.db.insert(this.schema.unsyncedFiles).values({
|
|
854
|
+
integration_id: params.integrationId,
|
|
855
|
+
crowdin_id: params.crowdinId,
|
|
856
|
+
files: params.files,
|
|
857
|
+
});
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
getUnsyncedFiles(params) {
|
|
861
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
862
|
+
yield this.migrationPromise;
|
|
863
|
+
const item = yield this.db.query.unsyncedFiles.findFirst({
|
|
864
|
+
where: (0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.unsyncedFiles.integration_id, params.integrationId), (0, drizzle_orm_1.eq)(this.schema.unsyncedFiles.crowdin_id, params.crowdinId)),
|
|
865
|
+
});
|
|
866
|
+
if (!item) {
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
return {
|
|
870
|
+
integrationId: item.integration_id,
|
|
871
|
+
crowdinId: item.crowdin_id,
|
|
872
|
+
files: item.files,
|
|
873
|
+
};
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
updateUnsyncedFiles(params) {
|
|
877
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
878
|
+
yield this.migrationPromise;
|
|
879
|
+
yield this.db
|
|
880
|
+
.update(this.schema.unsyncedFiles)
|
|
881
|
+
.set({ files: params.files })
|
|
882
|
+
.where((0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.unsyncedFiles.integration_id, params.integrationId), (0, drizzle_orm_1.eq)(this.schema.unsyncedFiles.crowdin_id, params.crowdinId)));
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
saveSyncedData(files, integrationId, crowdinId, type) {
|
|
886
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
887
|
+
yield this.migrationPromise;
|
|
888
|
+
yield this.db.insert(this.schema.syncedData).values({
|
|
889
|
+
integration_id: integrationId,
|
|
890
|
+
crowdin_id: crowdinId,
|
|
891
|
+
files: files,
|
|
892
|
+
type: type,
|
|
893
|
+
updated_at: Date.now().toString(),
|
|
894
|
+
});
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
updateSyncedData(files, integrationId, crowdinId, type) {
|
|
898
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
899
|
+
yield this.migrationPromise;
|
|
900
|
+
yield this.db
|
|
901
|
+
.update(this.schema.syncedData)
|
|
902
|
+
.set({ files: files, updated_at: Date.now().toString() })
|
|
903
|
+
.where((0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.syncedData.integration_id, integrationId), (0, drizzle_orm_1.eq)(this.schema.syncedData.crowdin_id, crowdinId), (0, drizzle_orm_1.eq)(this.schema.syncedData.type, type)));
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
getSyncedData(integrationId, crowdinId, type) {
|
|
907
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
908
|
+
yield this.migrationPromise;
|
|
909
|
+
const item = yield this.db.query.syncedData.findFirst({
|
|
910
|
+
where: (0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(this.schema.syncedData.integration_id, integrationId), (0, drizzle_orm_1.eq)(this.schema.syncedData.crowdin_id, crowdinId), (0, drizzle_orm_1.eq)(this.schema.syncedData.type, type)),
|
|
911
|
+
});
|
|
912
|
+
if (!item) {
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
return {
|
|
916
|
+
integrationId: item.integration_id,
|
|
917
|
+
crowdinId: item.crowdin_id,
|
|
918
|
+
files: item.files,
|
|
919
|
+
type: item.type,
|
|
920
|
+
};
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
toString(val) {
|
|
924
|
+
if (!val) {
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
return `${val}`;
|
|
928
|
+
}
|
|
929
|
+
toNumber(val) {
|
|
930
|
+
if (!val) {
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
if (typeof val === 'number') {
|
|
934
|
+
return val;
|
|
935
|
+
}
|
|
936
|
+
return Number(val);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
exports.DrizzleStorage = DrizzleStorage;
|