From aa4f9914efb4846ce85b538a23f1abbd1cca9c2e Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Wed, 9 Feb 2022 15:14:58 -0500 Subject: [PATCH 1/2] fix: use `isolatedModules: true` in tsconfig.json This setting ensures the module can be used in projects where the workflow includes type checking and transpilation as two separate steps. See: https://ncjamieson.com/dont-export-const-enums/ Fixes: https://github.com/cloudevents/sdk-javascript/issues/456 Signed-off-by: Lance Ball --- src/index.ts | 33 +++++++++++++-------------------- src/message/kafka/index.ts | 5 ++++- src/message/mqtt/index.ts | 5 ++--- tsconfig.json | 3 ++- 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/index.ts b/src/index.ts index eea449ad..768a88c1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,31 +16,24 @@ import CONSTANTS from "./constants"; export { // From event - CloudEvent, + CloudEvent, Version, + ValidationError, Mode, HTTP, + Kafka, MQTT, MQTTMessageFactory, emitterFor, + Emitter, + // From Constants + CONSTANTS +}; + +export type { CloudEventV1, CloudEventV1Attributes, - Version, - ValidationError, // From message - Headers, - Mode, - Binding, + Headers, Binding, Message, Deserializer, - Serializer, - HTTP, - Kafka, - KafkaEvent, - KafkaMessage, - MQTT, - MQTTMessage, - MQTTMessageFactory, + Serializer, KafkaEvent, + KafkaMessage, MQTTMessage, // From transport TransportFunction, - EmitterFunction, - emitterFor, - Emitter, - Options, - // From Constants - CONSTANTS, + EmitterFunction, Options }; diff --git a/src/message/kafka/index.ts b/src/message/kafka/index.ts index 13b15f42..85f3eeca 100644 --- a/src/message/kafka/index.ts +++ b/src/message/kafka/index.ts @@ -10,7 +10,10 @@ import { sanitize } from "../http/headers"; // Export the binding implementation and message interface export { - Kafka, + Kafka +}; + +export type { KafkaMessage, KafkaEvent }; diff --git a/src/message/mqtt/index.ts b/src/message/mqtt/index.ts index 3943834f..8f11b6bb 100644 --- a/src/message/mqtt/index.ts +++ b/src/message/mqtt/index.ts @@ -6,10 +6,9 @@ import { Binding, Deserializer, CloudEvent, CloudEventV1, CONSTANTS, Message, ValidationError, Headers } from "../.."; export { - MQTT, - MQTTMessage, - MQTTMessageFactory + MQTT, MQTTMessageFactory }; +export type { MQTTMessage }; /** * Extends the base {@linkcode Message} interface to include MQTT attributes, some of which diff --git a/tsconfig.json b/tsconfig.json index be34da2c..a073e029 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,8 @@ "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */ "outDir": "./dist", "declaration": true, - "experimentalDecorators": true + "experimentalDecorators": true, + "isolatedModules": true, }, "compileOnSave": true, "include": [ From aa926d4b3eb6c4bceecbf59132e7e7267bb77a34 Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Wed, 9 Feb 2022 17:55:55 -0500 Subject: [PATCH 2/2] fixup: formatting Signed-off-by: Lance Ball --- src/index.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 768a88c1..a8fc944e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,9 +16,15 @@ import CONSTANTS from "./constants"; export { // From event - CloudEvent, Version, - ValidationError, Mode, HTTP, - Kafka, MQTT, MQTTMessageFactory, emitterFor, + CloudEvent, + Version, + ValidationError, + Mode, + HTTP, + Kafka, + MQTT, + MQTTMessageFactory, + emitterFor, Emitter, // From Constants CONSTANTS @@ -28,12 +34,16 @@ export type { CloudEventV1, CloudEventV1Attributes, // From message - Headers, Binding, + Headers, + Binding, Message, Deserializer, - Serializer, KafkaEvent, - KafkaMessage, MQTTMessage, + Serializer, + KafkaEvent, + KafkaMessage, + MQTTMessage, // From transport TransportFunction, - EmitterFunction, Options + EmitterFunction, + Options };