@owlmeans/socket 0.1.18-rc.8 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/agent-meta/manifest.json +3 -3
- package/agent-meta/skills/socket/SKILL.md +115 -13
- package/build/consts.d.ts +21 -0
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +22 -0
- package/build/consts.js.map +1 -1
- package/build/errors.d.ts.map +1 -1
- package/build/errors.js.map +1 -1
- package/build/helper/types.d.ts +13 -0
- package/build/helper/types.d.ts.map +1 -0
- package/build/helper/types.js +2 -0
- package/build/helper/types.js.map +1 -0
- package/build/helper.d.ts +6 -3
- package/build/helper.d.ts.map +1 -1
- package/build/helper.js +14 -6
- package/build/helper.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js.map +1 -1
- package/build/model.d.ts.map +1 -1
- package/build/model.js +130 -105
- package/build/model.js.map +1 -1
- package/build/types.d.ts +5 -0
- package/build/types.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/consts.ts +23 -0
- package/src/helper/types.ts +13 -0
- package/src/helper.ts +27 -15
- package/src/index.ts +1 -0
- package/src/model.ts +136 -101
- package/src/types.ts +6 -0
- package/tests/model.spec.ts +59 -0
- package/tsconfig.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Shared WebSocket connection types and message protocol for OwlMeans real-time co
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
bun add @owlmeans/socket
|
|
15
|
+
bun add @owlmeans/socket@^0.1.18
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
## Usage
|
|
@@ -91,7 +91,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
91
91
|
your project's skill store (`.agents/skills/`):
|
|
92
92
|
|
|
93
93
|
```sh
|
|
94
|
-
npx @owlmeans/agent-skills
|
|
94
|
+
npx @owlmeans/agent-skills@^0.1.18
|
|
95
95
|
```
|
|
96
96
|
|
|
97
97
|
The embedded files are version-matched to this package release. Do not edit them
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"schemaVersion":
|
|
2
|
+
"schemaVersion": 3,
|
|
3
3
|
"package": "@owlmeans/socket",
|
|
4
|
-
"version": "0.1.18
|
|
5
|
-
"generatedAt": "2026-
|
|
4
|
+
"version": "0.1.18",
|
|
5
|
+
"generatedAt": "2026-10-28T00:31:34.737Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: socket
|
|
3
|
-
description: How to use @owlmeans/socket —
|
|
3
|
+
description: How to use @owlmeans/socket — the transport-agnostic Connection model shared by client-socket and server-socket, its message types (call/request/event/auth/system), the type guards, and the socket error classes. Auto-invoked when importing socket types, message constants or the connection model.
|
|
4
4
|
user-invocable: false
|
|
5
5
|
---
|
|
6
6
|
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
@@ -8,29 +8,131 @@ user-invocable: false
|
|
|
8
8
|
# @owlmeans/socket
|
|
9
9
|
|
|
10
10
|
**Layer:** Core
|
|
11
|
-
**Install:** `"@owlmeans/socket": "^0.1.18
|
|
11
|
+
**Install:** `"@owlmeans/socket": "^0.1.18"` in `dependencies`
|
|
12
|
+
|
|
13
|
+
Contracts and one implementation-free connection model. It knows nothing about WebSockets: the
|
|
14
|
+
browser side is `@owlmeans/client-socket`, the Fastify side `@owlmeans/server-socket`, and each
|
|
15
|
+
supplies the members the model leaves abstract — `send`, `close`, `authenticate` and `prepare` —
|
|
16
|
+
that make it concrete. Both halves of an application therefore speak the same frames.
|
|
12
17
|
|
|
13
18
|
## Key Exports
|
|
14
19
|
|
|
15
20
|
| Export | Description |
|
|
16
21
|
|--------|-------------|
|
|
17
|
-
| `
|
|
18
|
-
| `
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
+
| `createBasicConnection()` | The connection model — everything below the wire. A carrier assigns `send` / `close` / `authenticate` / `prepare` and feeds bytes to `receive` |
|
|
23
|
+
| `Connection` | What a handler is handed: the messaging verbs, `stage`, `getListeners` |
|
|
24
|
+
| `Message<T>` | The frame — `{ type, payload, id?, sender?, recipient?, dt?, rawData? }` |
|
|
25
|
+
| `CallMessage<T>` / `EventMessage<T>` / `AuthMessage<T>` | The three frames that add a field: `method` + `timeout`, `event`, `stage` |
|
|
26
|
+
| `MessageType` | `Call` `Result` `Error` `Request` `Response` `Event` `Message` `Auth` `System` |
|
|
27
|
+
| `socketMessageHelper` — `.isMessage` / `.isEventMessage` / `.isCallMessage` / `.isAuthMessage` | Type guards — `socketMessageHelper.isMessage(msg, true)` excludes system frames, `.isEventMessage(msg, true)` keeps only them |
|
|
28
|
+
| `ConnectionListener` / `CallHendler` / `RequestHandler` / `CallResolver` | The callback shapes |
|
|
29
|
+
| `SocketSystemEvent` | The `event` values a `MessageType.System` frame carries — see below |
|
|
30
|
+
| `SOCKET_HEARTBEAT_TIMEOUT_CODE` | `4000` — the close code `client-socket`'s carrier uses when it force-closes a socket that has gone silent |
|
|
31
|
+
| `SocketError` and subclasses | `SocketInitializationError`, `SocketConnectionError`, `SocketUnauthorized`, `SocketUnsupported`, `SocketTimeout`, `SocketMessageError`, `SocketMessageMalformed` — all registered with `ResilientError` |
|
|
32
|
+
| `CALL_TIMEOUT` | 60 000 ms, the fallback when neither the message nor `connection.defaultCallTimeout` says |
|
|
33
|
+
|
|
34
|
+
## The four ways to say something
|
|
35
|
+
|
|
36
|
+
Pick by who is expected to answer and how often — they are separate registries, and a handler
|
|
37
|
+
bound to one never sees the others.
|
|
22
38
|
|
|
23
|
-
|
|
39
|
+
| Verb | Answered by | Shape |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| `notify(event, payload)` | `observe(event, handler)` | Fire-and-forget, fanned out to every observer of that event name |
|
|
42
|
+
| `call(method, ...args)` | `perform(method, handler)` | One RPC, resolved with the handler's return value or rejected with its error |
|
|
43
|
+
| `request(payload, observer?)` | `acknowledge(handler)`, answered with `reply(id, payload)` | An open question — acknowledgers run in turn until one takes it |
|
|
44
|
+
| `enqueue(payload, id?)` | `consume(filter?)` | A mailbox the far side drains on its own schedule; `enqueued()` is its depth |
|
|
24
45
|
|
|
25
46
|
```typescript
|
|
26
|
-
import
|
|
47
|
+
import { MessageType } from '@owlmeans/socket'
|
|
48
|
+
import type { Connection, EventMessage } from '@owlmeans/socket'
|
|
49
|
+
|
|
50
|
+
connection.observe<Progress>('job-event', async message => render(message.payload))
|
|
51
|
+
await connection.notify('job-event', { id, progress: 0.5 })
|
|
52
|
+
|
|
53
|
+
connection.perform<Report, [string]>('report', async id => await build(id))
|
|
54
|
+
const report = await connection.call<Report, [string]>('report', id)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
A `call` carries an id and a timeout, and the model arms the timer on both sides: the caller
|
|
58
|
+
rejects with `SocketTimeout` when the answer does not arrive, and the performer stops sending one
|
|
59
|
+
once it has elapsed. `timeout: 0` disables it. A performer that throws is answered with a
|
|
60
|
+
`MessageType.Error` frame carrying the marshalled error, so the caller's `call` rejects with the
|
|
61
|
+
original class rather than with a string.
|
|
62
|
+
|
|
63
|
+
## Frames a listener sees
|
|
27
64
|
|
|
28
|
-
|
|
65
|
+
`listen(listener)` receives EVERY inbound frame after the model has routed it — the escape hatch
|
|
66
|
+
for what the verbs above do not cover. It also receives the frames a carrier synthesises, which is
|
|
67
|
+
how a handler learns the connection is gone:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
connection.listen(async message => {
|
|
71
|
+
if (typeof message !== 'object') {
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
const msg = message as EventMessage<void>
|
|
75
|
+
if (msg.type === MessageType.System && msg.event === 'close') {
|
|
76
|
+
await cleanUp()
|
|
77
|
+
}
|
|
78
|
+
})
|
|
29
79
|
```
|
|
30
80
|
|
|
31
|
-
|
|
81
|
+
Both carriers emit exactly that frame — `MessageType.System`, `event: 'close'`, payload
|
|
82
|
+
`{ code }` — when the socket closes for good. Nothing else reports a TERMINAL disconnect, so any
|
|
83
|
+
subscription a handler opened is released there.
|
|
84
|
+
|
|
85
|
+
**`SocketSystemEvent`** is the full vocabulary a `MessageType.System` frame's `event` can carry —
|
|
86
|
+
`client-socket`'s reconnecting carrier is what emits the other four:
|
|
87
|
+
|
|
88
|
+
| Event | Meaning |
|
|
89
|
+
|---|---|
|
|
90
|
+
| `close` | The connection is gone for good — see above |
|
|
91
|
+
| `disconnected` | The socket dropped and a retry IS scheduled (client-socket only) — `{ code }` |
|
|
92
|
+
| `reconnecting` | Before each retry attempt (client-socket only) — `{ attempt, delay }` |
|
|
93
|
+
| `reconnected` | A retry succeeded, same `Connection` model (client-socket only) — `{ attempts }` |
|
|
94
|
+
| `lost` | The retry budget elapsed with no success (client-socket only). NOT followed by `close`: the connection stays revivable until its owner closes it |
|
|
95
|
+
|
|
96
|
+
`close` is the only one of the five a plain carrier with no retry logic (like `server-socket`, or
|
|
97
|
+
`client-socket` itself with `reconnect: false`) will ever emit. A listener that must react to a
|
|
98
|
+
reconnecting carrier giving up listens for `lost` — a `close` there comes only from its owner's
|
|
99
|
+
own `close()` or a terminal server code.
|
|
100
|
+
|
|
101
|
+
## What the model expects of a carrier
|
|
102
|
+
|
|
103
|
+
- `receive(raw)` takes the raw string. It only parses text that starts with `{` or `[`; anything
|
|
104
|
+
else is dropped without reaching a listener. The carriers' own heartbeat IS JSON
|
|
105
|
+
(`{ type: 'ping' }`), so it is parsed: it matches no `MessageType` and routes nowhere, yet it
|
|
106
|
+
still reaches every `listen` listener — a listener has to recognise the frames it wants.
|
|
107
|
+
- A frame with no `type` is read as `MessageType.Message` and a frame with no `payload` is treated
|
|
108
|
+
as its own payload, so a plain JSON body from a foreign client still arrives as a message.
|
|
109
|
+
- `prepare(message, isRequest?)` is the carrier's hook for stamping a frame — timestamps,
|
|
110
|
+
`sender` / `recipient`. It runs on every outbound frame and on every inbound one.
|
|
111
|
+
- `send`, `close` and `authenticate` throw `SyntaxError` until a carrier assigns them, so one that
|
|
112
|
+
forgets a member fails loudly rather than dropping frames. `prepare` is the exception: it is
|
|
113
|
+
optional on the interface and simply absent until assigned, and the model calls it defensively —
|
|
114
|
+
a carrier that omits it stamps nothing.
|
|
115
|
+
|
|
116
|
+
## Authentication
|
|
117
|
+
|
|
118
|
+
`auth(stage, payload)` sends an `AuthMessage` and waits. The far side's `authenticate` answers with
|
|
119
|
+
the next stage and its payload, or throws — a rejection travels back as an `AuthMessage` with a
|
|
120
|
+
null stage and is rebuilt by the initiator. `connection.stage` holds the current
|
|
121
|
+
`AuthenticationStage` throughout. Only the server carrier implements a real sequence; see the
|
|
122
|
+
`server-socket` skill.
|
|
123
|
+
|
|
124
|
+
Raw inbound data is parsed and structurally checked before dispatch. A server connection may accept
|
|
125
|
+
only authentication frames until its carrier marks it authenticated; an unknown call returns a
|
|
126
|
+
typed socket error, and listener failures are isolated and logged so an EventEmitter never receives
|
|
127
|
+
an unhandled rejected promise. Keep sensitive actions behind the carrier's authentication stage.
|
|
32
128
|
|
|
33
129
|
## Depends On
|
|
34
130
|
|
|
35
|
-
- `@owlmeans/error`,
|
|
36
|
-
- `@owlmeans/
|
|
131
|
+
- `@owlmeans/error` — `ResilientError`, which every socket error registers with
|
|
132
|
+
- `@owlmeans/auth` — `AuthenticationStage`, the vocabulary the auth frames carry
|
|
133
|
+
- `@owlmeans/basic-ids` — `idHelper.uuid` for call and request ids
|
|
134
|
+
|
|
135
|
+
## Related
|
|
136
|
+
|
|
137
|
+
- `client-socket` — the browser carrier and `useWs`
|
|
138
|
+
- `server-socket` — the Fastify carrier, guard enforcement and `connection(protocol, callback)`
|
package/build/consts.d.ts
CHANGED
|
@@ -10,4 +10,25 @@ export declare enum MessageType {
|
|
|
10
10
|
System = "system"
|
|
11
11
|
}
|
|
12
12
|
export declare const CALL_TIMEOUT = 60000;
|
|
13
|
+
/**
|
|
14
|
+
* System frames a carrier synthesises around the lifecycle of the underlying transport.
|
|
15
|
+
*
|
|
16
|
+
* `Close` means the connection is gone for good — a client-initiated close, or a terminal server
|
|
17
|
+
* code. A drop the carrier intends to retry is reported as `Disconnected`, and an exhausted retry
|
|
18
|
+
* budget as `Lost` alone: a lost connection can still be revived, so it is not closed.
|
|
19
|
+
*/
|
|
20
|
+
export declare enum SocketSystemEvent {
|
|
21
|
+
Close = "close",
|
|
22
|
+
Disconnected = "disconnected",
|
|
23
|
+
Reconnecting = "reconnecting",
|
|
24
|
+
Reconnected = "reconnected",
|
|
25
|
+
Lost = "lost"
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The close code a carrier uses when it drops a socket itself — a missed heartbeat pong within
|
|
29
|
+
* `pongTimeout`, catching a half-open TCP connection long before the OS would notice one.
|
|
30
|
+
* Reserved in the 4000–4999 private-use range so it is never confused with a code either
|
|
31
|
+
* endpoint's own WebSocket stack could produce.
|
|
32
|
+
*/
|
|
33
|
+
export declare const SOCKET_HEARTBEAT_TIMEOUT_CODE = 4000;
|
|
13
34
|
//# sourceMappingURL=consts.d.ts.map
|
package/build/consts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,oBAAY,WAAW;IACrB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,MAAM,WAAW;CAClB;AAED,eAAO,MAAM,YAAY,QAAQ,CAAA"}
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,oBAAY,WAAW;IACrB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,MAAM,WAAW;CAClB;AAED,eAAO,MAAM,YAAY,QAAQ,CAAA;AAEjC;;;;;;GAMG;AACH,oBAAY,iBAAiB;IAC3B,KAAK,UAAU;IACf,YAAY,iBAAiB;IAC7B,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;IAC3B,IAAI,SAAS;CACd;AAED;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,OAAO,CAAA"}
|
package/build/consts.js
CHANGED
|
@@ -11,4 +11,26 @@ export var MessageType;
|
|
|
11
11
|
MessageType["System"] = "system";
|
|
12
12
|
})(MessageType || (MessageType = {}));
|
|
13
13
|
export const CALL_TIMEOUT = 60000;
|
|
14
|
+
/**
|
|
15
|
+
* System frames a carrier synthesises around the lifecycle of the underlying transport.
|
|
16
|
+
*
|
|
17
|
+
* `Close` means the connection is gone for good — a client-initiated close, or a terminal server
|
|
18
|
+
* code. A drop the carrier intends to retry is reported as `Disconnected`, and an exhausted retry
|
|
19
|
+
* budget as `Lost` alone: a lost connection can still be revived, so it is not closed.
|
|
20
|
+
*/
|
|
21
|
+
export var SocketSystemEvent;
|
|
22
|
+
(function (SocketSystemEvent) {
|
|
23
|
+
SocketSystemEvent["Close"] = "close";
|
|
24
|
+
SocketSystemEvent["Disconnected"] = "disconnected";
|
|
25
|
+
SocketSystemEvent["Reconnecting"] = "reconnecting";
|
|
26
|
+
SocketSystemEvent["Reconnected"] = "reconnected";
|
|
27
|
+
SocketSystemEvent["Lost"] = "lost";
|
|
28
|
+
})(SocketSystemEvent || (SocketSystemEvent = {}));
|
|
29
|
+
/**
|
|
30
|
+
* The close code a carrier uses when it drops a socket itself — a missed heartbeat pong within
|
|
31
|
+
* `pongTimeout`, catching a half-open TCP connection long before the OS would notice one.
|
|
32
|
+
* Reserved in the 4000–4999 private-use range so it is never confused with a code either
|
|
33
|
+
* endpoint's own WebSocket stack could produce.
|
|
34
|
+
*/
|
|
35
|
+
export const SOCKET_HEARTBEAT_TIMEOUT_CODE = 4000;
|
|
14
36
|
//# sourceMappingURL=consts.js.map
|
package/build/consts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAN,IAAY,WAUX;AAVD,WAAY,WAAW;IACrB,4BAAa,CAAA;IACb,gCAAiB,CAAA;IACjB,8BAAe,CAAA;IACf,kCAAmB,CAAA;IACnB,oCAAqB,CAAA;IACrB,8BAAe,CAAA;IACf,kCAAmB,CAAA;IACnB,4BAAa,CAAA;IACb,gCAAiB,CAAA;AACnB,CAAC,EAVW,WAAW,KAAX,WAAW,QAUtB;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAA"}
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAN,IAAY,WAUX;AAVD,WAAY,WAAW;IACrB,4BAAa,CAAA;IACb,gCAAiB,CAAA;IACjB,8BAAe,CAAA;IACf,kCAAmB,CAAA;IACnB,oCAAqB,CAAA;IACrB,8BAAe,CAAA;IACf,kCAAmB,CAAA;IACnB,4BAAa,CAAA;IACb,gCAAiB,CAAA;AACnB,CAAC,EAVW,WAAW,KAAX,WAAW,QAUtB;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAA;AAEjC;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,iBAMX;AAND,WAAY,iBAAiB;IAC3B,oCAAe,CAAA;IACf,kDAA6B,CAAA;IAC7B,kDAA6B,CAAA;IAC7B,gDAA2B,CAAA;IAC3B,kCAAa,CAAA;AACf,CAAC,EANW,iBAAiB,KAAjB,iBAAiB,QAM5B;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,IAAI,CAAA"}
|
package/build/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,qBAAa,WAAY,SAAQ,cAAc;IAC7C,OAAuB,QAAQ,EAAE,MAAM,CAAgB;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,qBAAa,WAAY,SAAQ,cAAc;IAC7C,OAAuB,QAAQ,EAAE,MAAM,CAAgB;IAEvD,YAAY,OAAO,GAAE,MAAgB,EAEpC;CACF;AAED,qBAAa,yBAA0B,SAAQ,WAAW;IACxD,OAAuB,QAAQ,EAAE,MAAM,CAA0C;IAEjF,YAAY,OAAO,GAAE,MAAgB,EAGpC;CACF;AAED,qBAAa,qBAAsB,SAAQ,WAAW;IACpD,OAAuB,QAAQ,EAAE,MAAM,CAAsC;IAE7E,YAAY,OAAO,GAAE,MAAgB,EAGpC;CACF;AAED,qBAAa,kBAAmB,SAAQ,qBAAqB;IAC3D,OAAuB,QAAQ,EAAE,MAAM,CAAkD;IAEzF,YAAY,OAAO,GAAE,MAAgB,EAGpC;CACF;AAED,qBAAa,iBAAkB,SAAQ,qBAAqB;IAC1D,OAAuB,QAAQ,EAAE,MAAM,CAAiD;IAExF,YAAY,OAAO,GAAE,MAAgB,EAGpC;CACF;AAED,qBAAa,aAAc,SAAQ,WAAW;IAC5C,OAAuB,QAAQ,EAAE,MAAM,CAAmC;IAE1E,YAAY,OAAO,GAAE,MAAgB,EAGpC;CACF;AAED,qBAAa,kBAAmB,SAAQ,WAAW;IACjD,OAAuB,QAAQ,EAAE,MAAM,CAAmC;IAE1E,YAAY,OAAO,GAAE,MAAgB,EAGpC;CACF;AAED,qBAAa,sBAAuB,SAAQ,kBAAkB;IAC5D,OAAuB,QAAQ,EAAE,MAAM,CAA4C;IAEnF,YAAY,OAAO,GAAE,MAAgB,EAGpC;CACF"}
|
package/build/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,MAAM,OAAO,WAAY,SAAQ,cAAc;IACtC,MAAM,CAAU,QAAQ,GAAW,aAAa,CAAA;IAEvD,YAAY,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AuthMessage, CallMessage, EventMessage, Message } from '../types.js';
|
|
2
|
+
/** Recognizes the kinds of socket message. */
|
|
3
|
+
export interface SocketMessageHelper {
|
|
4
|
+
/** Whether a received value is a message; `nonSystem` also requires it (not) to be a system one. */
|
|
5
|
+
isMessage: <P, T extends Message<P>>(msg: string | T, nonSystem?: boolean) => msg is T;
|
|
6
|
+
/** Whether a message is an event (system events included); `system` also requires it (not) to be a system one. */
|
|
7
|
+
isEventMessage: <P>(msg: string | Message<P>, system?: boolean) => msg is EventMessage<P>;
|
|
8
|
+
/** Whether a message is a call. */
|
|
9
|
+
isCallMessage: <P extends any[]>(msg: string | Message<unknown>) => msg is CallMessage<P>;
|
|
10
|
+
/** Whether a message is an authentication one. */
|
|
11
|
+
isAuthMessage: <P>(msg: string | Message<P>) => msg is AuthMessage<P>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/helper/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAElF,8CAA8C;AAC9C,MAAM,WAAW,mBAAmB;IAClC,oGAAoG;IACpG,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,EAAE,SAAS,CAAC,EAAE,OAAO,KAAK,GAAG,IAAI,CAAC,CAAA;IACtF,kHAAkH;IAClH,cAAc,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,CAAA;IACzF,mCAAmC;IACnC,aAAa,EAAE,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAA;IACzF,kDAAkD;IAClD,aAAa,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAA;CACtE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/helper/types.ts"],"names":[],"mappings":""}
|
package/build/helper.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EventMessage, Message } from './types.js';
|
|
2
|
+
import type { SocketMessageHelper } from './helper/types.js';
|
|
3
|
+
export declare const createSocketMessageHelper: () => SocketMessageHelper;
|
|
4
|
+
export declare const socketMessageHelper: SocketMessageHelper;
|
|
5
|
+
/** @deprecated compat:factory-refactor — use `socketMessageHelper.isMessage(…)` */
|
|
2
6
|
export declare const isMessage: <P, T extends Message<P>>(msg: string | T, nonSystem?: boolean) => msg is T;
|
|
7
|
+
/** @deprecated compat:factory-refactor — use `socketMessageHelper.isEventMessage(…)` */
|
|
3
8
|
export declare const isEventMessage: <P>(msg: string | Message<P>, system?: boolean) => msg is EventMessage<P>;
|
|
4
|
-
export declare const isCallMessage: <P extends any[]>(msg: string | Message<unknown>) => msg is CallMessage<P>;
|
|
5
|
-
export declare const isAuthMessage: <P>(msg: string | Message<P>) => msg is AuthMessage<P>;
|
|
6
9
|
//# sourceMappingURL=helper.d.ts.map
|
package/build/helper.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,YAAY,EAAE,OAAO,EAAe,MAAM,YAAY,CAAA;AACjF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAwB5D,eAAO,MAAM,yBAAyB,QAAO,mBAgB5C,CAAA;AAED,eAAO,MAAM,mBAAmB,qBAA8B,CAAA;AAE9D,mFAAmF;AACnF,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,OAAO,MAAM,GAAG,CAAC,cAAc,OAAO,KAAG,GAAG,IAAI,CAAwD,CAAA;AAEzJ,wFAAwF;AACxF,eAAO,MAAM,cAAc,GAAI,CAAC,OAAO,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,WAAW,OAAO,KAAG,GAAG,IAAI,YAAY,CAAC,CAAC,CAAuD,CAAA"}
|
package/build/helper.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import { MessageType } from './consts.js';
|
|
2
|
-
export const isMessage = (msg, nonSystem) => typeof msg === 'object' && 'type' in msg && 'payload' in msg
|
|
3
|
-
&& (nonSystem === undefined || nonSystem === (msg.type !== MessageType.System));
|
|
4
|
-
export const isEventMessage = (msg, system) => isMessage(msg) && [MessageType.Event, MessageType.System].includes(msg.type)
|
|
5
|
-
&& (system === undefined || system === (msg.type === MessageType.System));
|
|
6
|
-
export const isCallMessage = (msg) => isMessage(msg) && msg.type === MessageType.Call;
|
|
7
|
-
export const isAuthMessage = (msg) => isMessage(msg) && msg.type === MessageType.Auth;
|
|
8
2
|
// export const prepareLongCalls = (connection: Connection, longTimeout = CALL_TIMEOUT * 10) => {
|
|
9
3
|
// const _connection = connection as WithLongCalls
|
|
10
4
|
// if (_connection[long_calls] == null) {
|
|
@@ -23,4 +17,18 @@ export const isAuthMessage = (msg) => isMessage(msg) && msg.type === MessageType
|
|
|
23
17
|
// interface WithLongCalls extends Connection {
|
|
24
18
|
// [long_calls]: boolean
|
|
25
19
|
// }
|
|
20
|
+
export const createSocketMessageHelper = () => {
|
|
21
|
+
const isMessage = (msg, nonSystem) => typeof msg === 'object' && 'type' in msg && 'payload' in msg
|
|
22
|
+
&& (nonSystem === undefined || nonSystem === (msg.type !== MessageType.System));
|
|
23
|
+
const isEventMessage = (msg, system) => isMessage(msg) && [MessageType.Event, MessageType.System].includes(msg.type)
|
|
24
|
+
&& (system === undefined || system === (msg.type === MessageType.System));
|
|
25
|
+
const isCallMessage = (msg) => isMessage(msg) && msg.type === MessageType.Call;
|
|
26
|
+
const isAuthMessage = (msg) => isMessage(msg) && msg.type === MessageType.Auth;
|
|
27
|
+
return { isMessage, isEventMessage, isCallMessage, isAuthMessage };
|
|
28
|
+
};
|
|
29
|
+
export const socketMessageHelper = createSocketMessageHelper();
|
|
30
|
+
/** @deprecated compat:factory-refactor — use `socketMessageHelper.isMessage(…)` */
|
|
31
|
+
export const isMessage = (msg, nonSystem) => socketMessageHelper.isMessage(msg, nonSystem);
|
|
32
|
+
/** @deprecated compat:factory-refactor — use `socketMessageHelper.isEventMessage(…)` */
|
|
33
|
+
export const isEventMessage = (msg, system) => socketMessageHelper.isEventMessage(msg, system);
|
|
26
34
|
//# sourceMappingURL=helper.js.map
|
package/build/helper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAIzC,iGAAiG;AACjG,oDAAoD;AACpD,2CAA2C;AAC3C,yCAAyC;AACzC,qDAAqD;AACrD,oDAAoD;AACpD,wCAAwC;AACxC,UAAU;AAEV,wDAAwD;AACxD,QAAQ;AACR,qCAAqC;AACrC,MAAM;AAEN,sBAAsB;AACtB,IAAI;AAEJ,yDAAyD;AACzD,+CAA+C;AAC/C,0BAA0B;AAC1B,IAAI;AAEJ,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAwB,EAAE;IACjE,MAAM,SAAS,GAAG,CAA0B,GAAe,EAAE,SAAmB,EAAY,EAAE,CAC5F,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,IAAI,GAAG,IAAI,SAAS,IAAI,GAAG;WACzD,CAAC,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,CAAC,GAAG,CAAC,IAAI,KAAK,WAAW,CAAC,MAAM,CAAC,CAAC,CAAA;IAEjF,MAAM,cAAc,GAAG,CAAI,GAAwB,EAAE,MAAgB,EAA0B,EAAE,CAC/F,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;WACzE,CAAC,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,CAAC,GAAG,CAAC,IAAI,KAAK,WAAW,CAAC,MAAM,CAAC,CAAC,CAAA;IAE3E,MAAM,aAAa,GAAG,CAAkB,GAA8B,EAAyB,EAAE,CAC/F,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,WAAW,CAAC,IAAI,CAAA;IAEjD,MAAM,aAAa,GAAG,CAAI,GAAwB,EAAyB,EAAE,CAC3E,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,WAAW,CAAC,IAAI,CAAA;IAEjD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,CAAA;AACpE,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,yBAAyB,EAAE,CAAA;AAE9D,mFAAmF;AACnF,MAAM,CAAC,MAAM,SAAS,GAAG,CAA0B,GAAe,EAAE,SAAmB,EAAY,EAAE,CAAC,mBAAmB,CAAC,SAAS,CAAO,GAAG,EAAE,SAAS,CAAC,CAAA;AAEzJ,wFAAwF;AACxF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAI,GAAwB,EAAE,MAAgB,EAA0B,EAAE,CAAC,mBAAmB,CAAC,cAAc,CAAI,GAAG,EAAE,MAAM,CAAC,CAAA"}
|
package/build/index.d.ts
CHANGED
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,mBAAmB,mBAAmB,CAAA;AACtC,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
|
package/build/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAC2C,UAAU,EAEhE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAC2C,UAAU,EAEhE,MAAM,YAAY,CAAA;AAOnB,eAAO,MAAM,qBAAqB,QAAO,UA+XxC,CAAA"}
|