1 | import * as minioVendor from "minio";
|
2 | import * as postgresVendor from "postgres";
|
3 | import { queries } from "./src/generated/index.js";
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export const minio: typeof minioVendor;
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | export const postgres: typeof postgresVendor;
|
14 |
|
15 | export type Postgres = postgresVendor.Sql<{}>;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | export function newMinioClient(
|
22 | options: minioVendor.ClientOptions,
|
23 | ): minioVendor.Client;
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | export function ensureBucket(
|
29 | minio: minioVendor.Client,
|
30 | bucketName: string,
|
31 | region: minioVendor.Region,
|
32 | ): Promise<void>;
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | export function removeBucket(
|
38 | minio: minioVendor.Client,
|
39 | bucketName: string,
|
40 | ): Promise<void>;
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | export function listObjects(
|
47 | minio: minioVendor.Client,
|
48 | bucketName: string,
|
49 | filter?: string,
|
50 | ): Promise<
|
51 | {
|
52 | name: string;
|
53 | prefix: string;
|
54 | size: number;
|
55 | etag: string;
|
56 | lastModified: Date;
|
57 | }[]
|
58 | >;
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | export function copyAllObjects(
|
64 | minio: minioVendor.Client,
|
65 | sourceBucket: string,
|
66 | destinationBucket: string,
|
67 | ): Promise<void>;
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | export function removeBucketAndObjectsInBucket(
|
73 | minio: minioVendor.Client,
|
74 | bucketName: string,
|
75 | ): Promise<void>;
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | export function newPostgresConnection(
|
84 | opts?: postgresVendor.Options<{}> & { createIfNotExists?: boolean },
|
85 | ): Promise<Postgres>;
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | export function setPostgresDatabaseTemplate(
|
93 | databaseNameOrConnection: Postgres | string,
|
94 | ): Promise<void>;
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | export function cleanupPostgresDatabaseTemplate(): Promise<void>;
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | export function createTestPostgresDatabase(
|
106 | verboseSql?: boolean,
|
107 | ): Promise<Postgres>;
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | export function cleanupTestPostgresDatabase(sql: Postgres): Promise<void>;
|
113 |
|
114 |
|
115 |
|
116 |
|
117 | export interface MigrateFile {
|
118 | namespace: string;
|
119 | number: number;
|
120 | repeatable: boolean;
|
121 | name: string;
|
122 | fullPath: string;
|
123 | isMigrated: boolean;
|
124 | source: string;
|
125 | hash: string;
|
126 | }
|
127 |
|
128 |
|
129 |
|
130 |
|
131 | export interface MigrateContext {
|
132 | files: MigrateFile[];
|
133 | namespaces: string[];
|
134 | storedHashes: Record<string, string>;
|
135 | sql: Postgres;
|
136 | }
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | export function newMigrateContext(sql: Postgres): Promise<MigrateContext>;
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 | export function getMigrationsToBeApplied(
|
149 | mc: MigrateContext,
|
150 | ): false | { name: string; number: number; repeatable: boolean }[];
|
151 |
|
152 |
|
153 |
|
154 |
|
155 | export function runMigrations(mc: MigrateContext): Promise<void>;
|
156 |
|
157 | export interface StoreFile {
|
158 | id: string;
|
159 | bucketName: string;
|
160 | contentLength: number;
|
161 | contentType: string;
|
162 | name: string;
|
163 | createdAt: Date;
|
164 | updatedAt: Date;
|
165 | }
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 | export function createOrUpdateFile(
|
173 | sql: Postgres,
|
174 | minio: minioVendor.Client,
|
175 | bucketName: string,
|
176 | props: {
|
177 | id?: string;
|
178 | bucketName?: string;
|
179 | contentLength?: number;
|
180 | contentType?: string;
|
181 | name: string;
|
182 | createdAt?: string;
|
183 | updatedAt?: string;
|
184 | },
|
185 | streamOrPath: string | NodeJS.ReadStream,
|
186 | ): Promise<StoreFile>;
|
187 |
|
188 |
|
189 |
|
190 |
|
191 | export function syncDeletedFiles(
|
192 | sql: Postgres,
|
193 | minio: minioVendor.Client,
|
194 | bucketName: string,
|
195 | );
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | export function copyFile(
|
201 | sql: Postgres,
|
202 | minio: minioVendor.Client,
|
203 | bucketName: string,
|
204 | id: string,
|
205 | targetBucket?: string,
|
206 | ): Promise<StoreFile>;
|
207 |
|
208 |
|
209 |
|
210 |
|
211 | export function getFileStream(
|
212 | minio: minioVendor.Client,
|
213 | bucketName: string,
|
214 | id: string,
|
215 | range?: { start?: number; end?: number },
|
216 | ): Promise<NodeJS.ReadStream>;
|
217 |
|
218 | export interface FileGroup {
|
219 | id: string;
|
220 | name?: string;
|
221 | order: number;
|
222 | meta: {};
|
223 | file?: string;
|
224 | parent?: string;
|
225 | createdAt: Date;
|
226 | updatedAt: Date;
|
227 | deletedAt: Date;
|
228 | }
|
229 |
|
230 | export interface NestedFileGroup {
|
231 | id: string;
|
232 | name?: string;
|
233 | order: number;
|
234 | meta: {};
|
235 | parent?: string;
|
236 | isDirectory: boolean;
|
237 | file?:
|
238 | | {
|
239 | id: string;
|
240 | bucketName?: string;
|
241 | contentLength?: number;
|
242 | contentType?: string;
|
243 | name?: string;
|
244 | createdAt?: string;
|
245 | updatedAt?: string;
|
246 | }
|
247 | | undefined
|
248 | | string;
|
249 | createdAt: Date;
|
250 | updatedAt: Date;
|
251 | deletedAt: Date;
|
252 | children?: NestedFileGroup[];
|
253 | }
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 | export function hoistChildrenToParent(
|
260 | sql: Postgres,
|
261 | fileGroup: FileGroup,
|
262 | ): Promise<FileGroup[]>;
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 | export function updateFileGroupOrder(
|
269 | sql: Postgres,
|
270 | ids: string[],
|
271 | ): Promise<void>;
|
272 |
|
273 |
|
274 |
|
275 |
|
276 | export function getNestedFileGroups(
|
277 | sql: Postgres,
|
278 | where?: {
|
279 | deletedAtIncludeNotNull?: boolean;
|
280 | rootId?: string;
|
281 | excludeFiles?: boolean;
|
282 | },
|
283 | ): Promise<NestedFileGroup[]>;
|
284 |
|
285 | export interface FileCacheOptions {
|
286 | |
287 |
|
288 |
|
289 | inMemoryThreshold?: number;
|
290 |
|
291 | |
292 |
|
293 |
|
294 | cacheControlHeader?: string;
|
295 | }
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 | export class FileCache {
|
308 | static fileCachePath: string;
|
309 |
|
310 | constructor(
|
311 | sql: Postgres,
|
312 | minio: minioVendor.Client,
|
313 | bucketName: string,
|
314 | options?: FileCacheOptions,
|
315 | );
|
316 |
|
317 | /**
|
318 | * Get a file(part) from the cache.
|
319 | * If the file(part) does not exist, it will try to fetch it from the FileStore
|
320 | * If the file store throws an error / it doesn't exist, the error is propagated to the
|
321 | * caller
|
322 | */
|
323 | public getStreamFn: (
|
324 | file: StoreFile,
|
325 | start?: number,
|
326 | end?: number,
|
327 | ) => Promise<{ stream: NodeJS.ReadStream; cacheControl: string }>;
|
328 |
|
329 | |
330 |
|
331 |
|
332 | clear(fileId: string): void;
|
333 | }
|
334 |
|
335 |
|
336 |
|
337 |
|
338 | export interface JobData {
|
339 | id: number;
|
340 | createdAt: Date;
|
341 | scheduledAt: Date;
|
342 | name: string;
|
343 | data: any;
|
344 | }
|
345 |
|
346 |
|
347 |
|
348 |
|
349 | export interface JobInput {
|
350 | |
351 |
|
352 |
|
353 | priority?: number;
|
354 |
|
355 | |
356 |
|
357 |
|
358 | data?: Record<string, any>;
|
359 |
|
360 | |
361 |
|
362 |
|
363 | scheduledAt?: Date;
|
364 |
|
365 | name: string;
|
366 | }
|
367 |
|
368 | export interface JobQueueWorkerOptions {
|
369 | handler: (sql: Postgres, data: JobData) => void | Promise<void>;
|
370 |
|
371 | |
372 |
|
373 |
|
374 | pollInterval?: number;
|
375 |
|
376 | |
377 |
|
378 |
|
379 |
|
380 | parallelCount?: number;
|
381 | }
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 | export class JobQueueWorker {
|
388 | constructor(
|
389 | sql: Postgres,
|
390 | nameOrOptions: string | JobQueueWorkerOptions,
|
391 | options?: JobQueueWorkerOptions,
|
392 | );
|
393 |
|
394 | /**
|
395 | * Start the JobQueueWorker
|
396 | */
|
397 | start(): void;
|
398 |
|
399 | /**
|
400 | * Stop the JobQueueWorker
|
401 | * Running jobs will continue to run, but no new jobs are fetched
|
402 | */
|
403 | stop(): void;
|
404 |
|
405 | /**
|
406 | * Get the number of jobs that need to run
|
407 | */
|
408 | pendingQueueSize(): Promise<
|
409 | { pendingCount: number; scheduledCount: number } | undefined
|
410 | >;
|
411 |
|
412 | |
413 |
|
414 |
|
415 |
|
416 | averageTimeToCompletion(startDate: Date, endDate: Date): Promise<number>;
|
417 |
|
418 | |
419 |
|
420 |
|
421 |
|
422 | addJob(job: JobInput): Promise<number>;
|
423 | }
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 | export function addJobToQueue(sql: Postgres, job: JobInput): Promise<number>;
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 | export function addRecurringJobToQueue(
|
440 | sql: Postgres,
|
441 | {
|
442 | name,
|
443 | priority,
|
444 | interval,
|
445 | }: {
|
446 | name: string;
|
447 | priority?: number;
|
448 | interval: {
|
449 | years?: number;
|
450 | months?: number;
|
451 | days?: number;
|
452 | hours?: number;
|
453 | minutes?: number;
|
454 | seconds?: number;
|
455 | };
|
456 | },
|
457 | ): Promise<void>;
|
458 |
|
459 |
|
460 |
|
461 |
|
462 | export interface SessionStore {
|
463 | get(id: string): Promise<object | boolean>;
|
464 |
|
465 | set(id: string, session: object, age: number): Promise<void>;
|
466 |
|
467 | destroy(id: string): Promise<void>;
|
468 |
|
469 | |
470 |
|
471 |
|
472 | clean(): Promise<void>;
|
473 | }
|
474 |
|
475 |
|
476 |
|
477 |
|
478 | export function newSessionStore(sql: Postgres): SessionStore;
|
479 |
|
480 |
|
481 |
|
482 |
|
483 | export const migrations: string;
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 | export const storeStructure: any;
|
490 |
|
491 |
|
492 |
|
493 |
|
494 | export interface QueryPart {
|
495 | strings: string[];
|
496 | values: any[];
|
497 |
|
498 | append(part: QueryPart): QueryPart;
|
499 |
|
500 | exec(sql: Postgres): postgresVendor.PendingQuery<any>;
|
501 | }
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 |
|
517 | export function query(strings: string[], ...values: any[]): QueryPart;
|
518 |
|
519 |
|
520 |
|
521 |
|
522 | export function isQueryObject(value: any): value is QueryPart;
|
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 |
|
529 |
|
530 |
|
531 | export function explainAnalyzeQuery(
|
532 | sql: Postgres,
|
533 | queryPart: QueryPart,
|
534 | options?: { jsonResult?: true },
|
535 | ): Promise<string | any>;
|
536 |
|
537 |
|
538 |
|
539 |
|
540 |
|
541 | export function setStoreQueries(q: typeof queries): void;
|