From b10c332b64d40e3b1ca20b92f95dcb1954da52f8 Mon Sep 17 00:00:00 2001 From: Rifa Achrinza <25147899+achrinza@users.noreply.github.com> Date: Fri, 10 Apr 2020 13:59:20 +0800 Subject: [PATCH] feat: updates import resolution Updates import resolution to use ES6-style imports and Typescript import/export helpers. Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com> --- functions/src/config.example.ts | 2 +- functions/src/firebaseFunctions.ts | 2 +- functions/src/index.ts | 2 +- functions/src/opentrace/getHandshakePin.ts | 3 +-- functions/src/opentrace/getTempIDs.ts | 2 +- functions/src/opentrace/getUploadToken.ts | 4 ++-- functions/src/opentrace/processUploadedData.ts | 2 +- functions/src/opentrace/types/FunctionConfig.ts | 4 +--- functions/src/opentrace/types/HeartBeatEvent.ts | 4 +--- functions/src/opentrace/types/StreetPassRecord.ts | 4 +--- functions/src/opentrace/utils/Authenticator.ts | 2 +- functions/src/opentrace/utils/CustomEncrypter.ts | 2 +- functions/src/opentrace/utils/formatTimestamp.ts | 4 ++-- functions/test/index.test.ts | 2 +- functions/test/opentrace/config.test.ts | 8 ++++---- functions/tsconfig.json | 8 ++++---- 16 files changed, 24 insertions(+), 31 deletions(-) diff --git a/functions/src/config.example.ts b/functions/src/config.example.ts index c563d1e..cfe9e9f 100644 --- a/functions/src/config.example.ts +++ b/functions/src/config.example.ts @@ -1,4 +1,4 @@ -import FunctionConfig from "./opentrace/types/FunctionConfig"; +import {FunctionConfig} from "./opentrace/types/FunctionConfig"; import Authenticator from "./opentrace/utils/Authenticator"; import PinGenerator from "./opentrace/utils/PinGenerator"; diff --git a/functions/src/firebaseFunctions.ts b/functions/src/firebaseFunctions.ts index 9f4db02..d06f538 100644 --- a/functions/src/firebaseFunctions.ts +++ b/functions/src/firebaseFunctions.ts @@ -1,4 +1,4 @@ -import * as functions from "firebase-functions"; +import functions from "firebase-functions"; import config from "./config"; diff --git a/functions/src/index.ts b/functions/src/index.ts index 9544355..fd3aabc 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -1,4 +1,4 @@ -import * as admin from "firebase-admin"; +import admin from "firebase-admin"; admin.initializeApp(); import * as firebaseFunctions from "./firebaseFunctions"; diff --git a/functions/src/opentrace/getHandshakePin.ts b/functions/src/opentrace/getHandshakePin.ts index 39a6c2c..dd62ef5 100644 --- a/functions/src/opentrace/getHandshakePin.ts +++ b/functions/src/opentrace/getHandshakePin.ts @@ -1,5 +1,4 @@ -import * as functions from "firebase-functions"; - +import functions from "firebase-functions"; import config from "../config"; /** diff --git a/functions/src/opentrace/getTempIDs.ts b/functions/src/opentrace/getTempIDs.ts index aefebef..1c11a41 100644 --- a/functions/src/opentrace/getTempIDs.ts +++ b/functions/src/opentrace/getTempIDs.ts @@ -1,4 +1,4 @@ -import * as moment from "moment"; +import moment from "moment"; import config from "../config"; import CustomEncrypter from "./utils/CustomEncrypter"; diff --git a/functions/src/opentrace/getUploadToken.ts b/functions/src/opentrace/getUploadToken.ts index 34767a5..3c47478 100644 --- a/functions/src/opentrace/getUploadToken.ts +++ b/functions/src/opentrace/getUploadToken.ts @@ -1,5 +1,5 @@ -import * as functions from "firebase-functions"; -import * as admin from "firebase-admin"; +import functions from "firebase-functions"; +import admin from "firebase-admin"; import config from "../config"; import getEncryptionKey from "./utils/getEncryptionKey"; diff --git a/functions/src/opentrace/processUploadedData.ts b/functions/src/opentrace/processUploadedData.ts index 4bec9d1..c634cdd 100644 --- a/functions/src/opentrace/processUploadedData.ts +++ b/functions/src/opentrace/processUploadedData.ts @@ -1,4 +1,4 @@ -import * as functions from "firebase-functions"; +import functions from "firebase-functions"; import {ObjectMetadata} from "firebase-functions/lib/providers/storage"; const processUploadedData = async (object: ObjectMetadata) => { diff --git a/functions/src/opentrace/types/FunctionConfig.ts b/functions/src/opentrace/types/FunctionConfig.ts index 1815bc9..60e3ddb 100644 --- a/functions/src/opentrace/types/FunctionConfig.ts +++ b/functions/src/opentrace/types/FunctionConfig.ts @@ -4,7 +4,7 @@ import PinGenerator from "../utils/PinGenerator"; // SUPPORTED_REGIONS from function-configuration.d.ts declare type SUPPORTED_REGIONS = "us-central1" | "us-east1" | "us-east4" | "europe-west1" | "europe-west2" | "asia-east2" | "asia-northeast1"; -interface FunctionConfig { +export interface FunctionConfig { projectId: string // Firebase Project ID regions: SUPPORTED_REGIONS[] utcOffset: number | string @@ -28,5 +28,3 @@ interface FunctionConfig { bucketForArchive: string } } - -export default FunctionConfig; diff --git a/functions/src/opentrace/types/HeartBeatEvent.ts b/functions/src/opentrace/types/HeartBeatEvent.ts index f4ae4b6..7425230 100644 --- a/functions/src/opentrace/types/HeartBeatEvent.ts +++ b/functions/src/opentrace/types/HeartBeatEvent.ts @@ -1,8 +1,6 @@ -interface HeartBeatEvent { +export interface HeartBeatEvent { timestamp: number, msg?: string, // enhanced fields: timestampString?: string, } - -export default HeartBeatEvent; diff --git a/functions/src/opentrace/types/StreetPassRecord.ts b/functions/src/opentrace/types/StreetPassRecord.ts index 537629a..33a7cd7 100644 --- a/functions/src/opentrace/types/StreetPassRecord.ts +++ b/functions/src/opentrace/types/StreetPassRecord.ts @@ -8,7 +8,7 @@ * Transmission Power txPower * Organization org */ -interface StreetPassRecord { +export interface StreetPassRecord { timestamp: number, msg?: string, modelC: string, @@ -24,5 +24,3 @@ interface StreetPassRecord { contactIdValidFrom?: number, contactIdValidTo?: number, } - -export default StreetPassRecord; diff --git a/functions/src/opentrace/utils/Authenticator.ts b/functions/src/opentrace/utils/Authenticator.ts index 97eeda6..f97c30e 100644 --- a/functions/src/opentrace/utils/Authenticator.ts +++ b/functions/src/opentrace/utils/Authenticator.ts @@ -1,4 +1,4 @@ -import * as functions from "firebase-functions"; +import functions from "firebase-functions"; import {CallableContext} from "firebase-functions/lib/providers/https"; export default class Authenticator { diff --git a/functions/src/opentrace/utils/CustomEncrypter.ts b/functions/src/opentrace/utils/CustomEncrypter.ts index b4fff6b..a748d6a 100644 --- a/functions/src/opentrace/utils/CustomEncrypter.ts +++ b/functions/src/opentrace/utils/CustomEncrypter.ts @@ -1,4 +1,4 @@ -import * as crypto from "crypto"; +import crypto from "crypto"; import config from "../../config"; class CustomEncrypter { diff --git a/functions/src/opentrace/utils/formatTimestamp.ts b/functions/src/opentrace/utils/formatTimestamp.ts index 2ffd6e0..8bce58d 100644 --- a/functions/src/opentrace/utils/formatTimestamp.ts +++ b/functions/src/opentrace/utils/formatTimestamp.ts @@ -2,7 +2,7 @@ * Convert timestamp (expressed in seconds since the Epoch) to "DD-MMM-YYYY HH:mm:ss Z" format * @param timestamp */ -import * as moment from "moment"; +import moment from "moment"; import config from "../../config"; @@ -12,4 +12,4 @@ function formatTimestamp(timestamp: number) { return moment.unix(timestamp).utcOffset(config.utcOffset).format(TIMESTAMP_FORMAT); } -export default formatTimestamp; \ No newline at end of file +export default formatTimestamp; diff --git a/functions/test/index.test.ts b/functions/test/index.test.ts index 678b1d3..fa5f58d 100644 --- a/functions/test/index.test.ts +++ b/functions/test/index.test.ts @@ -1,4 +1,4 @@ -import * as admin from "firebase-admin"; +import admin from "firebase-admin"; import config from "../src/config"; if (!process.env.GOOGLE_APPLICATION_CREDENTIALS) { diff --git a/functions/test/opentrace/config.test.ts b/functions/test/opentrace/config.test.ts index edbd981..f004a46 100644 --- a/functions/test/opentrace/config.test.ts +++ b/functions/test/opentrace/config.test.ts @@ -1,7 +1,7 @@ -import * as admin from "firebase-admin"; -import * as functions from "firebase-functions"; -import * as chai from "chai"; -import * as crypto from "crypto"; +import admin from "firebase-admin"; +import functions from "firebase-functions"; +import chai from "chai"; +import crypto from "crypto"; import config from "../../src/config"; import {FunctionsTestWrapper} from "../index.test"; diff --git a/functions/tsconfig.json b/functions/tsconfig.json index e9cb7d0..b979a87 100644 --- a/functions/tsconfig.json +++ b/functions/tsconfig.json @@ -7,10 +7,10 @@ "skipLibCheck": true, "sourceMap": true, "strict": true, - "target": "es2017" + "target": "es2017", + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "importHelpers": true }, "compileOnSave": true, - "include": [ - "src" - ] }