-
Notifications
You must be signed in to change notification settings - Fork 402
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
PublishParameters message type too strict #412
Comments
Thank you for reaching out to us.
Serialization / deserialization expected to be done by user. |
The user can take advantage of According to the new typing, in order to support dynamic objects, the user must walk the entire object tree and convert all properties to RFC 8259 values first. But this is exactly what
Yes, but currently the PubNub JavaScript SDK forces the user to use its internal method of serialization and deserialization. That is, the user must provide a value which will be passed to For example, it the user already had a JSON string from another source, the user must parse the JSON string using Besides being redundant, deserializing and reserializing this way can actually change the message payload because RFC 8259 allows implementations to vary. For example: "This specification allows implementations to set limits on the range and precision of numbers accepted." If the source JSON is |
I still don't understand what is the issue and what redundant calls are done. User provides a valid JSON object or
|
No, users cannot provide a JSON string to
Indeed, if a user were to pass a JSON string to javascript/src/core/endpoints/publish.ts Lines 214 to 221 in c47f202
|
Fix definition of type which represent message actions received from history and list of users which added action of specific type and value to the message. Closes #407 refactor(types): remove indexed signature for publish Remove redundant indexed signature from publish message parameters type definition. Closes #413 refactor(types): add serializable objects to `Payload` type Extend `Payload` type definition with objects which can be serialized by `JSON.stringify` using `toJSON()` methods. Closes #412 refactor(types): aggregate generated types definitions Aggregate multiple types definitions into single type definition type with proper type names and namespaces. Closes #405 #409 #410 refactor(types): add missing Subscribe Event Engine types Add Subscribe Event Engine and Event Listener types to the bundled types definition file. Closes #377
It looks like the
Payload
type used byPublishParameters.message
attempts to ensure the value contains only valid JSON types, but using this type on inputs prevents users from utilizing the JSON serialization layer. Namely, classes/objects with custom JSON serialization viatoJSON()
: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#tojson_behaviorFor example, instances of
Date
. Another example is thatundefined
is not allowed even though JSON serialization excludes those properties automatically.I suggest using
unknown
instead ofPayload
.The workaround is to use the
any
trapdoor which defeats the purpose of the typing entirely.The text was updated successfully, but these errors were encountered: