@crowdin/app-project-module 0.75.0 → 0.76.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/app-test/integration/update-crowdin.js +2 -0
- package/out/app-test/integration/update-integration.js +2 -0
- package/out/modules/integration/handlers/crowdin-files.js +11 -1
- package/out/modules/integration/handlers/user-errors.js +2 -14
- package/out/modules/integration/types.d.ts +4 -2
- package/out/modules/integration/util/files.d.ts +7 -0
- package/out/modules/integration/util/files.js +44 -1
- package/out/modules/integration/util/job.js +33 -1
- package/out/modules/integration/util/types.d.ts +21 -0
- package/out/storage/index.d.ts +19 -1
- package/out/storage/index.js +38 -34
- package/out/storage/mysql.d.ts +17 -1
- package/out/storage/mysql.js +134 -117
- package/out/storage/postgre.d.ts +17 -1
- package/out/storage/postgre.js +136 -118
- package/out/storage/sqlite.d.ts +17 -1
- package/out/storage/sqlite.js +125 -115
- package/out/types.d.ts +1 -1
- package/out/types.js +1 -1
- package/out/util/index.d.ts +4 -0
- package/out/util/index.js +17 -1
- package/out/views/main.handlebars +39 -38
- package/package.json +1 -1
package/out/storage/mysql.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/* eslint-disable no-unused-expressions */
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
4
4
|
/* eslint-disable @typescript-eslint/ban-ts-ignore */
|
|
5
|
+
/* eslint-disable @typescript-eslint/camelcase */
|
|
5
6
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
7
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
8
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -23,6 +24,100 @@ class MySQLStorage {
|
|
|
23
24
|
this._res = res;
|
|
24
25
|
this._rej = rej;
|
|
25
26
|
});
|
|
27
|
+
this.tables = {
|
|
28
|
+
crowdin_credentials: `(
|
|
29
|
+
id varchar(255) primary key,
|
|
30
|
+
app_secret text,
|
|
31
|
+
domain varchar(255),
|
|
32
|
+
user_id varchar(255),
|
|
33
|
+
agent_id varchar(255),
|
|
34
|
+
organization_id varchar(255),
|
|
35
|
+
base_url varchar(255),
|
|
36
|
+
access_token text not null,
|
|
37
|
+
refresh_token text not null,
|
|
38
|
+
expire varchar(255) not null,
|
|
39
|
+
type varchar(255) not null
|
|
40
|
+
)`,
|
|
41
|
+
integration_credentials: `(
|
|
42
|
+
id varchar(255) primary key,
|
|
43
|
+
credentials text,
|
|
44
|
+
crowdin_id varchar(255) not null,
|
|
45
|
+
managers text
|
|
46
|
+
)`,
|
|
47
|
+
sync_settings: `(
|
|
48
|
+
id int auto_increment primary key,
|
|
49
|
+
files text,
|
|
50
|
+
integration_id varchar(255) not null,
|
|
51
|
+
crowdin_id varchar(255) not null,
|
|
52
|
+
type varchar(255) not null,
|
|
53
|
+
provider varchar(255) not null
|
|
54
|
+
)`,
|
|
55
|
+
app_metadata: `(
|
|
56
|
+
id varchar(255) primary key,
|
|
57
|
+
data text,
|
|
58
|
+
crowdin_id text
|
|
59
|
+
)`,
|
|
60
|
+
files_snapshot: `(
|
|
61
|
+
id int auto_increment primary key,
|
|
62
|
+
files text,
|
|
63
|
+
integration_id varchar(255) not null,
|
|
64
|
+
crowdin_id varchar(255) not null,
|
|
65
|
+
provider varchar(255) not null
|
|
66
|
+
)`,
|
|
67
|
+
webhooks: `(
|
|
68
|
+
id int auto_increment primary key,
|
|
69
|
+
file_id varchar(255) not null,
|
|
70
|
+
integration_id varchar(255) not null,
|
|
71
|
+
crowdin_id varchar(255) not null,
|
|
72
|
+
provider varchar(255) not null
|
|
73
|
+
)`,
|
|
74
|
+
user_errors: `(
|
|
75
|
+
id int auto_increment primary key,
|
|
76
|
+
action varchar(255) not null,
|
|
77
|
+
message varchar(255) not null,
|
|
78
|
+
data text,
|
|
79
|
+
created_at varchar(255) not null,
|
|
80
|
+
crowdin_id varchar(255) not null,
|
|
81
|
+
integration_id varchar(255)
|
|
82
|
+
)`,
|
|
83
|
+
integration_settings: `(
|
|
84
|
+
id int auto_increment primary key,
|
|
85
|
+
integration_id varchar(255) not null,
|
|
86
|
+
crowdin_id varchar(255) not null,
|
|
87
|
+
config text
|
|
88
|
+
)`,
|
|
89
|
+
job: `(
|
|
90
|
+
id varchar(255) not null primary key,
|
|
91
|
+
integration_id varchar(255) not null,
|
|
92
|
+
crowdin_id varchar(255) not null,
|
|
93
|
+
type varchar(255) not null,
|
|
94
|
+
payload text,
|
|
95
|
+
title text,
|
|
96
|
+
progress int 0,
|
|
97
|
+
status varchar(255) '${types_1.JobStatus.CREATED}',
|
|
98
|
+
payload text,
|
|
99
|
+
info text,
|
|
100
|
+
data text,
|
|
101
|
+
attempt int 0,
|
|
102
|
+
created_at varchar(255) not null,
|
|
103
|
+
updated_at varchar(255),
|
|
104
|
+
finished_at varchar(255)
|
|
105
|
+
)`,
|
|
106
|
+
translation_file_cache: `(
|
|
107
|
+
id int auto_increment primary key,
|
|
108
|
+
integration_id varchar(255) not null,
|
|
109
|
+
crowdin_id varchar(255) not null,
|
|
110
|
+
file_id int not null,
|
|
111
|
+
language_id varchar(255) not null,
|
|
112
|
+
etag varchar(255)
|
|
113
|
+
)`,
|
|
114
|
+
unsynced_files: `(
|
|
115
|
+
id int auto_increment primary key,
|
|
116
|
+
integration_id varchar(255) not null,
|
|
117
|
+
crowdin_id varchar(255) not null,
|
|
118
|
+
files text
|
|
119
|
+
)`,
|
|
120
|
+
};
|
|
26
121
|
this.config = config;
|
|
27
122
|
}
|
|
28
123
|
executeQuery(command) {
|
|
@@ -52,7 +147,7 @@ class MySQLStorage {
|
|
|
52
147
|
migrate() {
|
|
53
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
149
|
try {
|
|
55
|
-
yield this.executeQuery(this.addTables);
|
|
150
|
+
yield this.executeQuery((connection) => this.addTables(connection));
|
|
56
151
|
this._res && this._res();
|
|
57
152
|
}
|
|
58
153
|
catch (e) {
|
|
@@ -63,122 +158,9 @@ class MySQLStorage {
|
|
|
63
158
|
}
|
|
64
159
|
addTables(connection) {
|
|
65
160
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
id varchar(255) primary key,
|
|
70
|
-
app_secret text,
|
|
71
|
-
domain varchar(255),
|
|
72
|
-
user_id varchar(255),
|
|
73
|
-
agent_id varchar(255),
|
|
74
|
-
organization_id varchar(255),
|
|
75
|
-
base_url varchar(255),
|
|
76
|
-
access_token text not null,
|
|
77
|
-
refresh_token text not null,
|
|
78
|
-
expire varchar(255) not null,
|
|
79
|
-
type varchar(255) not null
|
|
80
|
-
)
|
|
81
|
-
`);
|
|
82
|
-
yield connection.execute(`
|
|
83
|
-
create table if not exists integration_credentials
|
|
84
|
-
(
|
|
85
|
-
id varchar(255) primary key,
|
|
86
|
-
credentials text,
|
|
87
|
-
crowdin_id varchar(255) not null,
|
|
88
|
-
managers text
|
|
89
|
-
)
|
|
90
|
-
`);
|
|
91
|
-
yield connection.execute(`
|
|
92
|
-
create table if not exists sync_settings
|
|
93
|
-
(
|
|
94
|
-
id int auto_increment primary key,
|
|
95
|
-
files text,
|
|
96
|
-
integration_id varchar(255) not null,
|
|
97
|
-
crowdin_id varchar(255) not null,
|
|
98
|
-
type varchar(255) not null,
|
|
99
|
-
provider varchar(255) not null
|
|
100
|
-
)
|
|
101
|
-
`);
|
|
102
|
-
yield connection.execute(`
|
|
103
|
-
create table if not exists app_metadata
|
|
104
|
-
(
|
|
105
|
-
id varchar(255) primary key,
|
|
106
|
-
data text,
|
|
107
|
-
crowdin_id text
|
|
108
|
-
)
|
|
109
|
-
`);
|
|
110
|
-
yield connection.execute(`
|
|
111
|
-
create table if not exists files_snapshot
|
|
112
|
-
(
|
|
113
|
-
id int auto_increment primary key,
|
|
114
|
-
files text,
|
|
115
|
-
integration_id varchar(255) not null,
|
|
116
|
-
crowdin_id varchar(255) not null,
|
|
117
|
-
provider varchar(255) not null
|
|
118
|
-
)
|
|
119
|
-
`);
|
|
120
|
-
yield connection.execute(`
|
|
121
|
-
create table if not exists webhooks
|
|
122
|
-
(
|
|
123
|
-
id int auto_increment primary key,
|
|
124
|
-
file_id varchar(255) not null,
|
|
125
|
-
integration_id varchar(255) not null,
|
|
126
|
-
crowdin_id varchar(255) not null,
|
|
127
|
-
provider varchar(255) not null
|
|
128
|
-
)
|
|
129
|
-
`);
|
|
130
|
-
yield connection.execute(`
|
|
131
|
-
create table if not exists user_errors
|
|
132
|
-
(
|
|
133
|
-
id int auto_increment primary key,
|
|
134
|
-
action varchar(255) not null,
|
|
135
|
-
message varchar(255) not null,
|
|
136
|
-
data text,
|
|
137
|
-
created_at varchar(255) not null,
|
|
138
|
-
crowdin_id varchar(255) not null,
|
|
139
|
-
integration_id varchar(255)
|
|
140
|
-
)
|
|
141
|
-
`);
|
|
142
|
-
yield connection.execute(`
|
|
143
|
-
create table if not exists integration_settings
|
|
144
|
-
(
|
|
145
|
-
id int auto_increment primary key,
|
|
146
|
-
integration_id varchar(255) not null,
|
|
147
|
-
crowdin_id varchar(255) not null,
|
|
148
|
-
config text
|
|
149
|
-
)
|
|
150
|
-
`);
|
|
151
|
-
yield connection.execute(`
|
|
152
|
-
create table if not exists job
|
|
153
|
-
(
|
|
154
|
-
id varchar(255) not null primary key,
|
|
155
|
-
integration_id varchar(255) not null,
|
|
156
|
-
crowdin_id varchar(255) not null,
|
|
157
|
-
type varchar(255) not null,
|
|
158
|
-
payload text,
|
|
159
|
-
title text,
|
|
160
|
-
progress int 0,
|
|
161
|
-
status varchar(255) '${types_1.JobStatus.CREATED}',
|
|
162
|
-
payload text,
|
|
163
|
-
info text,
|
|
164
|
-
data text,
|
|
165
|
-
attempt int 0,
|
|
166
|
-
created_at varchar(255) not null,
|
|
167
|
-
updated_at varchar(255),
|
|
168
|
-
finished_at varchar(255)
|
|
169
|
-
)
|
|
170
|
-
`);
|
|
171
|
-
yield connection.execute(`
|
|
172
|
-
create table if not exists translation_file_cache
|
|
173
|
-
(
|
|
174
|
-
id int auto_increment primary key,
|
|
175
|
-
integration_id varchar(255) not null,
|
|
176
|
-
crowdin_id varchar(255) not null,
|
|
177
|
-
file_id int not null,
|
|
178
|
-
language_id varchar(255) not null,
|
|
179
|
-
etag varchar(255)
|
|
180
|
-
)
|
|
181
|
-
`);
|
|
161
|
+
for (const [tableName, tableSchema] of Object.entries(this.tables)) {
|
|
162
|
+
yield connection.execute(`create table if not exists ${tableName} ${tableSchema}`);
|
|
163
|
+
}
|
|
182
164
|
});
|
|
183
165
|
}
|
|
184
166
|
saveCrowdinCredentials(credentials) {
|
|
@@ -248,6 +230,7 @@ class MySQLStorage {
|
|
|
248
230
|
yield connection.execute('DELETE FROM integration_settings WHERE crowdin_id = ?', [id]);
|
|
249
231
|
yield connection.execute('DELETE FROM job WHERE crowdin_id = ?', [id]);
|
|
250
232
|
yield connection.execute('DELETE FROM translation_file_cache WHERE crowdin_id = ?', [id]);
|
|
233
|
+
yield connection.execute('DELETE FROM unsynced_files WHERE crowdin_id = ?', [id]);
|
|
251
234
|
}));
|
|
252
235
|
});
|
|
253
236
|
}
|
|
@@ -300,6 +283,7 @@ class MySQLStorage {
|
|
|
300
283
|
yield connection.execute('DELETE FROM files_snapshot where integration_id = ?', [id]);
|
|
301
284
|
yield connection.execute('DELETE FROM webhooks where integration_id = ?', [id]);
|
|
302
285
|
yield connection.execute('DELETE FROM job where integration_id = ?', [id]);
|
|
286
|
+
yield connection.execute('DELETE FROM unsynced_files where integration_id = ?', [id]);
|
|
303
287
|
}));
|
|
304
288
|
});
|
|
305
289
|
}
|
|
@@ -313,6 +297,7 @@ class MySQLStorage {
|
|
|
313
297
|
yield connection.execute('DELETE FROM webhooks where crowdin_id = ?', [crowdinId]);
|
|
314
298
|
yield connection.execute('DELETE FROM user_errors where crowdin_id = ?', [crowdinId]);
|
|
315
299
|
yield connection.execute('DELETE FROM job where crowdin_id = ?', [crowdinId]);
|
|
300
|
+
yield connection.execute('DELETE FROM unsynced_files where crowdin_id = ?', [crowdinId]);
|
|
316
301
|
}));
|
|
317
302
|
});
|
|
318
303
|
}
|
|
@@ -675,5 +660,37 @@ class MySQLStorage {
|
|
|
675
660
|
`, [etag, integrationId, crowdinId, fileId, languageId]));
|
|
676
661
|
});
|
|
677
662
|
}
|
|
663
|
+
saveUnsyncedFiles({ integrationId, crowdinId, files }) {
|
|
664
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
665
|
+
yield this.dbPromise;
|
|
666
|
+
yield this.executeQuery((connection) => connection.execute(`
|
|
667
|
+
INSERT INTO unsynced_files(integration_id, crowdin_id, files)
|
|
668
|
+
VALUES (?, ?, ?,)
|
|
669
|
+
`, [integrationId, crowdinId, files]));
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
updateUnsyncedFiles({ integrationId, crowdinId, files }) {
|
|
673
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
674
|
+
yield this.dbPromise;
|
|
675
|
+
yield this.executeQuery((connection) => connection.execute(`
|
|
676
|
+
UPDATE unsynced_files
|
|
677
|
+
SET files = ?
|
|
678
|
+
WHERE integration_id = ? AND crowdin_id = ?
|
|
679
|
+
`, [files, integrationId, crowdinId]));
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
getUnsyncedFiles({ integrationId, crowdinId }) {
|
|
683
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
684
|
+
yield this.dbPromise;
|
|
685
|
+
return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
|
|
686
|
+
const [rows] = yield connection.execute(`
|
|
687
|
+
SELECT fileIds
|
|
688
|
+
FROM unsynced_files
|
|
689
|
+
WHERE integration_id = ? AND crowdin_id = ?
|
|
690
|
+
`, [integrationId, crowdinId]);
|
|
691
|
+
return (rows || [])[0];
|
|
692
|
+
}));
|
|
693
|
+
});
|
|
694
|
+
}
|
|
678
695
|
}
|
|
679
696
|
exports.MySQLStorage = MySQLStorage;
|
package/out/storage/postgre.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Client } from 'pg';
|
|
|
2
2
|
import { Storage } from '.';
|
|
3
3
|
import { CrowdinCredentials } from '../types';
|
|
4
4
|
import { IntegrationConfig, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks } from '../modules/integration/types';
|
|
5
|
-
import { CreateJobParams, GetActiveJobsParams, GetJobParams, GetFileTranslationCacheByLanguageParams, Job, TranslationCache, UpdateJobParams, UpdateTranslationCacheParams, GetFileTranslationCache } from '../modules/integration/util/types';
|
|
5
|
+
import { CreateJobParams, GetActiveJobsParams, GetJobParams, GetFileTranslationCacheByLanguageParams, Job, TranslationCache, UpdateJobParams, UpdateTranslationCacheParams, GetFileTranslationCache, UnsyncedFiles, GetUnsyncedFiles } from '../modules/integration/util/types';
|
|
6
6
|
import { UserErrors } from './types';
|
|
7
7
|
export interface PostgreStorageConfig {
|
|
8
8
|
host?: string;
|
|
@@ -22,6 +22,19 @@ export declare class PostgreStorage implements Storage {
|
|
|
22
22
|
private _res?;
|
|
23
23
|
private _rej?;
|
|
24
24
|
private dbPromise;
|
|
25
|
+
tables: {
|
|
26
|
+
crowdin_credentials: string;
|
|
27
|
+
integration_credentials: string;
|
|
28
|
+
sync_settings: string;
|
|
29
|
+
app_metadata: string;
|
|
30
|
+
files_snapshot: string;
|
|
31
|
+
webhooks: string;
|
|
32
|
+
user_errors: string;
|
|
33
|
+
integration_settings: string;
|
|
34
|
+
job: string;
|
|
35
|
+
translation_file_cache: string;
|
|
36
|
+
unsynced_files: string;
|
|
37
|
+
};
|
|
25
38
|
constructor(config: PostgreStorageConfig, directoryPath: string | null);
|
|
26
39
|
executeQuery<T>(command: (client: Client) => Promise<T>): Promise<T>;
|
|
27
40
|
migrate(): Promise<void>;
|
|
@@ -77,4 +90,7 @@ export declare class PostgreStorage implements Storage {
|
|
|
77
90
|
getFileTranslationCacheByLanguage({ integrationId, crowdinId, fileId, languageId, }: GetFileTranslationCacheByLanguageParams): Promise<TranslationCache | undefined>;
|
|
78
91
|
updateTranslationCache({ integrationId, crowdinId, fileId, languageId, etag, }: UpdateTranslationCacheParams): Promise<void>;
|
|
79
92
|
private migrateFromSqlite;
|
|
93
|
+
saveUnsyncedFiles({ integrationId, crowdinId, files }: UnsyncedFiles): Promise<void>;
|
|
94
|
+
updateUnsyncedFiles({ integrationId, crowdinId, files }: UnsyncedFiles): Promise<void>;
|
|
95
|
+
getUnsyncedFiles({ integrationId, crowdinId }: GetUnsyncedFiles): Promise<UnsyncedFiles | undefined>;
|
|
80
96
|
}
|
package/out/storage/postgre.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable no-unused-expressions */
|
|
3
|
+
/* eslint-disable @typescript-eslint/camelcase */
|
|
3
4
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
5
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
6
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -27,6 +28,99 @@ class PostgreStorage {
|
|
|
27
28
|
this._res = res;
|
|
28
29
|
this._rej = rej;
|
|
29
30
|
});
|
|
31
|
+
this.tables = {
|
|
32
|
+
crowdin_credentials: `(
|
|
33
|
+
id varchar primary key,
|
|
34
|
+
app_secret varchar,
|
|
35
|
+
domain varchar,
|
|
36
|
+
user_id varchar,
|
|
37
|
+
agent_id varchar,
|
|
38
|
+
organization_id varchar,
|
|
39
|
+
base_url varchar,
|
|
40
|
+
access_token varchar not null,
|
|
41
|
+
refresh_token varchar not null,
|
|
42
|
+
expire varchar not null,
|
|
43
|
+
type varchar not null
|
|
44
|
+
)`,
|
|
45
|
+
integration_credentials: `(
|
|
46
|
+
id varchar primary key,
|
|
47
|
+
credentials varchar,
|
|
48
|
+
crowdin_id varchar not null,
|
|
49
|
+
managers varchar
|
|
50
|
+
)`,
|
|
51
|
+
sync_settings: `(
|
|
52
|
+
id serial primary key,
|
|
53
|
+
files varchar,
|
|
54
|
+
integration_id varchar not null,
|
|
55
|
+
crowdin_id varchar not null,
|
|
56
|
+
type varchar not null,
|
|
57
|
+
provider varchar not null
|
|
58
|
+
)`,
|
|
59
|
+
app_metadata: `(
|
|
60
|
+
id varchar primary key,
|
|
61
|
+
data varchar,
|
|
62
|
+
crowdin_id varchar
|
|
63
|
+
)`,
|
|
64
|
+
files_snapshot: `(
|
|
65
|
+
id serial primary key,
|
|
66
|
+
integration_id varchar not null,
|
|
67
|
+
crowdin_id varchar not null,
|
|
68
|
+
files varchar,
|
|
69
|
+
provider varchar not null
|
|
70
|
+
)`,
|
|
71
|
+
webhooks: `(
|
|
72
|
+
id serial primary key,
|
|
73
|
+
file_id varchar not null,
|
|
74
|
+
integration_id varchar not null,
|
|
75
|
+
crowdin_id varchar not null,
|
|
76
|
+
provider varchar not null
|
|
77
|
+
)`,
|
|
78
|
+
user_errors: `(
|
|
79
|
+
id serial primary key,
|
|
80
|
+
action varchar not null,
|
|
81
|
+
message varchar not null,
|
|
82
|
+
data varchar,
|
|
83
|
+
created_at varchar not null,
|
|
84
|
+
crowdin_id varchar not null,
|
|
85
|
+
integration_id varchar
|
|
86
|
+
)`,
|
|
87
|
+
integration_settings: `(
|
|
88
|
+
id serial primary key,
|
|
89
|
+
integration_id varchar not null,
|
|
90
|
+
crowdin_id varchar not null,
|
|
91
|
+
config varchar
|
|
92
|
+
)`,
|
|
93
|
+
job: `(
|
|
94
|
+
id varchar not null primary key,
|
|
95
|
+
integration_id varchar not null,
|
|
96
|
+
crowdin_id varchar not null,
|
|
97
|
+
type varchar not null,
|
|
98
|
+
title varchar null,
|
|
99
|
+
progress int default 0,
|
|
100
|
+
status varchar default '${types_2.JobStatus.CREATED}',
|
|
101
|
+
payload varchar null,
|
|
102
|
+
info varchar null,
|
|
103
|
+
data varchar null,
|
|
104
|
+
attempt int default 0,
|
|
105
|
+
created_at varchar not null,
|
|
106
|
+
updated_at varchar null,
|
|
107
|
+
finished_at varchar null
|
|
108
|
+
)`,
|
|
109
|
+
translation_file_cache: `(
|
|
110
|
+
id serial primary key,
|
|
111
|
+
integration_id varchar not null,
|
|
112
|
+
crowdin_id varchar not null,
|
|
113
|
+
file_id int not null,
|
|
114
|
+
language_id varchar not null,
|
|
115
|
+
etag varchar
|
|
116
|
+
)`,
|
|
117
|
+
unsynced_files: `(
|
|
118
|
+
id serial primary key,
|
|
119
|
+
integration_id varchar not null,
|
|
120
|
+
crowdin_id varchar not null,
|
|
121
|
+
files varchar
|
|
122
|
+
)`,
|
|
123
|
+
};
|
|
30
124
|
this.config = config;
|
|
31
125
|
this.directoryPath = directoryPath;
|
|
32
126
|
}
|
|
@@ -58,7 +152,7 @@ class PostgreStorage {
|
|
|
58
152
|
if (this.directoryPath && fs_1.default.existsSync(this.directoryPath)) {
|
|
59
153
|
yield this.migrateFromSqlite(this.directoryPath);
|
|
60
154
|
}
|
|
61
|
-
yield this.executeQuery(this.addTables);
|
|
155
|
+
yield this.executeQuery((client) => this.addTables(client));
|
|
62
156
|
this._res && this._res();
|
|
63
157
|
// TODO: temporary code
|
|
64
158
|
yield this.executeQuery((client) => this.alterTables(client));
|
|
@@ -102,121 +196,9 @@ class PostgreStorage {
|
|
|
102
196
|
}
|
|
103
197
|
addTables(client) {
|
|
104
198
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
id varchar primary key,
|
|
109
|
-
app_secret varchar,
|
|
110
|
-
domain varchar,
|
|
111
|
-
user_id varchar,
|
|
112
|
-
agent_id varchar,
|
|
113
|
-
organization_id varchar,
|
|
114
|
-
base_url varchar,
|
|
115
|
-
access_token varchar not null,
|
|
116
|
-
refresh_token varchar not null,
|
|
117
|
-
expire varchar not null,
|
|
118
|
-
type varchar not null
|
|
119
|
-
)
|
|
120
|
-
`);
|
|
121
|
-
yield client.query(`
|
|
122
|
-
create table if not exists integration_credentials
|
|
123
|
-
(
|
|
124
|
-
id varchar primary key,
|
|
125
|
-
credentials varchar,
|
|
126
|
-
crowdin_id varchar not null,
|
|
127
|
-
managers varchar
|
|
128
|
-
)
|
|
129
|
-
`);
|
|
130
|
-
yield client.query(`
|
|
131
|
-
create table if not exists sync_settings
|
|
132
|
-
(
|
|
133
|
-
id serial primary key,
|
|
134
|
-
files varchar,
|
|
135
|
-
integration_id varchar not null,
|
|
136
|
-
crowdin_id varchar not null,
|
|
137
|
-
type varchar not null,
|
|
138
|
-
provider varchar not null
|
|
139
|
-
)
|
|
140
|
-
`);
|
|
141
|
-
yield client.query(`
|
|
142
|
-
create table if not exists app_metadata
|
|
143
|
-
(
|
|
144
|
-
id varchar primary key,
|
|
145
|
-
data varchar,
|
|
146
|
-
crowdin_id varchar
|
|
147
|
-
)
|
|
148
|
-
`);
|
|
149
|
-
yield client.query(`
|
|
150
|
-
create table if not exists files_snapshot
|
|
151
|
-
(
|
|
152
|
-
id serial primary key,
|
|
153
|
-
integration_id varchar not null,
|
|
154
|
-
crowdin_id varchar not null,
|
|
155
|
-
files varchar,
|
|
156
|
-
provider varchar not null
|
|
157
|
-
)
|
|
158
|
-
`);
|
|
159
|
-
yield client.query(`
|
|
160
|
-
create table if not exists webhooks
|
|
161
|
-
(
|
|
162
|
-
id serial primary key,
|
|
163
|
-
file_id varchar not null,
|
|
164
|
-
integration_id varchar not null,
|
|
165
|
-
crowdin_id varchar not null,
|
|
166
|
-
provider varchar not null
|
|
167
|
-
)
|
|
168
|
-
`);
|
|
169
|
-
yield client.query(`
|
|
170
|
-
create table if not exists user_errors
|
|
171
|
-
(
|
|
172
|
-
id serial primary key,
|
|
173
|
-
action varchar not null,
|
|
174
|
-
message varchar not null,
|
|
175
|
-
data varchar,
|
|
176
|
-
created_at varchar not null,
|
|
177
|
-
crowdin_id varchar not null,
|
|
178
|
-
integration_id varchar
|
|
179
|
-
)
|
|
180
|
-
`);
|
|
181
|
-
yield client.query(`
|
|
182
|
-
create table if not exists integration_settings
|
|
183
|
-
(
|
|
184
|
-
id serial primary key,
|
|
185
|
-
integration_id varchar not null,
|
|
186
|
-
crowdin_id varchar not null,
|
|
187
|
-
config varchar
|
|
188
|
-
)
|
|
189
|
-
`);
|
|
190
|
-
yield client.query(`
|
|
191
|
-
create table if not exists job
|
|
192
|
-
(
|
|
193
|
-
id varchar not null primary key,
|
|
194
|
-
integration_id varchar not null,
|
|
195
|
-
crowdin_id varchar not null,
|
|
196
|
-
type varchar not null,
|
|
197
|
-
title varchar null,
|
|
198
|
-
progress int default 0,
|
|
199
|
-
status varchar default '${types_2.JobStatus.CREATED}',
|
|
200
|
-
payload varchar null,
|
|
201
|
-
info varchar null,
|
|
202
|
-
data varchar null,
|
|
203
|
-
attempt int default 0,
|
|
204
|
-
created_at varchar not null,
|
|
205
|
-
updated_at varchar null,
|
|
206
|
-
finished_at varchar null
|
|
207
|
-
)
|
|
208
|
-
`);
|
|
209
|
-
yield client.query(`
|
|
210
|
-
create table if not exists translation_file_cache
|
|
211
|
-
(
|
|
212
|
-
id serial primary key,
|
|
213
|
-
integration_id varchar not null,
|
|
214
|
-
crowdin_id varchar not null,
|
|
215
|
-
file_id int not null,
|
|
216
|
-
language_id varchar not null,
|
|
217
|
-
etag varchar
|
|
218
|
-
)
|
|
219
|
-
`);
|
|
199
|
+
for (const [tableName, tableSchema] of Object.entries(this.tables)) {
|
|
200
|
+
yield client.query(`create table if not exists ${tableName} ${tableSchema}`);
|
|
201
|
+
}
|
|
220
202
|
});
|
|
221
203
|
}
|
|
222
204
|
saveCrowdinCredentials(credentials) {
|
|
@@ -286,6 +268,7 @@ class PostgreStorage {
|
|
|
286
268
|
yield client.query('DELETE FROM integration_settings WHERE crowdin_id = $1', [id]);
|
|
287
269
|
yield client.query('DELETE FROM job WHERE crowdin_id = $1', [id]);
|
|
288
270
|
yield client.query('DELETE FROM translation_file_cache WHERE crowdin_id = $1', [id]);
|
|
271
|
+
yield client.query('DELETE FROM unsynced_files WHERE crowdin_id = $1', [id]);
|
|
289
272
|
}));
|
|
290
273
|
});
|
|
291
274
|
}
|
|
@@ -338,6 +321,7 @@ class PostgreStorage {
|
|
|
338
321
|
yield client.query('DELETE FROM files_snapshot where integration_id = $1', [id]);
|
|
339
322
|
yield client.query('DELETE FROM webhooks where integration_id = $1', [id]);
|
|
340
323
|
yield client.query('DELETE FROM job where integration_id = $1', [id]);
|
|
324
|
+
yield client.query('DELETE FROM unsynced_files where integration_id = $1', [id]);
|
|
341
325
|
}));
|
|
342
326
|
});
|
|
343
327
|
}
|
|
@@ -351,6 +335,7 @@ class PostgreStorage {
|
|
|
351
335
|
yield client.query('DELETE FROM webhooks where crowdin_id = $1', [crowdinId]);
|
|
352
336
|
yield client.query('DELETE FROM user_errors where crowdin_id = $1', [crowdinId]);
|
|
353
337
|
yield client.query('DELETE FROM job where crowdin_id = $1', [crowdinId]);
|
|
338
|
+
yield client.query('DELETE FROM unsynced_files where crowdin_id = $1', [crowdinId]);
|
|
354
339
|
}));
|
|
355
340
|
});
|
|
356
341
|
}
|
|
@@ -721,7 +706,7 @@ class PostgreStorage {
|
|
|
721
706
|
}
|
|
722
707
|
migrateFromSqlite(directoryPath) {
|
|
723
708
|
return __awaiter(this, void 0, void 0, function* () {
|
|
724
|
-
const [name, extension] = types_1.storageFiles.
|
|
709
|
+
const [name, extension] = types_1.storageFiles.DUMP.split('%s');
|
|
725
710
|
const files = fs_1.default
|
|
726
711
|
.readdirSync(directoryPath)
|
|
727
712
|
.filter((file) => file.startsWith(name) && file.endsWith(extension))
|
|
@@ -736,10 +721,43 @@ class PostgreStorage {
|
|
|
736
721
|
catch (e) {
|
|
737
722
|
console.error('Error while executing', file);
|
|
738
723
|
console.error(e);
|
|
739
|
-
fs_1.default.renameSync(filePath, filePath.replace('
|
|
724
|
+
fs_1.default.renameSync(filePath, filePath.replace('dump_table_', 'error_dump_table_'));
|
|
740
725
|
}
|
|
741
726
|
}
|
|
742
727
|
});
|
|
743
728
|
}
|
|
729
|
+
saveUnsyncedFiles({ integrationId, crowdinId, files }) {
|
|
730
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
731
|
+
yield this.dbPromise;
|
|
732
|
+
yield this.executeQuery((client) => client.query(`
|
|
733
|
+
INSERT
|
|
734
|
+
INTO unsynced_files(integration_id, crowdin_id, files)
|
|
735
|
+
VALUES ($1, $2, $3,)
|
|
736
|
+
`, [integrationId, crowdinId, files]));
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
updateUnsyncedFiles({ integrationId, crowdinId, files }) {
|
|
740
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
741
|
+
yield this.dbPromise;
|
|
742
|
+
yield this.executeQuery((client) => client.query(`
|
|
743
|
+
UPDATE unsynced_files
|
|
744
|
+
SET files = $1
|
|
745
|
+
WHERE integration_id = $2 AND crowdin_id = $3
|
|
746
|
+
`, [files, integrationId, crowdinId]));
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
getUnsyncedFiles({ integrationId, crowdinId }) {
|
|
750
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
751
|
+
yield this.dbPromise;
|
|
752
|
+
return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
|
|
753
|
+
const res = yield client.query(`
|
|
754
|
+
SELECT files
|
|
755
|
+
FROM unsynced_files
|
|
756
|
+
WHERE integration_id = $1 AND crowdin_id = $2
|
|
757
|
+
`, [integrationId, crowdinId]);
|
|
758
|
+
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
759
|
+
}));
|
|
760
|
+
});
|
|
761
|
+
}
|
|
744
762
|
}
|
|
745
763
|
exports.PostgreStorage = PostgreStorage;
|
package/out/storage/sqlite.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Storage } from '.';
|
|
2
2
|
import { CrowdinCredentials } from '../types';
|
|
3
3
|
import { IntegrationConfig, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks } from '../modules/integration/types';
|
|
4
|
-
import { CreateJobParams, GetActiveJobsParams, GetJobParams, GetFileTranslationCacheByLanguageParams, Job, TranslationCache, UpdateJobParams, UpdateTranslationCacheParams, GetFileTranslationCache } from '../modules/integration/util/types';
|
|
4
|
+
import { CreateJobParams, GetActiveJobsParams, GetJobParams, GetFileTranslationCacheByLanguageParams, Job, TranslationCache, UpdateJobParams, UpdateTranslationCacheParams, GetFileTranslationCache, UnsyncedFiles, GetUnsyncedFiles } from '../modules/integration/util/types';
|
|
5
5
|
import { UserErrors } from './types';
|
|
6
6
|
export interface SQLiteStorageConfig {
|
|
7
7
|
dbFolder: string;
|
|
@@ -12,6 +12,19 @@ export declare class SQLiteStorage implements Storage {
|
|
|
12
12
|
private _rej?;
|
|
13
13
|
private dbPromise;
|
|
14
14
|
private config;
|
|
15
|
+
tables: {
|
|
16
|
+
crowdin_credentials: string;
|
|
17
|
+
integration_credentials: string;
|
|
18
|
+
sync_settings: string;
|
|
19
|
+
app_metadata: string;
|
|
20
|
+
files_snapshot: string;
|
|
21
|
+
webhooks: string;
|
|
22
|
+
user_errors: string;
|
|
23
|
+
integration_settings: string;
|
|
24
|
+
job: string;
|
|
25
|
+
translation_file_cache: string;
|
|
26
|
+
unsynced_files: string;
|
|
27
|
+
};
|
|
15
28
|
constructor(config: SQLiteStorageConfig);
|
|
16
29
|
private _run;
|
|
17
30
|
private run;
|
|
@@ -71,4 +84,7 @@ export declare class SQLiteStorage implements Storage {
|
|
|
71
84
|
getFileTranslationCache({ integrationId, crowdinId, fileId, }: GetFileTranslationCache): Promise<TranslationCache[] | undefined>;
|
|
72
85
|
getFileTranslationCacheByLanguage({ integrationId, crowdinId, fileId, languageId, }: GetFileTranslationCacheByLanguageParams): Promise<TranslationCache | undefined>;
|
|
73
86
|
updateTranslationCache({ integrationId, crowdinId, fileId, languageId, etag, }: UpdateTranslationCacheParams): Promise<void>;
|
|
87
|
+
saveUnsyncedFiles({ integrationId, crowdinId, files }: UnsyncedFiles): Promise<void>;
|
|
88
|
+
updateUnsyncedFiles({ integrationId, crowdinId, files }: UnsyncedFiles): Promise<void>;
|
|
89
|
+
getUnsyncedFiles({ integrationId, crowdinId }: GetUnsyncedFiles): Promise<UnsyncedFiles | undefined>;
|
|
74
90
|
}
|