Module: @socketdb/core
Interfaces
Functions
createBatchedClient
▸ createBatchedClient<Events
>(connection
, interval?
): Object
Type parameters
Name | Type |
---|---|
Events | extends GenericEvents |
Parameters
Name | Type |
---|---|
connection | Socket |
interval? | number |
Returns
Object
Name | Type |
---|---|
queue | <K>(event : K , data : Events [K ]) => void |
sendImmediately | <K>(event : K , data : Events [K ]) => void |
subscribe | <K>(event : K , callback : (data : Events [K ]) => void ) => () => void |
unsubscribe | <K>(event : K , callback? : (data : Events [K ]) => void ) => void |
Defined in
lib/batchedSocketEvents.ts:14
createEventBroker
▸ createEventBroker<Events
>(): Object
Type parameters
Name | Type |
---|---|
Events | extends Object = { [event: string] : unknown ; } |
Returns
Object
Name | Type |
---|---|
addListener | <Key>(event : Key , listener : Listener <Events [Key ]>) => () => void |
notify | <Key>(event : Key , data : Events [Key ]) => void |
removeListener | <Key>(event : Key , listener? : Listener <Events [Key ]>) => void |
Defined in
lib/socket-connection/eventBroker.ts:1
createStore
▸ createStore(): Store
Returns
Defined in
lib/store.ts:11
createSubscriptionManager
▸ createSubscriptionManager<DataType
>(«destructured»
): Object
manages client side subscriptions to the server
- manages listeners to various paths
- manages sending subscription requests to the server
- keeps amount of subscriptions to a minimum to prevent redundant update packets
Type parameters
Name | Type |
---|---|
DataType | any |
Parameters
Name | Type |
---|---|
«destructured» | Object |
› createPathSubscription | (path : NormalizedPath , notify : (data : DataType | () => DataType , options? : { excludeSelf? : boolean ; recursiveDown? : boolean ; recursiveUp? : boolean }) => void ) => void |
› destroySubscription | (path : NormalizedPath ) => void |
› restoreSubscription | (path : NormalizedPath ) => void |
Returns
Object
Name | Type |
---|---|
notify | (path : NormalizedPath , data : DataType | (path : string ) => DataType , options : { excludeSelf? : boolean ; recursiveDown? : boolean ; recursiveUp? : boolean }) => void |
resubscribe | () => void |
subscribe | (path : NormalizedPath , callback : (data : DataType ) => void , fromCache? : () => null | DataType ) => () => void |
unsubscribe | (path : NormalizedPath , callback : (data : DataType ) => void ) => void |
Defined in
lib/subscriptionManager.ts:12
createUpdateBatcher
▸ createUpdateBatcher(flushUpdate
, updateInterval
): Queue
<Change
| Deletion
>
Parameters
Name | Type |
---|---|
flushUpdate | (batchedUpdate : BatchedUpdate ) => void |
updateInterval | number |
Returns
Queue
<Change
| Deletion
>
Defined in
lib/updateBatcher.ts:22
deepClone
▸ deepClone<T
>(source
): T
Deeply clones arrays and objects.
In most cases, you should use simpleDeepClone instead, which is about 3x faster.
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
source | T |
Returns
T
Defined in
lib/utils.ts:36
hasChildNodes
▸ hasChildNodes(node?
): node is Node<Json>
Parameters
Name | Type |
---|---|
node? | Node <any > |
Returns
node is Node<Json>
Defined in
lib/node.ts:66
isChildPath
▸ isChildPath<Parent
>(path
, parentPath
): path is `${Parent}/${string}`
Type parameters
Name | Type |
---|---|
Parent | extends string |
Parameters
Name | Type |
---|---|
path | string |
parentPath | Parent |
Returns
path is `${Parent}/${string}`
Defined in
lib/path.ts:72
isNode
▸ isNode(value
): value is Node<any>
Parameters
Name | Type |
---|---|
value | any |
Returns
value is Node<any>
Defined in
lib/node.ts:27
isObject
▸ isObject(value
): value is Record<string, unknown>
Parameters
Name | Type |
---|---|
value | any |
Returns
value is Record<string, unknown>
Defined in
lib/utils.ts:1
isWildcardPath
▸ isWildcardPath(path
): path is WildcardPath
Parameters
Name | Type |
---|---|
path | string |
Returns
path is WildcardPath
Defined in
lib/path.ts:64
joinPath
▸ joinPath<PathA
, PathB
>(path
, subpath
): JoinPathReturnType
<PathA
, PathB
>
Joins two paths together. It always returns a normalized path with no leading or trailing slashes. So joinPath('a', '/') will return 'a'
Type parameters
Name | Type |
---|---|
PathA | extends string |
PathB | extends string |
Parameters
Name | Type |
---|---|
path | PathA |
subpath | PathB |
Returns
JoinPathReturnType
<PathA
, PathB
>
Defined in
lib/path.ts:49
mergeDiff
▸ mergeDiff<Source
, Target
>(source
, target
): Partial
<Source
>
Type parameters
Name | Type |
---|---|
Source | extends ObjectType |
Target | extends ObjectType |
Parameters
Name | Type |
---|---|
source | Source |
target | Target |
Returns
Partial
<Source
>
Defined in
lib/utils.ts:11
nodeify
▸ nodeify<Schema
>(data
): Node
<Schema
>
Type parameters
Name | Type |
---|---|
Schema | extends Json | LeafValue |
Parameters
Name | Type |
---|---|
data | Schema |
Returns
Node
<Schema
>
Defined in
lib/node.ts:31
normalizePath
▸ normalizePath<Path
>(path
): NormalizedPath
<Path
>
Normalizes a path by removing leading and trailing slashes
Type parameters
Name | Type |
---|---|
Path | extends string |
Parameters
Name | Type |
---|---|
path | Path |
Returns
NormalizedPath
<Path
>
Defined in
lib/path.ts:27
parsePath
▸ parsePath(path
): NormalizedPath
<string
>[]
Parses a path into an array of path segments
Parameters
Name | Type |
---|---|
path | string |
Returns
NormalizedPath
<string
>[]
Defined in
lib/path.ts:12
simpleDeepClone
▸ simpleDeepClone<T
>(source
): T
This is about 3x faster than deepClone, but it only clones object structures: It skips nullish values, arrays, primitives, functions, and dates, etc.
Note: It does not support circular references.
Type parameters
Name | Type |
---|---|
T | extends Record <string , unknown > |
Parameters
Name | Type |
---|---|
source | T |
Returns
T
Defined in
lib/utils.ts:48
traverseNode
▸ traverseNode(node
, callback
): void
Parameters
Name | Type |
---|---|
node | Node <any > |
callback | (path : NormalizedPath , data : Node <any >) => true | void |
Returns
void
Defined in
lib/node.ts:70
trimWildcard
▸ trimWildcard(path
): string
Parameters
Name | Type |
---|---|
path | string |
Returns
string
Defined in
lib/path.ts:68
unwrap
▸ unwrap<Schema
>(node
): Schema
Type parameters
Name | Type |
---|---|
Schema | extends Json | LeafValue |
Parameters
Name | Type |
---|---|
node | Node <Schema > |
Returns
Schema
Defined in
lib/node.ts:49
Type Aliases
BatchedUpdate
Ƭ BatchedUpdate: Object
Type declaration
Name | Type |
---|---|
change? | Node |
delete? | NormalizedPath [] |
Defined in
lib/updateBatcher.ts:7
Brand
Ƭ Brand<T
, B
>: T
& { __brand__
: B
}
Type parameters
Name |
---|
T |
B |
Defined in
lib/utils.ts:60
ConnectionEvents
Ƭ ConnectionEvents: Object
Type declaration
Name | Type |
---|---|
connection:goodbye | GoodbyeMessage |
Defined in
lib/events.ts:46
DataEvents
Ƭ DataEvents: { [updatePath in `${typeof DATA_CONTEXT}:${string}`]: Object } & { [updatePath in `${typeof DATA_CONTEXT}:${WildcardPath}`]: Object } & { data:subscribe
: { once?
: boolean
; path
: string
} ; data:subscribeKeys
: { path
: string
} ; data:unsubscribe
: { path
: string
} ; data:update
: { data
: BatchedUpdate
} }
Defined in
lib/events.ts:5
GenericQueuedEvent
Ƭ GenericQueuedEvent<Events
>: Object
Type parameters
Name | Type |
---|---|
Events | extends GenericEvents |
Type declaration
Name | Type |
---|---|
data | Events [keyof Events ] |
event | keyof Events |
Defined in
lib/batchedSocketEvents.ts:9
GoodbyeMessage
Ƭ GoodbyeMessage: { reason
: "keep-alive-check-failed"
| "unspecified"
} | CustomGoodbyeMessage
A socket event that is sent before the client is disconnected from the server.
You can extend this by ov
Defined in
lib/events.ts:40
Json
Ƭ Json: Object
Index signature
▪ [key: string
]: JsonPrimitives
| Json
| JsonArray
Defined in
lib/node.ts:11
KeepAliveEvents
Ƭ KeepAliveEvents: Object
Type declaration
Name | Type |
---|---|
keep-alive:ping | Record <string , unknown > |
keep-alive:pong | Record <string , unknown > |
Defined in
lib/events.ts:23
LeafValue
Ƭ LeafValue: JsonPrimitives
| JsonArray
Defined in
lib/node.ts:9
Node
Ƭ Node<Schema
>: Object
Type parameters
Name | Type |
---|---|
Schema | extends Json | LeafValue = any |
Type declaration
Name | Type |
---|---|
meta? | Meta |
value | Schema extends Json ? { [key in keyof Schema]: Node<Schema[key]> } : Schema |
Defined in
lib/node.ts:20
NormalizedPath
Ƭ NormalizedPath<T
>: Brand
<T
, "NormalizedPath"
>
This path has been normalized by removing leading and trailing slashes
Type parameters
Name | Type |
---|---|
T | extends string = string |
Defined in
lib/path.ts:20
Plugin
Ƭ Plugin<T
>: Object
Type parameters
Name |
---|
T |
Type declaration
Name | Type |
---|---|
hooks | T |
name | string |
Defined in
lib/plugin.ts:1
Socket
Ƭ Socket: Object
Type declaration
Name | Type |
---|---|
close | () => void |
off | (event : string , callback? : (data : any ) => void ) => void |
on | (event : string , callback : (data : any ) => void ) => void |
onDisconnect | (callback : () => void ) => void |
send | (event : string , data : any ) => void |
Defined in
lib/socket-connection/socket.ts:1
SocketClient
Ƭ SocketClient: { onConnect
: (callback
: () => void
) => void
} & Socket
Defined in
lib/socket-connection/socketClient.ts:3
Store
Ƭ Store: Object
Type declaration
Name | Type |
---|---|
del | (path : string ) => void |
get | (path? : string ) => Node | null |
put | (diff : Node ) => Node |
Defined in
lib/store.ts:5
WildcardPath
Ƭ WildcardPath: `${string}/` | ``"" \| [`NormalizedPath`](/api/modules/socketdb_core#normalizedpath)<
""`\> \| [
NormalizedPath](/api/modules/socketdb_core#normalizedpath)<\
${string}/`>
Defined in
lib/path.ts:3
Variables
CONNECTION_CONTEXT
• Const
CONNECTION_CONTEXT: "connection"
Defined in
lib/constants.ts:3
DATA_CONTEXT
• Const
DATA_CONTEXT: "data"
Defined in
lib/constants.ts:1
KEEP_ALIVE_CONTEXT
• Const
KEEP_ALIVE_CONTEXT: "keep-alive"
Defined in
lib/constants.ts:2
SOCKET_EVENTS
• Const
SOCKET_EVENTS: Object
Type declaration
Name | Type |
---|---|
connection | { goodbye : "connection:goodbye" } |
connection.goodbye | "connection:goodbye" |
data | { clientUpdate : "data:update" ; requestKeysSubscription : "data:subscribeKeys" ; requestSubscription : "data:subscribe" ; requestUnsubscription : "data:unsubscribe" } |
data.clientUpdate | "data:update" |
data.requestKeysSubscription | "data:subscribeKeys" |
data.requestSubscription | "data:subscribe" |
data.requestUnsubscription | "data:unsubscribe" |
keepAlive | { ping : "keep-alive:ping" ; pong : "keep-alive:pong" } |
keepAlive.ping | "keep-alive:ping" |
keepAlive.pong | "keep-alive:pong" |
Defined in
lib/constants.ts:5