Skip to main content

Module: @socketdb/core

Interfaces​

Functions​

createBatchedClient​

▸ createBatchedClient<Events>(connection, interval?): Object

Type parameters​

NameType
Eventsextends GenericEvents

Parameters​

NameType
connectionSocket
interval?number

Returns​

Object

NameType
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​

NameType
Eventsextends Object = { [event: string]: unknown; }

Returns​

Object

NameType
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​

Store

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​

NameType
DataTypeany

Parameters​

NameType
«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

NameType
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​

NameType
flushUpdate(batchedUpdate: BatchedUpdate) => void
updateIntervalnumber

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​

NameType
sourceT

Returns​

T

Defined in​

lib/utils.ts:36


hasChildNodes​

▸ hasChildNodes(node?): node is Node<Json>

Parameters​

NameType
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​

NameType
Parentextends string

Parameters​

NameType
pathstring
parentPathParent

Returns​

path is `${Parent}/${string}`

Defined in​

lib/path.ts:72


isNode​

▸ isNode(value): value is Node<any>

Parameters​

NameType
valueany

Returns​

value is Node<any>

Defined in​

lib/node.ts:27


isObject​

▸ isObject(value): value is Record<string, unknown>

Parameters​

NameType
valueany

Returns​

value is Record<string, unknown>

Defined in​

lib/utils.ts:1


isWildcardPath​

▸ isWildcardPath(path): path is WildcardPath

Parameters​

NameType
pathstring

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​

NameType
PathAextends string
PathBextends string

Parameters​

NameType
pathPathA
subpathPathB

Returns​

JoinPathReturnType<PathA, PathB>

Defined in​

lib/path.ts:49


mergeDiff​

▸ mergeDiff<Source, Target>(source, target): Partial<Source>

Type parameters​

NameType
Sourceextends ObjectType
Targetextends ObjectType

Parameters​

NameType
sourceSource
targetTarget

Returns​

Partial<Source>

Defined in​

lib/utils.ts:11


nodeify​

▸ nodeify<Schema>(data): Node<Schema>

Type parameters​

NameType
Schemaextends Json | LeafValue

Parameters​

NameType
dataSchema

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​

NameType
Pathextends string

Parameters​

NameType
pathPath

Returns​

NormalizedPath<Path>

Defined in​

lib/path.ts:27


parsePath​

▸ parsePath(path): NormalizedPath<string>[]

Parses a path into an array of path segments

Parameters​

NameType
pathstring

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​

NameType
Textends Record<string, unknown>

Parameters​

NameType
sourceT

Returns​

T

Defined in​

lib/utils.ts:48


traverseNode​

▸ traverseNode(node, callback): void

Parameters​

NameType
nodeNode<any>
callback(path: NormalizedPath, data: Node<any>) => true | void

Returns​

void

Defined in​

lib/node.ts:70


trimWildcard​

▸ trimWildcard(path): string

Parameters​

NameType
pathstring

Returns​

string

Defined in​

lib/path.ts:68


unwrap​

▸ unwrap<Schema>(node): Schema

Type parameters​

NameType
Schemaextends Json | LeafValue

Parameters​

NameType
nodeNode<Schema>

Returns​

Schema

Defined in​

lib/node.ts:49

Type Aliases​

BatchedUpdate​

Ƭ BatchedUpdate: Object

Type declaration​

NameType
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​

NameType
connection:goodbyeGoodbyeMessage

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​

NameType
Eventsextends GenericEvents

Type declaration​

NameType
dataEvents[keyof Events]
eventkeyof 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​

NameType
keep-alive:pingRecord<string, unknown>
keep-alive:pongRecord<string, unknown>

Defined in​

lib/events.ts:23


LeafValue​

Ƭ LeafValue: JsonPrimitives | JsonArray

Defined in​

lib/node.ts:9


Node​

Ƭ Node<Schema>: Object

Type parameters​

NameType
Schemaextends Json | LeafValue = any

Type declaration​

NameType
meta?Meta
valueSchema 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​

NameType
Textends string = string

Defined in​

lib/path.ts:20


Plugin​

Ƭ Plugin<T>: Object

Type parameters​

Name
T

Type declaration​

NameType
hooksT
namestring

Defined in​

lib/plugin.ts:1


Socket​

Ƭ Socket: Object

Type declaration​

NameType
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​

NameType
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​

NameType
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