Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and enable JS build #293

Merged
merged 4 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ [email protected]
IOS_SIMULATOR_ID=iPhone 15 Pro
SWIFT_PATH=swift

ENABLE_TARGET_JS=false
ENABLE_TARGET_JS=true
ENABLE_TARGET_IOS=false
ENABLE_TARGET_IOS_SIMULATOR=true
1,324 changes: 128 additions & 1,196 deletions kotlin-js-store/yarn.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pubnub-kotlin/pubnub-kotlin-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ kotlin {
if (enableJsTarget) {
val jsMain by getting {
dependencies {
implementation(npm("pubnub", "8.2.4"))
implementation(npm("pubnub", "8.2.8"))
}
}
}
Expand Down
78 changes: 78 additions & 0 deletions pubnub-kotlin/pubnub-kotlin-api/config/ktlint/baseline.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<baseline version="1.0">
<file name="src/jsMain/kotlin/Pubnub.d.kt">
<error line="156" column="40" source="standard:comment-wrapping" />
<error line="407" column="15" source="standard:class-naming" />
<error line="423" column="15" source="standard:class-naming" />
<error line="439" column="15" source="standard:class-naming" />
<error line="451" column="15" source="standard:class-naming" />
<error line="459" column="15" source="standard:class-naming" />
<error line="467" column="15" source="standard:class-naming" />
<error line="483" column="15" source="standard:class-naming" />
<error line="496" column="15" source="standard:class-naming" />
<error line="840" column="13" source="standard:property-naming" />
<error line="1023" column="15" source="standard:class-naming" />
<error line="1029" column="15" source="standard:class-naming" />
<error line="1148" column="13" source="standard:property-naming" />
<error line="1154" column="13" source="standard:property-naming" />
<error line="1156" column="13" source="standard:property-naming" />
<error line="1216" column="39" source="standard:comment-wrapping" />
<error line="1301" column="15" source="standard:class-naming" />
<error line="1329" column="42" source="standard:comment-wrapping" />
<error line="1379" column="37" source="standard:comment-wrapping" />
<error line="1400" column="13" source="standard:property-naming" />
<error line="1401" column="13" source="standard:property-naming" />
<error line="1405" column="13" source="standard:property-naming" />
<error line="1406" column="13" source="standard:property-naming" />
<error line="1425" column="9" source="standard:property-naming" />
<error line="1426" column="9" source="standard:property-naming" />
<error line="1427" column="9" source="standard:property-naming" />
<error line="1428" column="9" source="standard:property-naming" />
<error line="1429" column="9" source="standard:property-naming" />
<error line="1430" column="9" source="standard:property-naming" />
<error line="1431" column="9" source="standard:property-naming" />
<error line="1432" column="9" source="standard:property-naming" />
<error line="1433" column="9" source="standard:property-naming" />
<error line="1434" column="9" source="standard:property-naming" />
<error line="1435" column="9" source="standard:property-naming" />
<error line="1436" column="9" source="standard:property-naming" />
<error line="1437" column="9" source="standard:property-naming" />
<error line="1441" column="9" source="standard:property-naming" />
<error line="1442" column="9" source="standard:property-naming" />
<error line="1443" column="9" source="standard:property-naming" />
<error line="1444" column="9" source="standard:property-naming" />
<error line="1445" column="9" source="standard:property-naming" />
<error line="1446" column="9" source="standard:property-naming" />
<error line="1447" column="9" source="standard:property-naming" />
<error line="1448" column="9" source="standard:property-naming" />
<error line="1449" column="9" source="standard:property-naming" />
<error line="1450" column="9" source="standard:property-naming" />
<error line="1451" column="9" source="standard:property-naming" />
<error line="1452" column="9" source="standard:property-naming" />
<error line="1453" column="9" source="standard:property-naming" />
<error line="1454" column="9" source="standard:property-naming" />
<error line="1455" column="9" source="standard:property-naming" />
<error line="1456" column="9" source="standard:property-naming" />
<error line="1457" column="9" source="standard:property-naming" />
<error line="1458" column="9" source="standard:property-naming" />
<error line="1459" column="9" source="standard:property-naming" />
<error line="1460" column="9" source="standard:property-naming" />
<error line="1461" column="9" source="standard:property-naming" />
<error line="1462" column="9" source="standard:property-naming" />
<error line="1463" column="9" source="standard:property-naming" />
<error line="1464" column="9" source="standard:property-naming" />
<error line="1465" column="9" source="standard:property-naming" />
<error line="1466" column="9" source="standard:property-naming" />
<error line="1467" column="9" source="standard:property-naming" />
<error line="1468" column="9" source="standard:property-naming" />
<error line="1469" column="9" source="standard:property-naming" />
<error line="1470" column="9" source="standard:property-naming" />
<error line="1471" column="9" source="standard:property-naming" />
<error line="1472" column="9" source="standard:property-naming" />
<error line="1473" column="9" source="standard:property-naming" />
<error line="1474" column="9" source="standard:property-naming" />
<error line="1475" column="9" source="standard:property-naming" />
<error line="1476" column="9" source="standard:property-naming" />
</file>
<file name="src/jsMain/kotlin/com/pubnub/api/PubNubImpl.kt">
<error line="1115" column="5" source="standard:function-naming" />
<error line="1135" column="5" source="standard:function-naming" />
</file>
</baseline>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.pubnub.kmp.createEventListener
import com.pubnub.test.BaseIntegrationTest
import com.pubnub.test.await
import com.pubnub.test.test
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.yield
import kotlin.test.Ignore
Expand Down Expand Up @@ -66,18 +67,18 @@ class EntitiesTest : BaseIntegrationTest() {
}
assertEquals(channelSet, pubnub.getSubscribedChannels().toSet())

var messageFromSetSubscription: PNMessageResult? = null
var messageFromSetSubscription: CompletableDeferred<PNMessageResult> = CompletableDeferred()
set.addListener(
createEventListener(pubnub, onMessage = { pubNub, pnMessageResult ->
messageFromSetSubscription = pnMessageResult
if (!messageFromSetSubscription.isCompleted) {
messageFromSetSubscription.complete(pnMessageResult)
}
})
)

pubnub.publish(channelName, "some message", shouldStore = false).await()
val receivedMessage = nextMessage()
yield()

assertEquals(receivedMessage, messageFromSetSubscription)
assertEquals(receivedMessage, messageFromSetSubscription.await())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.pubnub.test.integration
import com.pubnub.api.models.consumer.objects.PNPage
import com.pubnub.api.models.consumer.objects.member.PNMember
import com.pubnub.api.models.consumer.objects.member.PNUUIDDetailsLevel
import com.pubnub.kmp.PLATFORM
import com.pubnub.kmp.createCustomObject
import com.pubnub.test.BaseIntegrationTest
import com.pubnub.test.await
Expand Down Expand Up @@ -41,6 +42,10 @@ class MembersTest : BaseIntegrationTest() {

@Test
fun can_set_members_with_status() = runTest(timeout = 10.seconds) {
if (PLATFORM == "JS") {
// TODO JS doesn't have membership status
return@runTest
}
// when
val result = pubnub.setChannelMembers(
channel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class UserMetadataTest : BaseIntegrationTest() {
val message = result.extractedMessage
message as PNSetUUIDMetadataEventMessage
assertEquals(uuid, message.data.id)
assertNull(message.data.name)
assertNull(message.data.name?.value)
assertEquals(externalId, message.data.externalId?.value)
assertEquals(profileUrl, message.data.profileUrl?.value)
assertEquals(email, message.data.email?.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import PubNub.SetChannelMetadataParameters
import PubNub.SetMembershipsParameters
import PubNub.SetUUIDMetadataParameters
import com.pubnub.kmp.JsMap
import com.pubnub.kmp.Optional
import org.khronos.webgl.ArrayBuffer
import org.w3c.files.Blob
import org.w3c.files.File
Expand Down Expand Up @@ -1096,13 +1095,6 @@ open external class PubNub(config: Any /* UUID | UserId */) {
var include: UuidIncludeCustom?
}

interface ChannelMetadataFieldsPartial {
var name: Optional<String>
var description: Optional<String>
var status: Optional<String>
var type: Optional<String>
}

interface ChannelMetadataFieldsNullable {
var name: String?
var description: String?
Expand Down Expand Up @@ -1143,7 +1135,7 @@ open external class PubNub(config: Any /* UUID | UserId */) {
}

interface ChannelMembershipObject : v2ObjectDataOmitId {
var channel: ChannelMetadataObject?
var channel: ChannelMetadataObject

var status: String?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import com.pubnub.api.models.consumer.objects.member.MemberInput
import com.pubnub.api.models.consumer.objects.member.PNUUIDDetailsLevel
import com.pubnub.api.models.consumer.objects.membership.ChannelMembershipInput
import com.pubnub.api.models.consumer.objects.membership.PNChannelDetailsLevel
import com.pubnub.api.utils.PatchValue
import com.pubnub.api.v2.PNConfiguration
import com.pubnub.api.v2.callbacks.EventListener
import com.pubnub.api.v2.callbacks.StatusListener
Expand All @@ -126,11 +127,9 @@ import com.pubnub.api.v2.subscriptions.SubscriptionSet
import com.pubnub.internal.v2.entities.ChannelImpl
import com.pubnub.internal.v2.subscriptions.SubscriptionSetImpl
import com.pubnub.kmp.CustomObject
import com.pubnub.kmp.Optional
import com.pubnub.kmp.Uploadable
import com.pubnub.kmp.createJsObject
import com.pubnub.kmp.toJsMap
import com.pubnub.kmp.toOptional
import kotlin.js.json
import PubNub as PubNubJs

Expand Down Expand Up @@ -171,7 +170,7 @@ class PubNubImpl(private val jsPubNub: PubNubJs) : PubNub {
channel: String,
message: Any,
meta: Any?,
shouldStore: Boolean,
shouldStore: Boolean?,
usePost: Boolean,
replicate: Boolean,
ttl: Int?
Expand All @@ -181,15 +180,15 @@ class PubNubImpl(private val jsPubNub: PubNubJs) : PubNub {
createJsObject {
this.message = message.adjustCollectionTypes()
this.channel = channel
this.storeInHistory = shouldStore
shouldStore?.let { this.storeInHistory = it }
this.meta = meta?.adjustCollectionTypes()
this.sendByPost = usePost
this.ttl = ttl
}
)
}

override fun fire(channel: String, message: Any, meta: Any?, usePost: Boolean, ttl: Int?): Publish {
override fun fire(channel: String, message: Any, meta: Any?, usePost: Boolean): Publish {
return FireImpl(
jsPubNub,
createJsObject {
Expand Down Expand Up @@ -562,11 +561,11 @@ class PubNubImpl(private val jsPubNub: PubNubJs) : PubNub {
createJsObject {
this.channel = channel
this.data = ChannelMetadata(
name.toOptional(),
description.toOptional(),
status.toOptional(),
type.toOptional(),
custom.toOptional()
PatchValue.of(name),
PatchValue.of(description),
PatchValue.of(status),
PatchValue.of(type),
PatchValue.of(custom),
)

this.include = createJsObject<PubNubJs.UuidIncludeCustom> {
Expand Down Expand Up @@ -635,13 +634,13 @@ class PubNubImpl(private val jsPubNub: PubNubJs) : PubNub {
jsPubNub,
createJsObject {
data = UUIDMetadata(
name.toOptional(),
externalId.toOptional(),
profileUrl.toOptional(),
email.toOptional(),
status.toOptional(),
type.toOptional(),
custom.toOptional()
PatchValue.of(name),
PatchValue.of(externalId),
PatchValue.of(profileUrl),
PatchValue.of(email),
PatchValue.of(status),
PatchValue.of(type),
PatchValue.of(custom),
)
this.uuid = uuid

Expand Down Expand Up @@ -1114,38 +1113,38 @@ private fun Any.adjustCollectionTypes(): Any {
}

fun UUIDMetadata(
name: Optional<String?>,
externalId: Optional<String?>,
profileUrl: Optional<String?>,
email: Optional<String?>,
status: Optional<String?>,
type: Optional<String?>,
custom: Optional<Map<String, Any?>?>
name: PatchValue<String?>,
externalId: PatchValue<String?>,
profileUrl: PatchValue<String?>,
email: PatchValue<String?>,
status: PatchValue<String?>,
type: PatchValue<String?>,
custom: PatchValue<Map<String, Any?>?>
): PubNubJs.UUIDMetadata {
val result: PubNubJs.UUIDMetadata = createJsObject()
name.onValue { result.name = it }
externalId.onValue { result.externalId = it }
profileUrl.onValue { result.profileUrl = it }
email.onValue { result.email = it }
status.onValue { result.status = it }
type.onValue { result.type = it }
custom.onValue { result.custom = it?.adjustCollectionTypes()?.unsafeCast<PubNubJs.CustomObject>() }
name.value?.let { result.name = it }
externalId.value?.let { result.externalId = it }
profileUrl.value?.let { result.profileUrl = it }
email.value?.let { result.email = it }
status.value?.let { result.status = it }
type.value?.let { result.type = it }
custom.value?.let { result.custom = it.adjustCollectionTypes().unsafeCast<PubNubJs.CustomObject>() }
return result
}

fun ChannelMetadata(
name: Optional<String?>,
description: Optional<String?>,
status: Optional<String?>,
type: Optional<String?>,
custom: Optional<Map<String, Any?>?>
name: PatchValue<String?>,
description: PatchValue<String?>,
status: PatchValue<String?>,
type: PatchValue<String?>,
custom: PatchValue<Map<String, Any?>?>
): PubNubJs.ChannelMetadata {
val result: PubNubJs.ChannelMetadata = createJsObject()
name.onValue { result.name = it }
description.onValue { result.description = it }
status.onValue { result.status = it }
type.onValue { result.type = it }
custom.onValue { result.custom = it?.adjustCollectionTypes()?.unsafeCast<PubNubJs.CustomObject>() }
name.value?.let { result.name = it }
description.value?.let { result.description = it }
status.value?.let { result.status = it }
type.value?.let { result.type = it }
custom.value?.let { result.custom = it.adjustCollectionTypes().unsafeCast<PubNubJs.CustomObject>() }
return result
}
//
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.pubnub.api.v2.callbacks

import com.pubnub.api.callbacks.Listener

/**
* Implement this interface and pass it into [EventEmitter.addListener] to listen for events from the PubNub real-time
* network.
*/
actual interface EventListener : BaseEventListener
actual interface EventListener : Listener
Loading
Loading