diff --git a/package.json b/package.json index 9a2b513..e1e369b 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@types/aws-sdk": "^2.7.0", "@types/busboy": "^1.5.0", "@types/express": "^4.17.13", + "@types/google-cloud__datastore": "^1.3.6", "@types/jest": "^27.5.1", "@types/memcached": "^2.2.7", "@types/mongodb": "^4.0.7", diff --git a/src/lib/document-stores/amazon-s3.ts b/src/lib/document-stores/amazon-s3.ts index 77454cc..1e59958 100644 --- a/src/lib/document-stores/amazon-s3.ts +++ b/src/lib/document-stores/amazon-s3.ts @@ -1,5 +1,5 @@ import * as winston from 'winston' -import AWS from 'aws-sdk' +import AWS = require('aws-sdk') import type { AmazonStoreConfig } from 'src/types/config' import { Callback } from 'src/types/callback' import { Store } from '.' diff --git a/src/lib/document-stores/google-datastore.ts b/src/lib/document-stores/google-datastore.ts index 71c331f..d7a4b93 100644 --- a/src/lib/document-stores/google-datastore.ts +++ b/src/lib/document-stores/google-datastore.ts @@ -1,4 +1,4 @@ -import { Datastore, PathType } from '@google-cloud/datastore' +import Datastore = require('@google-cloud/datastore') import * as winston from 'winston' import type { Callback } from 'src/types/callback' @@ -19,7 +19,7 @@ class GoogleDatastoreDocumentStore extends Store { // Save file in a key set = ( - key: PathType, + key: string, data: string, callback: Callback, skipExpire?: boolean @@ -56,13 +56,13 @@ class GoogleDatastoreDocumentStore extends Store { } // Get a file from a key - get = (key: PathType, callback: Callback, skipExpire?: boolean): void => { + get = (key: string, callback: Callback, skipExpire?: boolean): void => { const taskKey = this.datastore.key([this.kind, key]) this.datastore .get(taskKey) .then(entity => { - if (skipExpire || entity[0].expiration == null) { + if (skipExpire || entity[0]?.expiration == null) { callback(entity[0].value) } else if (entity[0].expiration < new Date()) { winston.info('document expired', { @@ -78,7 +78,7 @@ class GoogleDatastoreDocumentStore extends Store { data: [ { name: 'value', - value: entity[0].value, + value: entity[0]?.value, excludeFromIndexes: true }, { @@ -95,7 +95,7 @@ class GoogleDatastoreDocumentStore extends Store { .catch(err => { winston.error('failed to update expiration', { error: err }) }) - callback(entity[0].value) + callback(entity[0]?.value) } }) .catch(err => { diff --git a/src/lib/document-stores/mongo.ts b/src/lib/document-stores/mongo.ts index 6ce52ce..795accd 100644 --- a/src/lib/document-stores/mongo.ts +++ b/src/lib/document-stores/mongo.ts @@ -1,11 +1,13 @@ import * as winston from 'winston' -import { MongoClient } from 'mongodb' +import mongodb = require('mongodb') import type { Callback } from 'src/types/callback' import type { MongoStoreConfig } from 'src/types/config' import { Store } from '.' -type ConnectCallback = (error?: Error, db?: MongoClient) => void +const { MongoClient } = mongodb + +type ConnectCallback = (error?: Error, db?: mongodb.MongoClient) => void class MongoDocumentStore extends Store { connectionUrl: string diff --git a/src/lib/document-stores/postgres.ts b/src/lib/document-stores/postgres.ts index 1f0dd77..a85578c 100644 --- a/src/lib/document-stores/postgres.ts +++ b/src/lib/document-stores/postgres.ts @@ -1,19 +1,21 @@ import * as winston from 'winston' -import { Pool, PoolClient } from 'pg' +import Pg = require('pg') import type { Callback } from 'src/types/callback' import type { PostgresStoreConfig } from 'src/types/config' import { Store } from '.' +const { Pool } = Pg + type ConnectCallback = ( error?: Error, - client?: PoolClient, + client?: Pg.PoolClient, done?: () => void ) => void // A postgres document store class PostgresDocumentStore extends Store { - pool: Pool + pool: Pg.Pool constructor(options: PostgresStoreConfig) { super(options) @@ -23,14 +25,16 @@ class PostgresDocumentStore extends Store { // A connection wrapper safeConnect = (callback: ConnectCallback) => { - this.pool.connect((error: Error, client: PoolClient, done: () => void) => { - if (error) { - winston.error('error connecting to postgres', { error }) - callback(error) - } else { - callback(undefined, client, done) + this.pool.connect( + (error: Error, client: Pg.PoolClient, done: () => void) => { + if (error) { + winston.error('error connecting to postgres', { error }) + callback(error) + } else { + callback(undefined, client, done) + } } - }) + ) } // Get a given key's data diff --git a/src/lib/document-stores/redis.ts b/src/lib/document-stores/redis.ts index 2c1bb79..bc8776b 100644 --- a/src/lib/document-stores/redis.ts +++ b/src/lib/document-stores/redis.ts @@ -1,11 +1,13 @@ import * as winston from 'winston' -import { createClient } from 'redis' -import { bool } from 'aws-sdk/clients/redshiftdata' +import redis = require('redis') + import type { Callback } from 'src/types/callback' import { RedisStoreConfig } from 'src/types/config' import { Store } from '.' -export type RedisClientType = ReturnType +const { createClient } = redis + +export type RedisClientType = ReturnType // For storing in redis // options[type] = redis @@ -68,7 +70,7 @@ class RedisDocumentStore extends Store { }) } - getExpire = (skipExpire?: bool) => (!skipExpire ? { EX: this.expire } : {}) + getExpire = (skipExpire?: boolean) => (!skipExpire ? { EX: this.expire } : {}) get = (key: string, callback: Callback): void => { this.client diff --git a/src/lib/document-stores/rethinkdb.ts b/src/lib/document-stores/rethinkdb.ts index fce44ad..eddff70 100644 --- a/src/lib/document-stores/rethinkdb.ts +++ b/src/lib/document-stores/rethinkdb.ts @@ -1,7 +1,7 @@ import * as winston from 'winston' import * as crypto from 'crypto' -import rethink, { RethinkClient } from 'rethinkdbdash' +import rethink = require('rethinkdbdash') import type { RethinkDbStoreConfig } from 'src/types/config' import type { Callback } from 'src/types/callback' @@ -14,7 +14,7 @@ const md5 = (str: string) => { } class RethinkDBStore extends Store { - client: RethinkClient + client: rethink.RethinkClient constructor(options: RethinkDbStoreConfig) { super(options) diff --git a/yarn.lock b/yarn.lock index 7c1cb5c..be8bd1f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -763,6 +763,13 @@ "@types/minimatch" "*" "@types/node" "*" +"@types/google-cloud__datastore@^1.3.6": + version "1.3.6" + resolved "https://registry.yarnpkg.com/@types/google-cloud__datastore/-/google-cloud__datastore-1.3.6.tgz#33b2c65c1b797279e57ed5ac96966bebb9c6500b" + integrity sha512-92yEN/b5tkdNT+9l0BscP5uUQLk9h+aHH21TkHi7ITbXnRIPBs2lmV5dbmDVKkQRXHLiCdLv0zfk8xgfYqSGpg== + dependencies: + "@types/node" "*" + "@types/graceful-fs@^4.1.3": version "4.1.5" resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.5.tgz#21ffba0d98da4350db64891f92a9e5db3cdb4e15"