Overview of the Socket Refactor
SocketInterface
The helper class SocketInterface
has been reworked. Several methods have been deleted (effective immediately) including SocketInterface.trigger()
, SocketInterface.triggerMany()
SocketInterface.handle()
, SocketInterface.handleMany()
. If you were using these methods you will need to refactor your work to either call SocketInterface.dispatch()
OR to simply call game.socket.emit()
directly.
Multi-Entity and Multi-EmbeddedEntity Operations
The createMany
, updateMany
, and deleteMany
methods have been deprecated in favor of greater flexibility in the base create()
, update()
, and delete()
operations.
For example, instead of:
Actor.create(singleActorData, options); // creates one actor
Actor.createMany(arrayOfActorData, options); // creates many actors
You should now just use:
Actor.create(singleActorData, options); // creates one actor
Actor.create(arrayOfActorData, options); // creates many actors
The same holds true for EmbeddedEntity operations:
actor.createEmbeddedEntity("OwnedItem", singleItemData, options); // creates one item
actor.createEmbeddedEntity("OwnedItem", arrayOfItemData, options); // creates many items
Server Side Typescript
Implemented usage of Typescript for the server side database layer to ensure strict validations for all socket and database API contracts.
Hook Standardization
There was previously a disconnect with Hooks where the arguments provided to a hook could be slightly inconsistent depending on whether it was the pre-Hook or the post-Hook as well as whether it was the triggering client or a client receiving the broadcasted response. This was not intended and was a side effect of the previous SocketInterface's design choice which prevented the receiving client from always having the correct context. Database hooks should ALL now follow the same pattern.
Entity Hooks
preCreate<Entity>: [createData, options, userId]
create<Entity>: [entity, options, userId]
preUpdate<Entity>: [entity, updateData, options, userId]
update<Entity>: [entity, updateData, options, userId]
preDelete<Entity>: [entity, options, userId]
delete<Entity>: [entity, options, userId]
Embedded Entity Hooks
preCreate<EmbeddedEntity>: [parent, createData, options, userId]
create<EmbeddedEntity>: [parent, child, options, userId]
preUpdate<EmbeddedEntity>: [parent, child, updateData, options, userId]
update<EmbeddedEntity>: [parent, child, updateData, options, userId]
preDelete<EmbeddedEntity>: [parent, child, options, userId]
delete<EmbeddedEntity>: [parent, child, options, userId]
Callback Functions
The Entity
callback functions have also changed their signatures to remain in parity with the hook definitions. If you are defining a custom Entity class (like an Actor subclass) you will need to update the following method signatures.
_onCreate(data, options, userId)
_onUpdate(data, options, userId);
_onDelete(options, userId);
_onCreateEmbeddedEntity(embeddedName, child, options, userId);
_onUpdateEmbeddedEntity(embeddedName, child, updateData, options, userId);
_onDeleteEmbeddedEntity(embeddedName, child, options, userId);
_onModifyEmbeddedEntity(embeddedName, changes, options, userId, context);
Note that these callback events will run for every entity or embedded entity that is updated through a DB operation.
Socket Namespace Consolidation
Consolidation to modifyDocument
and modifyEmbeddedDocument
socket events - Reduction from 156 named socket events to just 17.
Code Reorganization
Moved Entity and EmbeddedEntity handler definitions out of the Collection class into the Entity class itself. Greatly consolidated the bloat of the various Collection
subclasses.